diff options
Diffstat (limited to 't/t5526-fetch-submodules.sh')
-rwxr-xr-x | t/t5526-fetch-submodules.sh | 273 |
1 files changed, 256 insertions, 17 deletions
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index 6c2f9b2ba2..53d7b8ed75 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -18,7 +18,7 @@ add_upstream_commit() { head2=$(git rev-parse --short HEAD) && echo "Fetching submodule submodule" > ../expect.err && echo "From $pwd/submodule" >> ../expect.err && - echo " $head1..$head2 master -> origin/master" >> ../expect.err + echo " $head1..$head2 sub -> origin/sub" >> ../expect.err ) && ( cd deepsubmodule && @@ -30,7 +30,7 @@ add_upstream_commit() { head2=$(git rev-parse --short HEAD) && echo "Fetching submodule submodule/subdir/deepsubmodule" >> ../expect.err echo "From $pwd/deepsubmodule" >> ../expect.err && - echo " $head1..$head2 master -> origin/master" >> ../expect.err + echo " $head1..$head2 deep -> origin/deep" >> ../expect.err ) } @@ -41,7 +41,8 @@ test_expect_success setup ' git init && echo deepsubcontent > deepsubfile && git add deepsubfile && - git commit -m new deepsubfile + git commit -m new deepsubfile && + git branch -M deep ) && mkdir submodule && ( @@ -50,10 +51,12 @@ test_expect_success setup ' echo subcontent > subfile && git add subfile && git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule && - git commit -a -m new + git commit -a -m new && + git branch -M sub ) && git submodule add "$pwd/submodule" submodule && git commit -am initial && + git branch -M super && git clone . downstream && ( cd downstream && @@ -245,7 +248,7 @@ test_expect_success "Recursion stops when no new submodule commits are fetched" 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 && + echo " $head1..$head2 super -> origin/super" >>expect.err.sub && head -3 expect.err >> expect.err.sub && ( cd downstream && @@ -263,7 +266,7 @@ test_expect_success "Recursion doesn't happen when new superproject commits don' 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 && + echo " $head1..$head2 super -> origin/super" >> expect.err.file && ( cd downstream && git fetch >../actual.out 2>../actual.err @@ -287,7 +290,7 @@ test_expect_success "Recursion picks up config in 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 && + echo " $head1..$head2 super -> origin/super" >> expect.err.sub && cat expect.err >> expect.err.sub && ( cd downstream && @@ -316,14 +319,14 @@ test_expect_success "Recursion picks up all submodules when necessary" ' head2=$(git rev-parse --short HEAD) && echo "Fetching submodule submodule" > ../expect.err.sub && echo "From $pwd/submodule" >> ../expect.err.sub && - echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub + echo " $head1..$head2 sub -> origin/sub" >> ../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 && + echo " $head1..$head2 super -> origin/super" >> expect.err.2 && cat expect.err.sub >> expect.err.2 && tail -3 expect.err >> expect.err.2 && ( @@ -349,7 +352,7 @@ test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no ne head2=$(git rev-parse --short HEAD) && echo Fetching submodule submodule > ../expect.err.sub && echo "From $pwd/submodule" >> ../expect.err.sub && - echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub + echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub ) && ( cd downstream && @@ -368,7 +371,7 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess head2=$(git rev-parse --short HEAD) && tail -3 expect.err > expect.err.deepsub && echo "From $pwd/." > expect.err && - echo " $head1..$head2 master -> origin/master" >>expect.err && + echo " $head1..$head2 super -> origin/super" >>expect.err && cat expect.err.sub >> expect.err && cat expect.err.deepsub >> expect.err && ( @@ -397,7 +400,7 @@ test_expect_success "'--recurse-submodules=on-demand' stops when no new submodul 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 && + echo " $head1..$head2 super -> origin/super" >> expect.err.file && ( cd downstream && git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err @@ -418,7 +421,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config 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 && + echo " $head1..$head2 super -> origin/super" >>expect.err.2 && head -3 expect.err >> expect.err.2 && ( cd downstream && @@ -446,7 +449,7 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override 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 && + echo " $head1..$head2 super -> origin/super" >>expect.err.2 && head -3 expect.err >> expect.err.2 && ( cd downstream && @@ -472,7 +475,7 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea git commit -m "submodule rewound" && head2=$(git rev-parse --short HEAD) && echo "From $pwd/." > expect.err && - echo " $head1..$head2 master -> origin/master" >> expect.err && + echo " $head1..$head2 super -> origin/super" >> expect.err && ( cd downstream && git fetch >../actual.out 2>../actual.err @@ -481,7 +484,7 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea test_i18ncmp expect.err actual.err && ( cd submodule && - git checkout -q master + git checkout -q sub ) ' @@ -497,7 +500,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git git commit -m "new submodule without .gitmodules" && head2=$(git rev-parse --short HEAD) && echo "From $pwd/." >expect.err.2 && - echo " $head1..$head2 master -> origin/master" >>expect.err.2 && + echo " $head1..$head2 super -> origin/super" >>expect.err.2 && head -3 expect.err >>expect.err.2 && ( cd downstream && @@ -524,6 +527,8 @@ test_expect_success 'fetching submodules respects parallel settings' ' git config fetch.recurseSubmodules true && ( cd downstream && + GIT_TRACE=$(pwd)/trace.out git fetch && + grep "1 tasks" trace.out && GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 && grep "7 tasks" trace.out && git config submodule.fetchJobs 8 && @@ -600,4 +605,238 @@ test_expect_success "fetch new commits when submodule got renamed" ' test_cmp expect actual ' +test_expect_success "fetch new submodule commits on-demand outside standard refspec" ' + # add a second submodule and ensure it is around in downstream first + git clone submodule sub1 && + git submodule add ./sub1 && + git commit -m "adding a second submodule" && + git -C downstream pull && + git -C downstream submodule update --init --recursive && + + git checkout --detach && + + C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) && + git -C submodule update-ref refs/changes/1 $C && + git update-index --cacheinfo 160000 $C submodule && + test_tick && + + D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) && + git -C sub1 update-ref refs/changes/2 $D && + git update-index --cacheinfo 160000 $D sub1 && + + git commit -m "updated submodules outside of refs/heads" && + E=$(git rev-parse HEAD) && + git update-ref refs/changes/3 $E && + ( + cd downstream && + git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch && + git -C submodule cat-file -t $C && + git -C sub1 cat-file -t $D && + git checkout --recurse-submodules FETCH_HEAD + ) +' + +test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' ' + # depends on the previous test for setup + + C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) && + git -C submodule update-ref refs/changes/4 $C && + git update-index --cacheinfo 160000 $C submodule && + test_tick && + + D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) && + git -C sub1 update-ref refs/changes/5 $D && + git update-index --cacheinfo 160000 $D sub1 && + + git commit -m "updated submodules outside of refs/heads" && + E=$(git rev-parse HEAD) && + git update-ref refs/changes/6 $E && + ( + cd downstream && + git fetch --recurse-submodules origin refs/changes/6 && + git -C submodule cat-file -t $C && + git -C sub1 cat-file -t $D && + git checkout --recurse-submodules FETCH_HEAD + ) +' + +test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' ' + # depends on the previous test for setup + + git config -f .gitmodules --remove-section submodule.sub1 && + git add .gitmodules && + git commit -m "delete gitmodules file" && + git checkout -B super && + git -C downstream fetch && + git -C downstream checkout origin/super && + + C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) && + git -C submodule update-ref refs/changes/7 $C && + git update-index --cacheinfo 160000 $C submodule && + test_tick && + + D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) && + git -C sub1 update-ref refs/changes/8 $D && + git update-index --cacheinfo 160000 $D sub1 && + + git commit -m "updated submodules outside of refs/heads" && + E=$(git rev-parse HEAD) && + git update-ref refs/changes/9 $E && + ( + cd downstream && + git fetch --recurse-submodules origin refs/changes/9 && + git -C submodule cat-file -t $C && + git -C sub1 cat-file -t $D && + git checkout --recurse-submodules FETCH_HEAD + ) +' + +test_expect_success 'fetch new submodule commit intermittently referenced by superproject' ' + # depends on the previous test for setup + + D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) && + E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) && + F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) && + + git -C sub1 update-ref refs/changes/10 $D && + git update-index --cacheinfo 160000 $D sub1 && + git commit -m "updated submodules outside of refs/heads" && + + git -C sub1 update-ref refs/changes/11 $E && + git update-index --cacheinfo 160000 $E sub1 && + git commit -m "updated submodules outside of refs/heads" && + + git -C sub1 update-ref refs/changes/12 $F && + git update-index --cacheinfo 160000 $F sub1 && + git commit -m "updated submodules outside of refs/heads" && + + G=$(git rev-parse HEAD) && + git update-ref refs/changes/13 $G && + ( + cd downstream && + git fetch --recurse-submodules origin refs/changes/13 && + + git -C sub1 cat-file -t $D && + git -C sub1 cat-file -t $E && + git -C sub1 cat-file -t $F + ) +' + +add_commit_push () { + dir="$1" && + msg="$2" && + shift 2 && + git -C "$dir" add "$@" && + git -C "$dir" commit -a -m "$msg" && + git -C "$dir" push +} + +compare_refs_in_dir () { + fail= && + if test "x$1" = 'x!' + then + fail='!' && + shift + fi && + git -C "$1" rev-parse --verify "$2" >expect && + git -C "$3" rev-parse --verify "$4" >actual && + eval $fail test_cmp expect actual +} + + +test_expect_success 'setup nested submodule fetch test' ' + # does not depend on any previous test setups + + for repo in outer middle inner + do + git init --bare $repo && + git clone $repo ${repo}_content && + echo "$repo" >"${repo}_content/file" && + add_commit_push ${repo}_content "initial" file || + return 1 + done && + + git clone outer A && + git -C A submodule add "$pwd/middle" && + git -C A/middle/ submodule add "$pwd/inner" && + add_commit_push A/middle/ "adding inner sub" .gitmodules inner && + add_commit_push A/ "adding middle sub" .gitmodules middle && + + git clone outer B && + git -C B/ submodule update --init middle && + + compare_refs_in_dir A HEAD B HEAD && + compare_refs_in_dir A/middle HEAD B/middle HEAD && + test_path_is_file B/file && + test_path_is_file B/middle/file && + test_path_is_missing B/middle/inner/file && + + echo "change on inner repo of A" >"A/middle/inner/file" && + add_commit_push A/middle/inner "change on inner" file && + add_commit_push A/middle "change on inner" inner && + add_commit_push A "change on inner" middle +' + +test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' ' + # depends on previous test for setup + + git -C B/ fetch && + compare_refs_in_dir A origin/HEAD B origin/HEAD +' + +fetch_with_recursion_abort () { + # In a regression the following git call will run into infinite recursion. + # To handle that, we connect the sed command to the git call by a pipe + # so that sed can kill the infinite recursion when detected. + # The recursion creates git output like: + # Fetching submodule sub + # Fetching submodule sub/sub <-- [1] + # Fetching submodule sub/sub/sub + # ... + # [1] sed will stop reading and cause git to eventually stop and die + + git -C "$1" fetch --recurse-submodules 2>&1 | + sed "/Fetching submodule $2[^$]/q" >out && + ! grep "Fetching submodule $2[^$]" out +} + +test_expect_success 'setup recursive fetch with uninit submodule' ' + # does not depend on any previous test setups + + test_create_repo super && + test_commit -C super initial && + test_create_repo sub && + test_commit -C sub initial && + git -C sub rev-parse HEAD >expect && + + git -C super submodule add ../sub && + git -C super commit -m "add sub" && + + git clone super superclone && + git -C superclone submodule status >out && + sed -e "s/^-//" -e "s/ sub.*$//" out >actual && + test_cmp expect actual +' + +test_expect_success 'recursive fetch with uninit submodule' ' + # depends on previous test for setup + + fetch_with_recursion_abort superclone sub && + git -C superclone submodule status >out && + sed -e "s/^-//" -e "s/ sub$//" out >actual && + test_cmp expect actual +' + +test_expect_success 'recursive fetch after deinit a submodule' ' + # depends on previous test for setup + + git -C superclone submodule update --init sub && + git -C superclone submodule deinit -f sub && + + fetch_with_recursion_abort superclone sub && + git -C superclone submodule status >out && + sed -e "s/^-//" -e "s/ sub$//" out >actual && + test_cmp expect actual +' + test_done |