summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh38
1 files changed, 34 insertions, 4 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 3aff37970a..f4f3562671 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -15,6 +15,7 @@ require_work_tree
command=
branch=
quiet=
+reference=
cached=
nofetch=
update=
@@ -92,6 +93,7 @@ module_clone()
{
path=$1
url=$2
+ reference="$3"
# If there already is a directory at the submodule path,
# expect it to be empty (since that is the default checkout
@@ -107,7 +109,12 @@ module_clone()
test -e "$path" &&
die "A file already exist at path '$path'"
- git-clone -n "$url" "$path" ||
+ if test -n "$reference"
+ then
+ git-clone "$reference" -n "$url" "$path"
+ else
+ git-clone -n "$url" "$path"
+ fi ||
die "Clone of '$url' into submodule path '$path' failed"
}
@@ -132,6 +139,15 @@ cmd_add()
-q|--quiet)
quiet=1
;;
+ --reference)
+ case "$2" in '') usage ;; esac
+ reference="--reference=$2"
+ shift
+ ;;
+ --reference=*)
+ reference="$1"
+ shift
+ ;;
--)
shift
break
@@ -204,7 +220,7 @@ cmd_add()
git config submodule."$path".url "$url"
else
- module_clone "$path" "$realrepo" || exit
+ module_clone "$path" "$realrepo" "$reference" || exit
(
unset GIT_DIR
cd "$path" &&
@@ -320,8 +336,8 @@ cmd_update()
quiet=1
;;
-i|--init)
+ init=1
shift
- cmd_init "$@" || return
;;
-N|--no-fetch)
shift
@@ -331,6 +347,15 @@ cmd_update()
shift
update="rebase"
;;
+ --reference)
+ case "$2" in '') usage ;; esac
+ reference="--reference=$2"
+ shift 2
+ ;;
+ --reference=*)
+ reference="$1"
+ shift
+ ;;
-m|--merge)
shift
update="merge"
@@ -348,6 +373,11 @@ cmd_update()
esac
done
+ if test -n "$init"
+ then
+ cmd_init "--" "$@" || return
+ fi
+
module_list "$@" |
while read mode sha1 stage path
do
@@ -366,7 +396,7 @@ cmd_update()
if ! test -d "$path"/.git -o -f "$path"/.git
then
- module_clone "$path" "$url" || exit
+ module_clone "$path" "$url" "$reference"|| exit
subsha1=
else
subsha1=$(unset GIT_DIR; cd "$path" &&