add update 'none' flag to disable update of submodule by default

This is useful to mark a submodule as unneeded by default. When this option is set and the user wants to work with such a submodule he needs to configure 'submodule.<name>.update=checkout' or pass the --checkout option. Then the submodule can be handled like a normal submodule. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Heiko Voigt committed Aug 11, 2011 at 19:51 UTC 322bb6e12f713900dcac7cac59c00a167f70f2c3
3 files changed +78 -1
Documentation/git-submodule.txt
+7 -1
@@ -120,6 +120,8 @@ too (and can also report changes to a submodule's work tree).
120 init::
121 Initialize the submodules, i.e. register each submodule name
122 and url found in .gitmodules into .git/config.
123 + It will also copy the value of `submodule.$name.update` into
124 + .git/config.
125 The key used in .git/config is `submodule.$name.url`.
126 This command does not alter existing information in .git/config.
127 You can then customize the submodule clone URLs in .git/config
@@ -133,7 +135,7 @@ update::
135 checkout the commit specified in the index of the containing repository.
136 This will make the submodules HEAD be detached unless `--rebase` or
137 `--merge` is specified or the key `submodule.$name.update` is set to
136 - `rebase` or `merge`.
138 + `rebase`, `merge` or `none`.
139 +
140 If the submodule is not yet initialized, and you just want to use the
141 setting as stored in .gitmodules, you can automatically initialize the
@@ -141,6 +143,10 @@ submodule with the `--init` option.
143 +
144 If `--recursive` is specified, this command will recurse into the
145 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.
150
151 summary::
152 Show commit summary between the given commit (defaults to HEAD) and
git-submodule.sh
+9
@@ -429,6 +429,9 @@ cmd_update()
429 --recursive)
430 recursive=1
431 ;;
432 + --checkout)
433 + update="checkout"
434 + ;;
435 --)
436 shift
437 break
@@ -468,6 +471,12 @@ cmd_update()
471 update_module=$(git config submodule."$name".update)
472 fi
473
474 + if test "$update_module" = "none"
475 + then
476 + echo "Skipping submodule '$path'"
477 + continue
478 + fi
479 +
480 if test -z "$url"
481 then
482 # Only mention uninitialized submodules when its
t/t7406-submodule-update.sh
+62
@@ -30,6 +30,7 @@ test_expect_success 'setup a submodule tree' '
30 git clone super submodule &&
31 git clone super rebasing &&
32 git clone super merging &&
33 + git clone super none &&
34 (cd super &&
35 git submodule add ../submodule submodule &&
36 test_tick &&
@@ -58,6 +59,11 @@ test_expect_success 'setup a submodule tree' '
59 test_tick &&
60 git commit -m "rebasing"
61 )
62 + (cd super &&
63 + git submodule add ../none none &&
64 + test_tick &&
65 + git commit -m "none"
66 + )
67 '
68
69 test_expect_success 'submodule update detaching the HEAD ' '
@@ -298,6 +304,62 @@ test_expect_success 'submodule update ignores update=rebase config for new submo
304 )
305 '
306
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 +
363 test_expect_success 'submodule update continues after checkout error' '
364 (cd super &&
365 git reset --hard HEAD &&