Skip to content

Commit 01d4721

Browse files
Stefan Zagergitster
authored andcommitted
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 <[email protected]> Acked-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6dfbcf commit 01d4721

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Documentation/git-submodule.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ submodule with the `--init` option.
149149
+
150150
If `--recursive` is specified, this command will recurse into the
151151
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.
152157

153158
summary::
154159
Show commit summary between the given commit (defaults to HEAD) and
@@ -210,7 +215,9 @@ OPTIONS
210215
This option is only valid for add and update commands.
211216
When running add, allow adding an otherwise ignored submodule path.
212217
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.
214221

215222
--cached::
216223
This option is only valid for status and summary commands. These

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ Maybe you want to use 'update --init'?")"
537537
die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
538538
fi
539539

540-
if test "$subsha1" != "$sha1"
540+
if test "$subsha1" != "$sha1" -o -n "$force"
541541
then
542542
subforce=$force
543543
# If we don't already have a -f flag and the submodule has never been checked out

t/t7406-submodule-update.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ test_expect_success 'submodule update should throw away changes with --force ' '
123123
)
124124
'
125125

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+
126138
test_expect_success 'submodule update --rebase staying on master' '
127139
(cd super/submodule &&
128140
git checkout master

0 commit comments

Comments
 (0)