]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-submodule.sh
Merge branch 'ph/submodule-rebase' (early part)
[thirdparty/git.git] / git-submodule.sh
index ab1ed02a663b7e6252fe33f5224cb9653bcd50f2..19a3a840fdc7eed4994741e13306b71a3ffd2ada 100755 (executable)
@@ -18,6 +18,7 @@ quiet=
 reference=
 cached=
 nofetch=
+update=
 
 #
 # print stuff on stdout unless -q was specified
@@ -310,6 +311,11 @@ cmd_init()
                git config submodule."$name".url "$url" ||
                die "Failed to register url for submodule path '$path'"
 
+               upd="$(git config -f .gitmodules submodule."$name".update)"
+               test -z "$upd" ||
+               git config submodule."$name".update "$upd" ||
+               die "Failed to register update mode for submodule path '$path'"
+
                say "Submodule '$name' ($url) registered for path '$path'"
        done
 }
@@ -337,6 +343,10 @@ cmd_update()
                        shift
                        nofetch=1
                        ;;
+               -r|--rebase)
+                       shift
+                       update="rebase"
+                       ;;
                --reference)
                        case "$2" in '') usage ;; esac
                        reference="--reference=$2"
@@ -369,6 +379,7 @@ cmd_update()
        do
                name=$(module_name "$path") || exit
                url=$(git config submodule."$name".url)
+               update_module=$(git config submodule."$name".update)
                if test -z "$url"
                then
                        # Only mention uninitialized submodules when its
@@ -389,6 +400,11 @@ cmd_update()
                        die "Unable to find current revision in submodule path '$path'"
                fi
 
+               if ! test -z "$update"
+               then
+                       update_module=$update
+               fi
+
                if test "$subsha1" != "$sha1"
                then
                        force=
@@ -404,11 +420,22 @@ cmd_update()
                                die "Unable to fetch in submodule path '$path'"
                        fi
 
-                       (unset GIT_DIR; cd "$path" &&
-                                 git-checkout $force -q "$sha1") ||
-                       die "Unable to checkout '$sha1' in submodule path '$path'"
+                       case "$update_module" in
+                       rebase)
+                               command="git rebase"
+                               action="rebase"
+                               msg="rebased onto"
+                               ;;
+                       *)
+                               command="git checkout $force -q"
+                               action="checkout"
+                               msg="checked out"
+                               ;;
+                       esac
 
-                       say "Submodule path '$path': checked out '$sha1'"
+                       (unset GIT_DIR; cd "$path" && $command "$sha1") ||
+                       die "Unable to $action '$sha1' in submodule path '$path'"
+                       say "Submodule path '$path': $msg '$sha1'"
                fi
        done
 }