diff options
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-x | git-submodule.sh | 103 |
1 files changed, 70 insertions, 33 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index 3daa0c834..928a62f62 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -35,7 +35,7 @@ resolve_relative_url () { remote=$(get_default_remote) remoteurl=$(git config "remote.$remote.url") || - die "$(eval_gettext "remote (\$remote) does not have a url defined in .git/config")" + remoteurl=$(pwd) # the repository is its own authoritative upstream url="$1" remoteurl=${remoteurl%/} sep=/ @@ -122,14 +122,55 @@ module_clone() path=$1 url=$2 reference="$3" + quiet= + if test -n "$GIT_QUIET" + then + quiet=-q + fi + + gitdir= + gitdir_base= + name=$(module_name "$path") + base_path=$(dirname "$path") + + gitdir=$(git rev-parse --git-dir) + gitdir_base="$gitdir/modules/$base_path" + gitdir="$gitdir/modules/$path" + + case $gitdir in + /*) + a="$(cd_to_toplevel && pwd)/" + b=$gitdir + while [ "$b" ] && [ "${a%%/*}" = "${b%%/*}" ] + do + a=${a#*/} b=${b#*/}; + done - if test -n "$reference" + rel="$a$name" + rel=`echo $rel | sed -e 's|[^/]*|..|g'` + rel_gitdir="$rel/$b" + ;; + *) + rel=`echo $name | sed -e 's|[^/]*|..|g'` + rel_gitdir="$rel/$gitdir" + ;; + esac + + if test -d "$gitdir" then - git-clone "$reference" -n "$url" "$path" + mkdir -p "$path" + echo "gitdir: $rel_gitdir" >"$path/.git" + rm -f "$gitdir/index" else - git-clone -n "$url" "$path" - fi || - die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")" + mkdir -p "$gitdir_base" + if test -n "$reference" + then + git-clone $quiet "$reference" -n "$url" "$path" --separate-git-dir "$gitdir" + else + git-clone $quiet -n "$url" "$path" --separate-git-dir "$gitdir" + fi || + die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")" + fi } # @@ -223,12 +264,9 @@ cmd_add() if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1 then - ( - eval_gettext "The following path is ignored by one of your .gitignore files: + eval_gettextln "The following path is ignored by one of your .gitignore files: \$path -Use -f if you really want to add it." && - echo - ) >&2 +Use -f if you really want to add it." >&2 exit 1 fi @@ -237,19 +275,11 @@ Use -f if you really want to add it." && then if test -d "$path"/.git -o -f "$path"/.git then - eval_gettext "Adding existing repo at '\$path' to the index"; echo + eval_gettextln "Adding existing repo at '\$path' to the index" else die "$(eval_gettext "'\$path' already exists and is not a valid git repo")" fi - case "$repo" in - ./*|../*) - url=$(resolve_relative_url "$repo") || exit - ;; - *) - url="$repo" - ;; - esac else module_clone "$path" "$realrepo" "$reference" || exit @@ -263,7 +293,7 @@ Use -f if you really want to add it." && esac ) || die "$(eval_gettext "Unable to checkout submodule '\$path'")" fi - git config submodule."$path".url "$url" + git config submodule."$path".url "$realrepo" git add $force "$path" || die "$(eval_gettext "Failed to add submodule '\$path'")" @@ -432,6 +462,9 @@ cmd_update() --recursive) recursive=1 ;; + --checkout) + update="checkout" + ;; --) shift break @@ -464,7 +497,19 @@ cmd_update() fi name=$(module_name "$path") || exit url=$(git config submodule."$name".url) - update_module=$(git config submodule."$name".update) + if ! test -z "$update" + then + update_module=$update + else + update_module=$(git config submodule."$name".update) + fi + + if test "$update_module" = "none" + then + echo "Skipping submodule '$path'" + continue + fi + if test -z "$url" then # Only mention uninitialized submodules when its @@ -486,11 +531,6 @@ Maybe you want to use 'update --init'?")" die "$(eval_gettext "Unable to find current revision in submodule path '\$path'")" fi - if ! test -z "$update" - then - update_module=$update - fi - if test "$subsha1" != "$sha1" then subforce=$force @@ -704,10 +744,7 @@ cmd_summary() { ;; # removed *) # unexpected type - ( - eval_gettext "unexpected mode \$mod_dst" && - echo - ) >&2 + eval_gettextln "unexpected mode \$mod_dst" >&2 continue ;; esac fi @@ -794,9 +831,9 @@ cmd_summary() { done | if test -n "$for_status"; then if [ -n "$files" ]; then - gettext "# Submodules changed but not updated:"; echo + gettextln "# Submodules changed but not updated:" else - gettext "# Submodule changes to be committed:"; echo + gettextln "# Submodule changes to be committed:" fi echo "#" sed -e 's|^|# |' -e 's|^# $|#|' |