Skip to content

Commit a49eb19

Browse files
committed
Merge branch 'ph/submodule-rebase'
* ph/submodule-rebase: git-submodule: add support for --merge. Conflicts: Documentation/git-submodule.txt git-submodule.sh
2 parents c28a17f + 42b4917 commit a49eb19

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

Documentation/git-submodule.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ init::
115115
update::
116116
Update the registered submodules, i.e. clone missing submodules and
117117
checkout the commit specified in the index of the containing repository.
118-
This will make the submodules HEAD be detached unless '--rebase' is
119-
specified or the key `submodule.$name.update` is set to `rebase`.
118+
This will make the submodules HEAD be detached unless '--rebase' or
119+
'--merge' is specified or the key `submodule.$name.update` is set to
120+
`rebase` or `merge`.
120121
+
121122
If the submodule is not yet initialized, and you just want to use the
122123
setting as stored in .gitmodules, you can automatically initialize the
@@ -180,6 +181,16 @@ OPTIONS
180181
This option is only valid for the update command.
181182
Don't fetch new objects from the remote site.
182183

184+
--merge::
185+
This option is only valid for the update command.
186+
Merge the commit recorded in the superproject into the current branch
187+
of the submodule. If this option is given, the submodule's HEAD will
188+
not be detached. If a merge failure prevents this process, you will
189+
have to resolve the resulting conflicts within the submodule with the
190+
usual conflict resolution tools.
191+
If the key `submodule.$name.update` is set to `merge`, this option is
192+
implicit.
193+
183194
--rebase::
184195
This option is only valid for the update command.
185196
Rebase the current branch onto the commit recorded in the

Documentation/gitmodules.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ submodule.<name>.update::
3535
If 'checkout' (the default), the new commit specified in the
3636
superproject will be checked out in the submodule on a detached HEAD.
3737
If 'rebase', the current branch of the submodule will be rebased onto
38-
the commit specified in the superproject.
38+
the commit specified in the superproject. If 'merge', the commit
39+
specified in the superproject will be merged into the current branch
40+
in the submodule.
3941
This config option is overridden if 'git submodule update' is given
40-
the '--rebase' option.
42+
the '--merge' or '--rebase' options.
4143

4244

4345
EXAMPLES

git-submodule.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright (c) 2007 Lars Hjemli
66

77
USAGE="[--quiet] [--cached] \
8-
[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit <n>] [<commit>]] \
8+
[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \
99
[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
1010
OPTIONS_SPEC=
1111
. git-sh-setup
@@ -356,6 +356,10 @@ cmd_update()
356356
reference="$1"
357357
shift
358358
;;
359+
-m|--merge)
360+
shift
361+
update="merge"
362+
;;
359363
--)
360364
shift
361365
break
@@ -426,6 +430,11 @@ cmd_update()
426430
action="rebase"
427431
msg="rebased onto"
428432
;;
433+
merge)
434+
command="git merge"
435+
action="merge"
436+
msg="merged in"
437+
;;
429438
*)
430439
command="git checkout $force -q"
431440
action="checkout"

t/t7406-submodule-update.sh

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
test_description='Test updating submodules
77
88
This test verifies that "git submodule update" detaches the HEAD of the
9-
submodule and "git submodule update --rebase" does not detach the HEAD.
9+
submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
1010
'
1111

1212
. ./test-lib.sh
@@ -76,6 +76,20 @@ test_expect_success 'submodule update --rebase staying on master' '
7676
)
7777
'
7878

79+
test_expect_success 'submodule update --merge staying on master' '
80+
(cd super/submodule &&
81+
git reset --hard HEAD~1
82+
) &&
83+
(cd super &&
84+
(cd submodule &&
85+
compare_head
86+
) &&
87+
git submodule update --merge submodule &&
88+
cd submodule &&
89+
compare_head
90+
)
91+
'
92+
7993
test_expect_success 'submodule update - rebase in .git/config' '
8094
(cd super &&
8195
git config submodule.submodule.update rebase
@@ -110,6 +124,40 @@ test_expect_success 'submodule update - checkout in .git/config but --rebase giv
110124
)
111125
'
112126

127+
test_expect_success 'submodule update - merge in .git/config' '
128+
(cd super &&
129+
git config submodule.submodule.update merge
130+
) &&
131+
(cd super/submodule &&
132+
git reset --hard HEAD~1
133+
) &&
134+
(cd super &&
135+
(cd submodule &&
136+
compare_head
137+
) &&
138+
git submodule update submodule &&
139+
cd submodule &&
140+
compare_head
141+
)
142+
'
143+
144+
test_expect_success 'submodule update - checkout in .git/config but --merge given' '
145+
(cd super &&
146+
git config submodule.submodule.update checkout
147+
) &&
148+
(cd super/submodule &&
149+
git reset --hard HEAD~1
150+
) &&
151+
(cd super &&
152+
(cd submodule &&
153+
compare_head
154+
) &&
155+
git submodule update --merge submodule &&
156+
cd submodule &&
157+
compare_head
158+
)
159+
'
160+
113161
test_expect_success 'submodule update - checkout in .git/config' '
114162
(cd super &&
115163
git config submodule.submodule.update checkout
@@ -137,4 +185,14 @@ test_expect_success 'submodule init picks up rebase' '
137185
)
138186
'
139187

188+
test_expect_success 'submodule init picks up merge' '
189+
(cd super &&
190+
git config submodule.merging.url git://non-existing/git &&
191+
git config submodule.merging.path does-not-matter &&
192+
git config submodule.merging.update merge &&
193+
git submodule init merging &&
194+
test "merge" = $(git config submodule.merging.update)
195+
)
196+
'
197+
140198
test_done

0 commit comments

Comments
 (0)