Code

Rename submodule.<name>.rebase to submodule.<name>.update
authorJohan Herland <johan@herland.net>
Wed, 3 Jun 2009 06:27:06 +0000 (08:27 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Jun 2009 07:04:52 +0000 (00:04 -0700)
The addition of "submodule.<name>.rebase" demonstrates the usefulness of
alternatives to the default behaviour of "git submodule update". However,
by naming the config variable "submodule.<name>.rebase", and making it a
boolean choice, we are artificially constraining future git versions that
may want to add _more_ alternatives than just "rebase".

Therefore, while "submodule.<name>.rebase" is not yet in a stable git
release, future-proof it, by changing it from

  submodule.<name>.rebase = true/false

to

  submodule.<name>.update = rebase/checkout

where "checkout" specifies the default behaviour of "git submodule update"
(checking out the new commit to a detached HEAD), and "rebase" specifies
the --rebase behaviour (where the current local branch in the submodule is
rebase onto the new commit). Thus .update == checkout is equivalent to
.rebase == false, and .update == rebase is equivalent to .rebase == true.
Finally, leaving .update unset is equivalent to leaving .rebase unset.

In future git versions, other alternatives to "git submodule update"
behaviour can be included by adding them to the list of allowable values
for the submodule.<name>.update variable.

Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-submodule.txt
Documentation/gitmodules.txt
git-submodule.sh
t/t7406-submodule-update.sh

index 0286409744937bac5b4bed5af775f9b9834ea126..f993469dc642d6fc84a07826c3782b8e22e3e223 100644 (file)
@@ -114,7 +114,7 @@ update::
        Update the registered submodules, i.e. clone missing submodules and
        checkout the commit specified in the index of the containing repository.
        This will make the submodules HEAD be detached unless '--rebase' is
-       specified or the key `submodule.$name.rebase` is set to `true`.
+       specified or the key `submodule.$name.update` is set to `rebase`.
 +
 If the submodule is not yet initialized, and you just want to use the
 setting as stored in .gitmodules, you can automatically initialize the
@@ -184,7 +184,7 @@ OPTIONS
        superproject. If this option is given, the submodule's HEAD will not
        be detached. If a a merge failure prevents this process, you will have
        to resolve these failures with linkgit:git-rebase[1].
-       If the key `submodule.$name.rebase` is set to `true`, this option is
+       If the key `submodule.$name.update` is set to `rebase`, this option is
        implicit.
 
 <path>...::
index 7c22c409497cbfa403d108e6009ca000acaf771f..1b67f0a9f12974afca2e8e6948d0fca564b9b17b 100644 (file)
@@ -30,8 +30,14 @@ submodule.<name>.path::
 submodule.<name>.url::
        Defines an url from where the submodule repository can be cloned.
 
-submodule.<name>.rebase::
-       Defines that the submodule should be rebased by default.
+submodule.<name>.update::
+       Defines what to do when the submodule is updated by the superproject.
+       If 'checkout' (the default), the new commit specified in the
+       superproject will be checked out in the submodule on a detached HEAD.
+       If 'rebase', the current branch of the submodule will be rebased onto
+       the commit specified in the superproject.
+       This config option is overridden if 'git submodule update' is given
+       the '--rebase' option.
 
 
 EXAMPLES
index 3176226ac7ecca9dc875a20bd5c2df607cdfb504..f384c6b2b4953110ab0f892aabdbb826ac2263da 100755 (executable)
@@ -17,7 +17,7 @@ branch=
 quiet=
 cached=
 nofetch=
-rebase=
+update=
 
 #
 # print stuff on stdout unless -q was specified
@@ -295,10 +295,10 @@ cmd_init()
                git config submodule."$name".url "$url" ||
                die "Failed to register url for submodule path '$path'"
 
-               test true != "$(git config -f .gitmodules --bool \
-                       submodule."$name".rebase)" ||
-               git config submodule."$name".rebase true ||
-               die "Failed to register submodule path '$path' as rebasing"
+               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
@@ -329,7 +329,7 @@ cmd_update()
                        ;;
                -r|--rebase)
                        shift
-                       rebase=true
+                       update="rebase"
                        ;;
                --)
                        shift
@@ -349,7 +349,7 @@ cmd_update()
        do
                name=$(module_name "$path") || exit
                url=$(git config submodule."$name".url)
-               rebase_module=$(git config --bool submodule."$name".rebase)
+               update_module=$(git config submodule."$name".update)
                if test -z "$url"
                then
                        # Only mention uninitialized submodules when its
@@ -370,9 +370,9 @@ cmd_update()
                        die "Unable to find current revision in submodule path '$path'"
                fi
 
-               if test true = "$rebase"
+               if ! test -z "$update"
                then
-                       rebase_module=true
+                       update_module=$update
                fi
 
                if test "$subsha1" != "$sha1"
@@ -390,16 +390,18 @@ cmd_update()
                                die "Unable to fetch in submodule path '$path'"
                        fi
 
-                       if test true = "$rebase_module"
-                       then
-                               command="git-rebase"
+                       case "$update_module" in
+                       rebase)
+                               command="git rebase"
                                action="rebase"
                                msg="rebased onto"
-                       else
-                               command="git-checkout $force -q"
+                               ;;
+                       *)
+                               command="git checkout $force -q"
                                action="checkout"
                                msg="checked out"
-                       fi
+                               ;;
+                       esac
 
                        (unset GIT_DIR; cd "$path" && $command "$sha1") ||
                        die "Unable to $action '$sha1' in submodule path '$path'"
index 3442c05d2a535dcd4ae7a6784db7ed268695191c..0773fe405bb792e82b658c7cea2d8815163ccd19 100755 (executable)
@@ -76,9 +76,9 @@ test_expect_success 'submodule update --rebase staying on master' '
        )
 '
 
-test_expect_success 'submodule update - rebase true in .git/config' '
+test_expect_success 'submodule update - rebase in .git/config' '
        (cd super &&
-        git config submodule.submodule.rebase true
+        git config submodule.submodule.update rebase
        ) &&
        (cd super/submodule &&
          git reset --hard HEAD~1
@@ -93,9 +93,9 @@ test_expect_success 'submodule update - rebase true in .git/config' '
        )
 '
 
-test_expect_success 'submodule update - rebase false in .git/config but --rebase given' '
+test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
        (cd super &&
-        git config submodule.submodule.rebase false
+        git config submodule.submodule.update checkout
        ) &&
        (cd super/submodule &&
          git reset --hard HEAD~1
@@ -110,9 +110,9 @@ test_expect_success 'submodule update - rebase false in .git/config but --rebase
        )
 '
 
-test_expect_success 'submodule update - rebase false in .git/config' '
+test_expect_success 'submodule update - checkout in .git/config' '
        (cd super &&
-        git config submodule.submodule.rebase false
+        git config submodule.submodule.update checkout
        ) &&
        (cd super/submodule &&
          git reset --hard HEAD^
@@ -131,9 +131,9 @@ test_expect_success 'submodule init picks up rebase' '
        (cd super &&
         git config submodule.rebasing.url git://non-existing/git &&
         git config submodule.rebasing.path does-not-matter &&
-        git config submodule.rebasing.rebase true &&
+        git config submodule.rebasing.update rebase &&
         git submodule init rebasing &&
-        test true = $(git config --bool submodule.rebasing.rebase)
+        test "rebase" = $(git config submodule.rebasing.update)
        )
 '