@matheusbsbs / matheus-bagliano / commits / 329484256e
Fork 0

Rename submodule.<name>.rebase to submodule.<name>.update

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>

Johan Herland committed Jun 3, 2009 at 08:27 UTC 329484256e0fe42676e93669122e7a5a007ef4ed
4 files changed +35 -27
Documentation/git-submodule.txt
+2 -2
@@ -114,7 +114,7 @@ update::
114 Update the registered submodules, i.e. clone missing submodules and
115 checkout the commit specified in the index of the containing repository.
116 This will make the submodules HEAD be detached unless '--rebase' is
117 - specified or the key `submodule.$name.rebase` is set to `true`.
117 + specified or the key `submodule.$name.update` is set to `rebase`.
118 +
119 If the submodule is not yet initialized, and you just want to use the
120 setting as stored in .gitmodules, you can automatically initialize the
@@ -184,7 +184,7 @@ OPTIONS
184 superproject. If this option is given, the submodule's HEAD will not
185 be detached. If a a merge failure prevents this process, you will have
186 to resolve these failures with linkgit:git-rebase[1].
187 - If the key `submodule.$name.rebase` is set to `true`, this option is
187 + If the key `submodule.$name.update` is set to `rebase`, this option is
188 implicit.
189
190 <path>...::
Documentation/gitmodules.txt
+8 -2
@@ -30,8 +30,14 @@ submodule.<name>.path::
30 submodule.<name>.url::
31 Defines an url from where the submodule repository can be cloned.
32
33 -submodule.<name>.rebase::
34 - Defines that the submodule should be rebased by default.
33 +submodule.<name>.update::
34 + Defines what to do when the submodule is updated by the superproject.
35 + If 'checkout' (the default), the new commit specified in the
36 + superproject will be checked out in the submodule on a detached HEAD.
37 + If 'rebase', the current branch of the submodule will be rebased onto
38 + the commit specified in the superproject.
39 + This config option is overridden if 'git submodule update' is given
40 + the '--rebase' option.
41
42
43 EXAMPLES
git-submodule.sh
+17 -15
@@ -17,7 +17,7 @@ branch=
17 quiet=
18 cached=
19 nofetch=
20 -rebase=
20 +update=
21
22 #
23 # print stuff on stdout unless -q was specified
@@ -295,10 +295,10 @@ cmd_init()
295 git config submodule."$name".url "$url" ||
296 die "Failed to register url for submodule path '$path'"
297
298 - test true != "$(git config -f .gitmodules --bool \
299 - submodule."$name".rebase)" ||
300 - git config submodule."$name".rebase true ||
301 - die "Failed to register submodule path '$path' as rebasing"
298 + upd="$(git config -f .gitmodules submodule."$name".update)"
299 + test -z "$upd" ||
300 + git config submodule."$name".update "$upd" ||
301 + die "Failed to register update mode for submodule path '$path'"
302
303 say "Submodule '$name' ($url) registered for path '$path'"
304 done
@@ -329,7 +329,7 @@ cmd_update()
329 ;;
330 -r|--rebase)
331 shift
332 - rebase=true
332 + update="rebase"
333 ;;
334 --)
335 shift
@@ -349,7 +349,7 @@ cmd_update()
349 do
350 name=$(module_name "$path") || exit
351 url=$(git config submodule."$name".url)
352 - rebase_module=$(git config --bool submodule."$name".rebase)
352 + update_module=$(git config submodule."$name".update)
353 if test -z "$url"
354 then
355 # Only mention uninitialized submodules when its
@@ -370,9 +370,9 @@ cmd_update()
370 die "Unable to find current revision in submodule path '$path'"
371 fi
372
373 - if test true = "$rebase"
373 + if ! test -z "$update"
374 then
375 - rebase_module=true
375 + update_module=$update
376 fi
377
378 if test "$subsha1" != "$sha1"
@@ -390,16 +390,18 @@ cmd_update()
390 die "Unable to fetch in submodule path '$path'"
391 fi
392
393 - if test true = "$rebase_module"
394 - then
395 - command="git-rebase"
393 + case "$update_module" in
394 + rebase)
395 + command="git rebase"
396 action="rebase"
397 msg="rebased onto"
398 - else
399 - command="git-checkout $force -q"
398 + ;;
399 + *)
400 + command="git checkout $force -q"
401 action="checkout"
402 msg="checked out"
402 - fi
403 + ;;
404 + esac
405
406 (unset GIT_DIR; cd "$path" && $command "$sha1") ||
407 die "Unable to $action '$sha1' in submodule path '$path'"
t/t7406-submodule-update.sh
+8 -8
@@ -76,9 +76,9 @@ test_expect_success 'submodule update --rebase staying on master' '
76 )
77 '
78
79 -test_expect_success 'submodule update - rebase true in .git/config' '
79 +test_expect_success 'submodule update - rebase in .git/config' '
80 (cd super &&
81 - git config submodule.submodule.rebase true
81 + git config submodule.submodule.update rebase
82 ) &&
83 (cd super/submodule &&
84 git reset --hard HEAD~1
@@ -93,9 +93,9 @@ test_expect_success 'submodule update - rebase true in .git/config' '
93 )
94 '
95
96 -test_expect_success 'submodule update - rebase false in .git/config but --rebase given' '
96 +test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
97 (cd super &&
98 - git config submodule.submodule.rebase false
98 + git config submodule.submodule.update checkout
99 ) &&
100 (cd super/submodule &&
101 git reset --hard HEAD~1
@@ -110,9 +110,9 @@ test_expect_success 'submodule update - rebase false in .git/config but --rebase
110 )
111 '
112
113 -test_expect_success 'submodule update - rebase false in .git/config' '
113 +test_expect_success 'submodule update - checkout in .git/config' '
114 (cd super &&
115 - git config submodule.submodule.rebase false
115 + git config submodule.submodule.update checkout
116 ) &&
117 (cd super/submodule &&
118 git reset --hard HEAD^
@@ -131,9 +131,9 @@ test_expect_success 'submodule init picks up rebase' '
131 (cd super &&
132 git config submodule.rebasing.url git://non-existing/git &&
133 git config submodule.rebasing.path does-not-matter &&
134 - git config submodule.rebasing.rebase true &&
134 + git config submodule.rebasing.update rebase &&
135 git submodule init rebasing &&
136 - test true = $(git config --bool submodule.rebasing.rebase)
136 + test "rebase" = $(git config submodule.rebasing.update)
137 )
138 '
139