Skip to content

Commit

Permalink
Make 'git submodule update --force' always check out submodules.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Stefan Zager authored and gitster committed Aug 24, 2012
1 parent e6dfbcf commit 01d4721
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Documentation/git-submodule.txt
Expand Up @@ -149,6 +149,11 @@ submodule with the `--init` option.
+
If `--recursive` is specified, this command will recurse into the
registered submodules, and update any nested submodules within.
+
If `--force` is specified, the submodule will be checked out (using
`git checkout --force` if appropriate), even if the commit specified in the
index of the containing repository already matches the commit checked out in
the submodule.

summary::
Show commit summary between the given commit (defaults to HEAD) and
Expand Down Expand Up @@ -210,7 +215,9 @@ OPTIONS
This option is only valid for add and update commands.
When running add, allow adding an otherwise ignored submodule path.
When running update, throw away local changes in submodules when
switching to a different commit.
switching to a different commit; and always run a checkout operation
in the submodule, even if the commit listed in the index of the
containing repository matches the commit checked out in the submodule.

--cached::
This option is only valid for status and summary commands. These
Expand Down
2 changes: 1 addition & 1 deletion git-submodule.sh
Expand Up @@ -537,7 +537,7 @@ Maybe you want to use 'update --init'?")"
die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
fi

if test "$subsha1" != "$sha1"
if test "$subsha1" != "$sha1" -o -n "$force"
then
subforce=$force
# If we don't already have a -f flag and the submodule has never been checked out
Expand Down
12 changes: 12 additions & 0 deletions t/t7406-submodule-update.sh
Expand Up @@ -123,6 +123,18 @@ test_expect_success 'submodule update should throw away changes with --force ' '
)
'

test_expect_success 'submodule update --force forcibly checks out submodules' '
(cd super &&
(cd submodule &&
rm -f file
) &&
git submodule update --force submodule &&
(cd submodule &&
test "$(git status -s file)" = ""
)
)
'

test_expect_success 'submodule update --rebase staying on master' '
(cd super/submodule &&
git checkout master
Expand Down

0 comments on commit 01d4721

Please sign in to comment.