Skip to content

Commit 61f9db7

Browse files
committed
Merge branch 'hv/submodule-update-none'
* hv/submodule-update-none: add update 'none' flag to disable update of submodule by default submodule: move update configuration variable further up
2 parents efc5fb6 + 322bb6e commit 61f9db7

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

Documentation/git-submodule.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ too (and can also report changes to a submodule's work tree).
120120
init::
121121
Initialize the submodules, i.e. register each submodule name
122122
and url found in .gitmodules into .git/config.
123+
It will also copy the value of `submodule.$name.update` into
124+
.git/config.
123125
The key used in .git/config is `submodule.$name.url`.
124126
This command does not alter existing information in .git/config.
125127
You can then customize the submodule clone URLs in .git/config
@@ -133,14 +135,18 @@ update::
133135
checkout the commit specified in the index of the containing repository.
134136
This will make the submodules HEAD be detached unless `--rebase` or
135137
`--merge` is specified or the key `submodule.$name.update` is set to
136-
`rebase` or `merge`.
138+
`rebase`, `merge` or `none`.
137139
+
138140
If the submodule is not yet initialized, and you just want to use the
139141
setting as stored in .gitmodules, you can automatically initialize the
140142
submodule with the `--init` option.
141143
+
142144
If `--recursive` is specified, this command will recurse into the
143145
registered submodules, and update any nested submodules within.
146+
+
147+
If the configuration key `submodule.$name.update` is set to `none` the
148+
submodule with name `$name` will not be updated by default. This can be
149+
overriden by adding `--checkout` to the command.
144150

145151
summary::
146152
Show commit summary between the given commit (defaults to HEAD) and

t/t7406-submodule-update.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test_expect_success 'setup a submodule tree' '
3030
git clone super submodule &&
3131
git clone super rebasing &&
3232
git clone super merging &&
33+
git clone super none &&
3334
(cd super &&
3435
git submodule add ../submodule submodule &&
3536
test_tick &&
@@ -58,6 +59,11 @@ test_expect_success 'setup a submodule tree' '
5859
test_tick &&
5960
git commit -m "rebasing"
6061
)
62+
(cd super &&
63+
git submodule add ../none none &&
64+
test_tick &&
65+
git commit -m "none"
66+
)
6167
'
6268

6369
test_expect_success 'submodule update detaching the HEAD ' '
@@ -298,6 +304,62 @@ test_expect_success 'submodule update ignores update=rebase config for new submo
298304
)
299305
'
300306

307+
test_expect_success 'submodule init picks up update=none' '
308+
(cd super &&
309+
git config -f .gitmodules submodule.none.update none &&
310+
git submodule init none &&
311+
test "none" = "$(git config submodule.none.update)"
312+
)
313+
'
314+
315+
test_expect_success 'submodule update - update=none in .git/config' '
316+
(cd super &&
317+
git config submodule.submodule.update none &&
318+
(cd submodule &&
319+
git checkout master &&
320+
compare_head
321+
) &&
322+
git diff --raw | grep " submodule" &&
323+
git submodule update &&
324+
git diff --raw | grep " submodule" &&
325+
(cd submodule &&
326+
compare_head
327+
) &&
328+
git config --unset submodule.submodule.update &&
329+
git submodule update submodule
330+
)
331+
'
332+
333+
test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
334+
(cd super &&
335+
git config submodule.submodule.update none &&
336+
(cd submodule &&
337+
git checkout master &&
338+
compare_head
339+
) &&
340+
git diff --raw | grep " submodule" &&
341+
git submodule update --checkout &&
342+
test_must_fail git diff --raw \| grep " submodule" &&
343+
(cd submodule &&
344+
test_must_fail compare_head
345+
) &&
346+
git config --unset submodule.submodule.update
347+
)
348+
'
349+
350+
test_expect_success 'submodule update --init skips submodule with update=none' '
351+
(cd super &&
352+
git add .gitmodules &&
353+
git commit -m ".gitmodules"
354+
) &&
355+
git clone super cloned &&
356+
(cd cloned &&
357+
git submodule update --init &&
358+
test -e submodule/.git &&
359+
test_must_fail test -e none/.git
360+
)
361+
'
362+
301363
test_expect_success 'submodule update continues after checkout error' '
302364
(cd super &&
303365
git reset --hard HEAD &&

0 commit comments

Comments
 (0)