@matheusbsbs / matheus-bagliano / commits / 42b4917862
Fork 0

git-submodule: add support for --merge.

'git submodule update --merge' merges the commit referenced by the superproject into your local branch, instead of checking it out on a detached HEAD. As evidenced by the addition of "git submodule update --rebase", it is useful to provide alternatives to the default 'checkout' behaviour of "git submodule update". One such alternative is, when updating a submodule to a new commit, to merge that commit into the current local branch in that submodule. This is useful in workflows where you want to update your submodule from its upstream, but you cannot use --rebase, because you have downstream people working on top of your submodule branch, and you don't want to disrupt their work. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johan Herland committed Jun 3, 2009 at 00:59 UTC 42b491786260eb17d97ea9fb1c4b70075bca9523
4 files changed +86 -6
Documentation/git-submodule.txt
+13 -2
@@ -113,8 +113,9 @@ init::
113 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.update` is set to `rebase`.
116 + This will make the submodules HEAD be detached unless '--rebase' or
117 + '--merge' is specified or the key `submodule.$name.update` is set to
118 + `rebase` or `merge`.
119 +
120 If the submodule is not yet initialized, and you just want to use the
121 setting as stored in .gitmodules, you can automatically initialize the
@@ -187,6 +188,16 @@ OPTIONS
188 If the key `submodule.$name.update` is set to `rebase`, this option is
189 implicit.
190
191 +--merge::
192 + This option is only valid for the update command.
193 + Merge the commit recorded in the superproject into the current branch
194 + of the submodule. If this option is given, the submodule's HEAD will
195 + not be detached. If a merge failure prevents this process, you will
196 + have to resolve the resulting conflicts within the submodule with the
197 + usual conflict resolution tools.
198 + If the key `submodule.$name.update` is set to `merge`, this option is
199 + implicit.
200 +
201 <path>...::
202 Paths to submodule(s). When specified this will restrict the command
203 to only operate on the submodules found at the specified paths.
Documentation/gitmodules.txt
+4 -2
@@ -35,9 +35,11 @@ submodule.<name>.update::
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.
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.
41 This config option is overridden if 'git submodule update' is given
40 - the '--rebase' option.
42 + the '--merge' or '--rebase' options.
43
44
45 EXAMPLES
git-submodule.sh
+10 -1
@@ -5,7 +5,7 @@
5 # Copyright (c) 2007 Lars Hjemli
6
7 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>]] \
9 [--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
10 OPTIONS_SPEC=
11 . git-sh-setup
@@ -331,6 +331,10 @@ cmd_update()
331 shift
332 update="rebase"
333 ;;
334 + -m|--merge)
335 + shift
336 + update="merge"
337 + ;;
338 --)
339 shift
340 break
@@ -396,6 +400,11 @@ cmd_update()
400 action="rebase"
401 msg="rebased onto"
402 ;;
403 + merge)
404 + command="git merge"
405 + action="merge"
406 + msg="merged in"
407 + ;;
408 *)
409 command="git checkout $force -q"
410 action="checkout"
t/t7406-submodule-update.sh
+59 -1
@@ -6,7 +6,7 @@
6 test_description='Test updating submodules
7
8 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.
10 '
11
12 . ./test-lib.sh
@@ -76,6 +76,20 @@ test_expect_success 'submodule update --rebase staying on master' '
76 )
77 '
78
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 +
93 test_expect_success 'submodule update - rebase in .git/config' '
94 (cd super &&
95 git config submodule.submodule.update rebase
@@ -110,6 +124,40 @@ test_expect_success 'submodule update - checkout in .git/config but --rebase giv
124 )
125 '
126
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 +
161 test_expect_success 'submodule update - checkout in .git/config' '
162 (cd super &&
163 git config submodule.submodule.update checkout
@@ -137,4 +185,14 @@ test_expect_success 'submodule init picks up rebase' '
185 )
186 '
187
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 +
198 test_done