]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-submodule.sh
Doc: mention --delta-base-offset is the default for Porcelain commands
[thirdparty/git.git] / git-submodule.sh
index 6af1f7e7fd894d48bc22c1ad73d84b00664b26bb..3a13397e057edf88d2c810490ec3d7d755be2009 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%/}"
 }
 
 #
@@ -360,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
                        ;;
                --)
@@ -408,6 +414,8 @@ cmd_update()
                        break
                        ;;
                esac
+               orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
+               shift
        done
 
        if test -n "$init"
@@ -415,6 +423,7 @@ cmd_update()
                cmd_init "--" "$@" || return
        fi
 
+       cloned_modules=
        module_list "$@" |
        while read mode sha1 stage path
        do
@@ -434,6 +443,7 @@ cmd_update()
                if ! test -d "$path"/.git -o -f "$path"/.git
                then
                        module_clone "$path" "$url" "$reference"|| exit
+                       cloned_modules="$cloned_modules;$name"
                        subsha1=
                else
                        subsha1=$(clear_local_git_env; cd "$path" &&
@@ -461,6 +471,13 @@ cmd_update()
                                die "Unable to fetch in submodule path '$path'"
                        fi
 
+                       # Is this something we just cloned?
+                       case ";$cloned_modules;" in
+                       *";$name;"*)
+                               # then there is no local change to integrate
+                               update_module= ;;
+                       esac
+
                        case "$update_module" in
                        rebase)
                                command="git rebase"
@@ -486,7 +503,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
@@ -719,7 +736,7 @@ cmd_summary() {
 cmd_status()
 {
        # parse $args after "submodule ... status".
-       orig_args="$@"
+       orig_flags=
        while test $# -ne 0
        do
                case "$1" in
@@ -743,6 +760,7 @@ cmd_status()
                        break
                        ;;
                esac
+               orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
                shift
        done
 
@@ -776,7 +794,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