Skip to content

Commit 3294842

Browse files
jherlandgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca2cedb commit 3294842

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

Documentation/git-submodule.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ update::
114114
Update the registered submodules, i.e. clone missing submodules and
115115
checkout the commit specified in the index of the containing repository.
116116
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`.
118118
+
119119
If the submodule is not yet initialized, and you just want to use the
120120
setting as stored in .gitmodules, you can automatically initialize the
@@ -184,7 +184,7 @@ OPTIONS
184184
superproject. If this option is given, the submodule's HEAD will not
185185
be detached. If a a merge failure prevents this process, you will have
186186
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
188188
implicit.
189189

190190
<path>...::

Documentation/gitmodules.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ submodule.<name>.path::
3030
submodule.<name>.url::
3131
Defines an url from where the submodule repository can be cloned.
3232

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.
3541

3642

3743
EXAMPLES

git-submodule.sh

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ branch=
1717
quiet=
1818
cached=
1919
nofetch=
20-
rebase=
20+
update=
2121

2222
#
2323
# print stuff on stdout unless -q was specified
@@ -295,10 +295,10 @@ cmd_init()
295295
git config submodule."$name".url "$url" ||
296296
die "Failed to register url for submodule path '$path'"
297297

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'"
302302

303303
say "Submodule '$name' ($url) registered for path '$path'"
304304
done
@@ -329,7 +329,7 @@ cmd_update()
329329
;;
330330
-r|--rebase)
331331
shift
332-
rebase=true
332+
update="rebase"
333333
;;
334334
--)
335335
shift
@@ -349,7 +349,7 @@ cmd_update()
349349
do
350350
name=$(module_name "$path") || exit
351351
url=$(git config submodule."$name".url)
352-
rebase_module=$(git config --bool submodule."$name".rebase)
352+
update_module=$(git config submodule."$name".update)
353353
if test -z "$url"
354354
then
355355
# Only mention uninitialized submodules when its
@@ -370,9 +370,9 @@ cmd_update()
370370
die "Unable to find current revision in submodule path '$path'"
371371
fi
372372

373-
if test true = "$rebase"
373+
if ! test -z "$update"
374374
then
375-
rebase_module=true
375+
update_module=$update
376376
fi
377377

378378
if test "$subsha1" != "$sha1"
@@ -390,16 +390,18 @@ cmd_update()
390390
die "Unable to fetch in submodule path '$path'"
391391
fi
392392

393-
if test true = "$rebase_module"
394-
then
395-
command="git-rebase"
393+
case "$update_module" in
394+
rebase)
395+
command="git rebase"
396396
action="rebase"
397397
msg="rebased onto"
398-
else
399-
command="git-checkout $force -q"
398+
;;
399+
*)
400+
command="git checkout $force -q"
400401
action="checkout"
401402
msg="checked out"
402-
fi
403+
;;
404+
esac
403405

404406
(unset GIT_DIR; cd "$path" && $command "$sha1") ||
405407
die "Unable to $action '$sha1' in submodule path '$path'"

t/t7406-submodule-update.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ test_expect_success 'submodule update --rebase staying on master' '
7676
)
7777
'
7878

79-
test_expect_success 'submodule update - rebase true in .git/config' '
79+
test_expect_success 'submodule update - rebase in .git/config' '
8080
(cd super &&
81-
git config submodule.submodule.rebase true
81+
git config submodule.submodule.update rebase
8282
) &&
8383
(cd super/submodule &&
8484
git reset --hard HEAD~1
@@ -93,9 +93,9 @@ test_expect_success 'submodule update - rebase true in .git/config' '
9393
)
9494
'
9595

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' '
9797
(cd super &&
98-
git config submodule.submodule.rebase false
98+
git config submodule.submodule.update checkout
9999
) &&
100100
(cd super/submodule &&
101101
git reset --hard HEAD~1
@@ -110,9 +110,9 @@ test_expect_success 'submodule update - rebase false in .git/config but --rebase
110110
)
111111
'
112112

113-
test_expect_success 'submodule update - rebase false in .git/config' '
113+
test_expect_success 'submodule update - checkout in .git/config' '
114114
(cd super &&
115-
git config submodule.submodule.rebase false
115+
git config submodule.submodule.update checkout
116116
) &&
117117
(cd super/submodule &&
118118
git reset --hard HEAD^
@@ -131,9 +131,9 @@ test_expect_success 'submodule init picks up rebase' '
131131
(cd super &&
132132
git config submodule.rebasing.url git://non-existing/git &&
133133
git config submodule.rebasing.path does-not-matter &&
134-
git config submodule.rebasing.rebase true &&
134+
git config submodule.rebasing.update rebase &&
135135
git submodule init rebasing &&
136-
test true = $(git config --bool submodule.rebasing.rebase)
136+
test "rebase" = $(git config submodule.rebasing.update)
137137
)
138138
'
139139

0 commit comments

Comments
 (0)