diff options
Diffstat (limited to 't/t5526-fetch-submodules.sh')
-rwxr-xr-x | t/t5526-fetch-submodules.sh | 158 |
1 files changed, 139 insertions, 19 deletions
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index a877dd145e..ed11569d8d 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -3,6 +3,9 @@ test_description='Recursive "git fetch" for submodules' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./test-lib.sh pwd=$(pwd) @@ -71,7 +74,7 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" ' git fetch --recurse-submodules >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "submodule.recurse option triggers recursive fetch" ' @@ -81,7 +84,7 @@ test_expect_success "submodule.recurse option triggers recursive fetch" ' git -c submodule.recurse fetch >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" ' @@ -91,7 +94,7 @@ test_expect_success "fetch --recurse-submodules -j2 has the same output behaviou GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err && + test_cmp expect.err actual.err && grep "2 tasks" trace.out ' @@ -121,7 +124,7 @@ test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses i git fetch >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "--no-recurse-submodules overrides .gitmodules config" ' @@ -152,7 +155,7 @@ test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setti git config --unset submodule.submodule.fetchRecurseSubmodules ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "--quiet propagates to submodules" ' @@ -180,7 +183,7 @@ test_expect_success "--dry-run propagates to submodules" ' git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "Without --dry-run propagates to submodules" ' @@ -189,7 +192,7 @@ test_expect_success "Without --dry-run propagates to submodules" ' git fetch --recurse-submodules >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "recurseSubmodules=true propagates into submodules" ' @@ -200,7 +203,7 @@ test_expect_success "recurseSubmodules=true propagates into submodules" ' git fetch >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "--recurse-submodules overrides config in submodule" ' @@ -214,7 +217,7 @@ test_expect_success "--recurse-submodules overrides config in submodule" ' git fetch --recurse-submodules >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "--no-recurse-submodules overrides config setting" ' @@ -254,7 +257,7 @@ test_expect_success "Recursion stops when no new submodule commits are fetched" cd downstream && git fetch >../actual.out 2>../actual.err ) && - test_i18ncmp expect.err.sub actual.err && + test_cmp expect.err.sub actual.err && test_must_be_empty actual.out ' @@ -272,7 +275,7 @@ test_expect_success "Recursion doesn't happen when new superproject commits don' git fetch >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err.file actual.err + test_cmp expect.err.file actual.err ' test_expect_success "Recursion picks up config in submodule" ' @@ -300,7 +303,7 @@ test_expect_success "Recursion picks up config in submodule" ' git config --unset fetch.recurseSubmodules ) ) && - test_i18ncmp expect.err.sub actual.err && + test_cmp expect.err.sub actual.err && test_must_be_empty actual.out ' @@ -333,7 +336,7 @@ test_expect_success "Recursion picks up all submodules when necessary" ' cd downstream && git fetch >../actual.out 2>../actual.err ) && - test_i18ncmp expect.err.2 actual.err && + test_cmp expect.err.2 actual.err && test_must_be_empty actual.out ' @@ -389,7 +392,7 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess ) ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err + test_cmp expect.err actual.err ' test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" ' @@ -406,7 +409,7 @@ test_expect_success "'--recurse-submodules=on-demand' stops when no new submodul git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err.file actual.err + test_cmp expect.err.file actual.err ' test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" ' @@ -434,7 +437,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config git config --unset fetch.recurseSubmodules ) && test_must_be_empty actual.out && - test_i18ncmp expect.err.2 actual.err + test_cmp expect.err.2 actual.err ' test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" ' @@ -462,7 +465,7 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override git config --unset submodule.submodule.fetchRecurseSubmodules ) && test_must_be_empty actual.out && - test_i18ncmp expect.err.2 actual.err + test_cmp expect.err.2 actual.err ' test_expect_success "don't fetch submodule when newly recorded commits are already present" ' @@ -481,7 +484,7 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea git fetch >../actual.out 2>../actual.err ) && test_must_be_empty actual.out && - test_i18ncmp expect.err actual.err && + test_cmp expect.err actual.err && ( cd submodule && git checkout -q sub @@ -517,7 +520,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git git reset --hard ) && test_must_be_empty actual.out && - test_i18ncmp expect.err.2 actual.err && + test_cmp expect.err.2 actual.err && git checkout HEAD^ -- .gitmodules && git add .gitmodules && git commit -m "new submodule restored .gitmodules" @@ -722,4 +725,121 @@ test_expect_success 'fetch new submodule commit intermittently referenced by sup ) ' +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 |