]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-submodule.sh
builtin-commit: refactor short-status code into wt-status.c
[thirdparty/git.git] / git-submodule.sh
index ab1ed02a663b7e6252fe33f5224cb9653bcd50f2..ebed711da41a7ac3c4caa7ae9b7f73e0c75f4fe7 100755 (executable)
@@ -5,7 +5,7 @@
 # Copyright (c) 2007 Lars Hjemli
 
 USAGE="[--quiet] [--cached] \
-[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit <n>] [<commit>]] \
+[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \
 [--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
 OPTIONS_SPEC=
 . git-sh-setup
@@ -14,21 +14,10 @@ require_work_tree
 
 command=
 branch=
-quiet=
 reference=
 cached=
 nofetch=
-
-#
-# print stuff on stdout unless -q was specified
-#
-say()
-{
-       if test -z "$quiet"
-       then
-               echo "$@"
-       fi
-}
+update=
 
 # Resolve relative url by appending to parent's url
 resolve_relative_url ()
@@ -136,7 +125,7 @@ cmd_add()
                        shift
                        ;;
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
                        ;;
                --reference)
                        case "$2" in '') usage ;; esac
@@ -272,7 +261,7 @@ cmd_init()
        do
                case "$1" in
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
                        ;;
                --)
                        shift
@@ -310,6 +299,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
 }
@@ -327,7 +321,7 @@ cmd_update()
                case "$1" in
                -q|--quiet)
                        shift
-                       quiet=1
+                       GIT_QUIET=1
                        ;;
                -i|--init)
                        init=1
@@ -337,6 +331,10 @@ cmd_update()
                        shift
                        nofetch=1
                        ;;
+               -r|--rebase)
+                       shift
+                       update="rebase"
+                       ;;
                --reference)
                        case "$2" in '') usage ;; esac
                        reference="--reference=$2"
@@ -346,6 +344,10 @@ cmd_update()
                        reference="$1"
                        shift
                        ;;
+               -m|--merge)
+                       shift
+                       update="merge"
+                       ;;
                --)
                        shift
                        break
@@ -369,6 +371,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 +392,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 +412,27 @@ 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"
+                               ;;
+                       merge)
+                               command="git merge"
+                               action="merge"
+                               msg="merged in"
+                               ;;
+                       *)
+                               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
 }
@@ -623,7 +647,7 @@ cmd_status()
        do
                case "$1" in
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
                        ;;
                --cached)
                        cached=1
@@ -677,7 +701,7 @@ cmd_sync()
        do
                case "$1" in
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
                        shift
                        ;;
                --)
@@ -732,7 +756,7 @@ do
                command=$1
                ;;
        -q|--quiet)
-               quiet=1
+               GIT_QUIET=1
                ;;
        -b|--branch)
                case "$2" in