diff options
author | Jens Lehmann <Jens.Lehmann@web.de> | 2011-03-06 23:10:46 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-03-09 13:10:35 -0800 |
commit | 88a21979c5717e3f37b9691e90b6dbf2b94c751a (patch) | |
tree | 4ab2508d6ea972df446b45b56b470330610176d2 /t | |
parent | update-index --refresh --porcelain: add missing const (diff) | |
download | tgif-88a21979c5717e3f37b9691e90b6dbf2b94c751a.tar.xz |
fetch/pull: recurse into submodules when necessary
To be able to access all commits of populated submodules referenced by the
superproject it is sufficient to only then let "git fetch" recurse into a
submodule when the new commits fetched in the superproject record new
commits for it. Having these commits present is extremely useful when
using the "--submodule" option to "git diff" (which is what "git gui" and
"gitk" do since 1.6.6), as all submodule commits needed for creating a
descriptive output can be accessed. Also merging submodule commits (added
in 1.7.3) depends on the submodule commits in question being present to
work. Last but not least this enables disconnected operation when using
submodules, as all commits necessary for a successful "git submodule
update -N" will have been fetched automatically. So we choose this mode as
the default for fetch and pull.
Before a new or changed ref from upstream is updated in update_local_ref()
"git rev-list <new-sha1> --not --branches --remotes" is used to determine
all newly fetched commits. These are then walked and diffed against their
parent(s) to see if a submodule has been changed. If that is the case, its
path is stored to be fetched after the superproject fetch is completed.
Using the "--recurse-submodules" or the "--no-recurse-submodules" option
disables the examination of the fetched refs because the result will be
ignored anyway.
There is currently no infrastructure for storing deleted and new
submodules in the .git directory of the superproject. That's why fetch and
pull for now only fetch submodules that are already checked out and are
not renamed.
In t7403 the "--no-recurse-submodules" argument had to be added to "git
pull" to avoid failure because of the moved upstream submodule repo.
Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
Thanks-to: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t5526-fetch-submodules.sh | 109 | ||||
-rwxr-xr-x | t/t7403-submodule-sync.sh | 2 |
2 files changed, 110 insertions, 1 deletions
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index a5f458533f..6d92f7a5a7 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -192,4 +192,113 @@ test_expect_success "--no-recurse-submodules overrides config setting" ' ! test -s actual.err ' +test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" ' + ( + cd downstream && + ( + cd submodule && + git config --unset fetch.recurseSubmodules + ) && + git config --unset fetch.recurseSubmodules + git fetch >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "Recursion stops when no new submodule commits are fetched" ' + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "Fetching submodule submodule" > expect.out.sub && + echo "From $pwd/." > expect.err.sub && + echo " $head1..$head2 master -> origin/master" >> expect.err.sub + head -2 expect.err >> expect.err.sub && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + test_cmp expect.err.sub actual.err && + test_cmp expect.out.sub actual.out +' + +test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" ' + add_upstream_commit && + head1=$(git rev-parse --short HEAD) && + echo a > file && + git add file && + git commit -m "new file" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.file && + echo " $head1..$head2 master -> origin/master" >> expect.err.file && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + test_cmp expect.err.file actual.err +' + +test_expect_success "Recursion picks up config in submodule" ' + ( + cd downstream && + git fetch --recurse-submodules && + ( + cd submodule && + git config fetch.recurseSubmodules true + ) + ) && + add_upstream_commit && + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.sub && + echo " $head1..$head2 master -> origin/master" >> expect.err.sub && + cat expect.err >> expect.err.sub && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err && + ( + cd submodule && + git config --unset fetch.recurseSubmodules + ) + ) && + test_cmp expect.err.sub actual.err && + test_cmp expect.out actual.out +' + +test_expect_success "Recursion picks up all submodules when necessary" ' + add_upstream_commit && + ( + cd submodule && + ( + cd deepsubmodule && + git fetch && + git checkout -q FETCH_HEAD + ) && + head1=$(git rev-parse --short HEAD^) && + git add deepsubmodule && + git commit -m "new deepsubmodule" + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/submodule" > ../expect.err.sub && + echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub + ) && + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.2 && + echo " $head1..$head2 master -> origin/master" >> expect.err.2 && + cat expect.err.sub >> expect.err.2 && + tail -2 expect.err >> expect.err.2 && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + test_cmp expect.err.2 actual.err && + test_cmp expect.out actual.out +' + test_done diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh index e5b19538b0..d600583cef 100755 --- a/t/t7403-submodule-sync.sh +++ b/t/t7403-submodule-sync.sh @@ -52,7 +52,7 @@ test_expect_success 'change submodule url' ' test_expect_success '"git submodule sync" should update submodule URLs' ' (cd super-clone && - git pull && + git pull --no-recurse-submodules && git submodule sync ) && test -d "$(git config -f super-clone/submodule/.git/config \ |