Skip to content

Commit 81dbbf7

Browse files
committed
Merge branch 'sz/submodule-force-update'
"git submodule update --force" used to leave the working tree of the submodule intact when there were local changes. It is more intiutive to make "--force" a sign to run "checkout -f" to overwrite them. * sz/submodule-force-update: Make 'git submodule update --force' always check out submodules.
2 parents 799beac + 01d4721 commit 81dbbf7

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
@@ -603,7 +603,7 @@ Maybe you want to use 'update --init'?")"
603603
die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
604604
fi
605605

606-
if test "$subsha1" != "$sha1"
606+
if test "$subsha1" != "$sha1" -o -n "$force"
607607
then
608608
subforce=$force
609609
# 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)