Code

fast-import: leakfix for 'ls' of dirty trees
[git.git] / git-submodule.sh
index c291eed59cca35d4b08285133acaca29bd80d372..8b9058971767dbb4d94e996876f6ba7ed178ddd6 100755 (executable)
@@ -37,12 +37,24 @@ resolve_relative_url ()
                die "remote ($remote) does not have a url defined in .git/config"
        url="$1"
        remoteurl=${remoteurl%/}
+       sep=/
        while test -n "$url"
        do
                case "$url" in
                ../*)
                        url="${url#../}"
-                       remoteurl="${remoteurl%/*}"
+                       case "$remoteurl" in
+                       */*)
+                               remoteurl="${remoteurl%/*}"
+                               ;;
+                       *:*)
+                               remoteurl="${remoteurl%:*}"
+                               sep=:
+                               ;;
+                       *)
+                               die "cannot strip one component off url '$remoteurl'"
+                               ;;
+                       esac
                        ;;
                ./*)
                        url="${url#./}"
@@ -51,7 +63,7 @@ resolve_relative_url ()
                        break;;
                esac
        done
-       echo "$remoteurl/${url%/}"
+       echo "$remoteurl$sep${url%/}"
 }
 
 #
@@ -93,20 +105,6 @@ module_clone()
        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
-       # action) and try to remove it.
-       # Note: if $path is a symlink to a directory the test will
-       # succeed but the rmdir will fail. We might want to fix this.
-       if test -d "$path"
-       then
-               rmdir "$path" 2>/dev/null ||
-               die "Directory '$path' exists, but is neither empty nor a git repository"
-       fi
-
-       test -e "$path" &&
-       die "A file already exist at path '$path'"
-
        if test -n "$reference"
        then
                git-clone "$reference" -n "$url" "$path"
@@ -241,7 +239,7 @@ cmd_add()
                        # ash fails to wordsplit ${branch:+-b "$branch"...}
                        case "$branch" in
                        '') git checkout -f -q ;;
-                       ?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
+                       ?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
                        esac
                ) || die "Unable to checkout submodule '$path'"
        fi
@@ -374,41 +372,35 @@ cmd_init()
 cmd_update()
 {
        # parse $args after "submodule ... update".
-       orig_args="$@"
+       orig_flags=
        while test $# -ne 0
        do
                case "$1" in
                -q|--quiet)
-                       shift
                        GIT_QUIET=1
                        ;;
                -i|--init)
                        init=1
-                       shift
                        ;;
                -N|--no-fetch)
-                       shift
                        nofetch=1
                        ;;
                -r|--rebase)
-                       shift
                        update="rebase"
                        ;;
                --reference)
                        case "$2" in '') usage ;; esac
                        reference="--reference=$2"
-                       shift 2
+                       orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
+                       shift
                        ;;
                --reference=*)
                        reference="$1"
-                       shift
                        ;;
                -m|--merge)
-                       shift
                        update="merge"
                        ;;
                --recursive)
-                       shift
                        recursive=1
                        ;;
                --)
@@ -422,6 +414,8 @@ cmd_update()
                        break
                        ;;
                esac
+               orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
+               shift
        done
 
        if test -n "$init"
@@ -500,7 +494,7 @@ cmd_update()
 
                if test -n "$recursive"
                then
-                       (clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
+                       (clear_local_git_env; cd "$path" && eval cmd_update "$orig_flags") ||
                        die "Failed to recurse into submodule path '$path'"
                fi
        done
@@ -733,7 +727,7 @@ cmd_summary() {
 cmd_status()
 {
        # parse $args after "submodule ... status".
-       orig_args="$@"
+       orig_flags=
        while test $# -ne 0
        do
                case "$1" in
@@ -757,6 +751,7 @@ cmd_status()
                        break
                        ;;
                esac
+               orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
                shift
        done
 
@@ -790,7 +785,7 @@ cmd_status()
                                prefix="$displaypath/"
                                clear_local_git_env
                                cd "$path" &&
-                               cmd_status $orig_args
+                               eval cmd_status "$orig_args"
                        ) ||
                        die "Failed to recurse into submodule path '$path'"
                fi