Make 'git submodule update --force' always check out submodules.

Currently, it will only do a checkout if the sha1 registered in the containing repository doesn't match the HEAD of the submodule, regardless of whether the submodule is dirty. As discussed on the mailing list, the '--force' flag is a strong indicator that the state of the submodule is suspect, and should be reset to HEAD. Signed-off-by: Stefan Zager <szager@google.com> Acked-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Zager committed Jul 25, 2012 at 10:41 UTC 01d4721565f1562172149ebb91d29d6a7e7f922d
3 files changed +21 -2
Documentation/git-submodule.txt
+8 -1
@@ -149,6 +149,11 @@ submodule with the `--init` option.
149 +
150 If `--recursive` is specified, this command will recurse into the
151 registered submodules, and update any nested submodules within.
152 ++
153 +If `--force` is specified, the submodule will be checked out (using
154 +`git checkout --force` if appropriate), even if the commit specified in the
155 +index of the containing repository already matches the commit checked out in
156 +the submodule.
157
158 summary::
159 Show commit summary between the given commit (defaults to HEAD) and
@@ -210,7 +215,9 @@ OPTIONS
215 This option is only valid for add and update commands.
216 When running add, allow adding an otherwise ignored submodule path.
217 When running update, throw away local changes in submodules when
213 - switching to a different commit.
218 + switching to a different commit; and always run a checkout operation
219 + in the submodule, even if the commit listed in the index of the
220 + containing repository matches the commit checked out in the submodule.
221
222 --cached::
223 This option is only valid for status and summary commands. These
git-submodule.sh
+1 -1
@@ -537,7 +537,7 @@ Maybe you want to use 'update --init'?")"
537 die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
538 fi
539
540 - if test "$subsha1" != "$sha1"
540 + if test "$subsha1" != "$sha1" -o -n "$force"
541 then
542 subforce=$force
543 # If we don't already have a -f flag and the submodule has never been checked out
t/t7406-submodule-update.sh
+12
@@ -123,6 +123,18 @@ test_expect_success 'submodule update should throw away changes with --force ' '
123 )
124 '
125
126 +test_expect_success 'submodule update --force forcibly checks out submodules' '
127 + (cd super &&
128 + (cd submodule &&
129 + rm -f file
130 + ) &&
131 + git submodule update --force submodule &&
132 + (cd submodule &&
133 + test "$(git status -s file)" = ""
134 + )
135 + )
136 +'
137 +
138 test_expect_success 'submodule update --rebase staying on master' '
139 (cd super/submodule &&
140 git checkout master