From: Junio C Hamano Date: Wed, 30 May 2018 12:51:28 +0000 (+0900) Subject: Merge branch 'bc/hash-independent-tests' X-Git-Tag: v2.18.0-rc0~3 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9472b13201aea57d7f9212ca2678aba4d6dbdfdb?ds=inline;hp=-c Merge branch 'bc/hash-independent-tests' Many tests hardcode the raw object names, which would change once we migrate away from SHA-1. While some of them must test against exact object names, most of them do not have to use hardcoded constants in the test. The latter kind of tests have been updated to test the moral equivalent of the original without hardcoding the actual object names. * bc/hash-independent-tests: (28 commits) t5300: abstract away SHA-1-specific constants t4208: abstract away SHA-1-specific constants t4045: abstract away SHA-1-specific constants t4042: abstract away SHA-1-specific constants t4205: sort log output in a hash-independent way t/lib-diff-alternative: abstract away SHA-1-specific constants t4030: abstract away SHA-1-specific constants t4029: abstract away SHA-1-specific constants t4029: fix test indentation t4022: abstract away SHA-1-specific constants t4020: abstract away SHA-1-specific constants t4014: abstract away SHA-1-specific constants t4008: abstract away SHA-1-specific constants t4007: abstract away SHA-1-specific constants t3905: abstract away SHA-1-specific constants t3702: abstract away SHA-1-specific constants t3103: abstract away SHA-1-specific constants t2203: abstract away SHA-1-specific constants t: skip pack tests if not using SHA-1 t4044: skip test if not using SHA-1 ... --- 9472b13201aea57d7f9212ca2678aba4d6dbdfdb diff --combined t/t1400-update-ref.sh index faf0dfe993,f6dc05654e..e1fd0f0ca8 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@@ -6,7 -6,7 +6,7 @@@ test_description='Test git update-ref and basic ref logging' . ./test-lib.sh - Z=$_z40 + Z=$ZERO_OID m=refs/heads/master n_dir=refs/heads/gu @@@ -457,66 -457,6 +457,66 @@@ test_expect_success 'git cat-file blob test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F") ' +# Test adding and deleting pseudorefs + +test_expect_success 'given old value for missing pseudoref, do not create' ' + test_must_fail git update-ref PSEUDOREF $A $B 2>err && + test_path_is_missing .git/PSEUDOREF && + grep "could not read ref" err +' + +test_expect_success 'create pseudoref' ' + git update-ref PSEUDOREF $A && + test $A = $(cat .git/PSEUDOREF) +' + +test_expect_success 'overwrite pseudoref with no old value given' ' + git update-ref PSEUDOREF $B && + test $B = $(cat .git/PSEUDOREF) +' + +test_expect_success 'overwrite pseudoref with correct old value' ' + git update-ref PSEUDOREF $C $B && + test $C = $(cat .git/PSEUDOREF) +' + +test_expect_success 'do not overwrite pseudoref with wrong old value' ' + test_must_fail git update-ref PSEUDOREF $D $E 2>err && + test $C = $(cat .git/PSEUDOREF) && + grep "unexpected object ID" err +' + +test_expect_success 'delete pseudoref' ' + git update-ref -d PSEUDOREF && + test_path_is_missing .git/PSEUDOREF +' + +test_expect_success 'do not delete pseudoref with wrong old value' ' + git update-ref PSEUDOREF $A && + test_must_fail git update-ref -d PSEUDOREF $B 2>err && + test $A = $(cat .git/PSEUDOREF) && + grep "unexpected object ID" err +' + +test_expect_success 'delete pseudoref with correct old value' ' + git update-ref -d PSEUDOREF $A && + test_path_is_missing .git/PSEUDOREF +' + +test_expect_success 'create pseudoref with old OID zero' ' + git update-ref PSEUDOREF $A $Z && + test $A = $(cat .git/PSEUDOREF) +' + +test_expect_success 'do not overwrite pseudoref with old OID zero' ' + test_when_finished git update-ref -d PSEUDOREF && + test_must_fail git update-ref PSEUDOREF $B $Z 2>err && + test $A = $(cat .git/PSEUDOREF) && + grep "already exists" err +' + +# Test --stdin + a=refs/heads/a b=refs/heads/b c=refs/heads/c diff --combined t/t1512-rev-parse-disambiguation.sh index 2701462041,6537f30c9e..96fe3754c8 --- a/t/t1512-rev-parse-disambiguation.sh +++ b/t/t1512-rev-parse-disambiguation.sh @@@ -22,6 -22,12 +22,12 @@@ one tagged as v1.0.0. They all have on . ./test-lib.sh + if ! test_have_prereq SHA1 + then + skip_all='not using SHA-1 for objects' + test_done + fi + test_expect_success 'blob and tree' ' test_tick && ( @@@ -361,25 -367,4 +367,25 @@@ test_expect_success 'core.disambiguate git -c core.disambiguate=committish rev-parse $sha1^{tree} ' +test_expect_success C_LOCALE_OUTPUT 'ambiguous commits are printed by type first, then hash order' ' + test_must_fail git rev-parse 0000 2>stderr && + grep ^hint: stderr >hints && + grep 0000 hints >objects && + cat >expected <<-\EOF && + tag + commit + tree + blob + EOF + awk "{print \$3}" objects.types && + uniq objects.types.uniq && + test_cmp expected objects.types.uniq && + for type in tag commit tree blob + do + grep $type objects >$type.objects && + sort $type.objects >$type.objects.sorted && + test_cmp $type.objects.sorted $type.objects + done +' + test_done diff --combined t/t2025-worktree-add.sh index 2240498924,beaed5e7a1..d2e49f7632 --- a/t/t2025-worktree-add.sh +++ b/t/t2025-worktree-add.sh @@@ -198,25 -198,13 +198,25 @@@ test_expect_success '"add" with " dwim fails with checked out branch' ' + git checkout -b test-branch && + test_must_fail git worktree add test-branch && + test_path_is_missing test-branch +' + +test_expect_success '"add --force" with existing dwimd name doesnt die' ' + git checkout test-branch && + git worktree add --force test-branch ' test_expect_success '"add" no auto-vivify with --detach and omitted' ' @@@ -477,7 -465,7 +477,7 @@@ post_checkout_hook () test_expect_success '"add" invokes post-checkout hook (branch)' ' post_checkout_hook && { - echo $_z40 $(git rev-parse HEAD) 1 && + echo $ZERO_OID $(git rev-parse HEAD) 1 && echo $(pwd)/.git/worktrees/gumby && echo $(pwd)/gumby } >hook.expect && @@@ -488,7 -476,7 +488,7 @@@ test_expect_success '"add" invokes post-checkout hook (detached)' ' post_checkout_hook && { - echo $_z40 $(git rev-parse HEAD) 1 && + echo $ZERO_OID $(git rev-parse HEAD) 1 && echo $(pwd)/.git/worktrees/grumpy && echo $(pwd)/grumpy } >hook.expect && @@@ -506,7 -494,7 +506,7 @@@ test_expect_success '"add --no-checkout test_expect_success '"add" in other worktree invokes post-checkout hook' ' post_checkout_hook && { - echo $_z40 $(git rev-parse HEAD) 1 && + echo $ZERO_OID $(git rev-parse HEAD) 1 && echo $(pwd)/.git/worktrees/guppy && echo $(pwd)/guppy } >hook.expect && @@@ -518,7 -506,7 +518,7 @@@ test_expect_success '"add" in bare rep rm -rf bare && git clone --bare . bare && { - echo $_z40 $(git --git-dir=bare rev-parse HEAD) 1 && + echo $ZERO_OID $(git --git-dir=bare rev-parse HEAD) 1 && echo $(pwd)/bare/worktrees/goozy && echo $(pwd)/goozy } >hook.expect && diff --combined t/t4014-format-patch.sh index 6ea08fd5e9,349029f43b..028d5507a6 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@@ -578,7 -578,11 +578,11 @@@ test_expect_success 'excessive subject rm -rf patches/ && git checkout side && + before=$(git hash-object file) && + before=$(git rev-parse --short $before) && for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file && + after=$(git hash-object file) && + after=$(git rev-parse --short $after) && git update-index file && git commit -m "This is an excessively long subject line for a message due to the habit some projects have of not having a short, one-line subject at the start of the commit message, but rather sticking a whole paragraph right at the start as the only thing in the commit message. It had better not become the filename for the patch." && git format-patch -o patches/ master..side && @@@ -586,7 -590,6 +590,6 @@@ ' test_expect_success 'cover-letter inherits diff options' ' - git mv file foo && git commit -m foo && git format-patch --no-renames --cover-letter -1 && @@@ -616,7 -619,7 +619,7 @@@ test_expect_success 'shortlog of cover- ' cat > expect << EOF - index 40f36c6..2dc5c23 100644 + index $before..$after 100644 --- a/file +++ b/file @@ -13,4 +13,20 @@ C @@@ -640,7 -643,7 +643,7 @@@ test_expect_success 'format-patch respe cat > expect << EOF diff --git a/file b/file - index 40f36c6..2dc5c23 100644 + index $before..$after 100644 --- a/file +++ b/file @@ -14,3 +14,19 @@ C @@@ -1523,14 -1526,14 +1526,14 @@@ test_expect_success 'cover letter auto test_expect_success 'format-patch --zero-commit' ' git format-patch --zero-commit --stdout v2..v1 >patch2 && grep "^From " patch2 | sort | uniq >actual && - echo "From $_z40 Mon Sep 17 00:00:00 2001" >expect && + echo "From $ZERO_OID Mon Sep 17 00:00:00 2001" >expect && test_cmp expect actual ' test_expect_success 'From line has expected format' ' git format-patch --stdout v2..v1 >patch2 && grep "^From " patch2 >from && - grep "^From $_x40 Mon Sep 17 00:00:00 2001$" patch2 >filtered && + grep "^From $OID_REGEX Mon Sep 17 00:00:00 2001$" patch2 >filtered && test_cmp from filtered ' @@@ -1661,15 -1664,6 +1664,15 @@@ test_expect_success 'format-patch --bas test_write_lines 1 2 >expect && test_cmp expect actual ' +test_expect_success 'format-patch --attach cover-letter only is non-multipart' ' + test_when_finished "rm -fr patches" && + git format-patch -o patches --cover-letter --attach=mimemime --base=HEAD~ -1 && + ! egrep "^--+mimemime" patches/0000*.patch && + egrep "^--+mimemime$" patches/0001*.patch >output && + test_line_count = 2 output && + egrep "^--+mimemime--$" patches/0001*.patch >output && + test_line_count = 1 output +' test_expect_success 'format-patch --pretty=mboxrd' ' sp=" " && diff --combined t/t5300-pack-object.sh index 54eff03851,9e66637a19..87a590c4a9 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@@ -457,11 -457,6 +457,11 @@@ test_expect_success !PTHREADS,C_LOCALE_ grep -F "no threads support, ignoring pack.threads" err ' +test_expect_success 'pack-objects in too-many-packs mode' ' + GIT_TEST_FULL_IN_PACK_ARRAY=1 git repack -ad && + git fsck +' + # # WARNING! # @@@ -471,9 -466,11 +471,11 @@@ test_expect_success \ 'fake a SHA1 hash collision' \ - 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 && - cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \ - .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67' + 'long_a=$(git hash-object a | sed -e "s!^..!&/!") && + long_b=$(git hash-object b | sed -e "s!^..!&/!") && + test -f .git/objects/$long_b && + cp -f .git/objects/$long_a \ + .git/objects/$long_b' test_expect_success \ 'make sure index-pack detects the SHA1 collision' \ diff --combined t/t5516-fetch-push.sh index 3e8940eee5,d9c90f2ba5..f4d28288f0 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@@ -94,9 -94,6 +94,9 @@@ mk_child() } check_push_result () { + test $# -ge 3 || + error "bug in the test script: check_push_result requires at least 3 parameters" + repo_name="$1" shift @@@ -556,7 -553,10 +556,7 @@@ test_expect_success 'branch.*.pushremot test_expect_success 'push with dry-run' ' mk_test testrepo heads/master && - ( - cd testrepo && - old_commit=$(git show-ref -s --verify refs/heads/master) - ) && + old_commit=$(git -C testrepo show-ref -s --verify refs/heads/master) && git push --dry-run testrepo : && check_push_result testrepo $old_commit heads/master ' @@@ -612,7 -612,7 +612,7 @@@ test_expect_success 'push does not upda chmod +x testrepo/.git/hooks/pre-receive && ( cd child && - git pull .. master + git pull .. master && test_must_fail git push && test $(git rev-parse master) != \ $(git rev-parse remotes/origin/master) @@@ -634,7 -634,7 +634,7 @@@ test_expect_success 'pushing valid ref orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && newmaster=$(git show-ref -s --verify refs/heads/master) && orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && - newnext=$_z40 && + newnext=$ZERO_OID && git push testrepo refs/heads/master:refs/heads/master :refs/heads/next && ( cd testrepo/.git && @@@ -672,15 -672,15 +672,15 @@@ test_expect_success 'deleting dangling ( cd testrepo/.git && cat >pre-receive.expect <<-EOF && - $_z40 $_z40 refs/heads/master + $ZERO_OID $ZERO_OID refs/heads/master EOF cat >update.expect <<-EOF && - refs/heads/master $_z40 $_z40 + refs/heads/master $ZERO_OID $ZERO_OID EOF cat >post-receive.expect <<-EOF && - $_z40 $_z40 refs/heads/master + $ZERO_OID $ZERO_OID refs/heads/master EOF cat >post-update.expect <<-EOF && @@@ -703,12 -703,12 +703,12 @@@ test_expect_success 'deletion of a non- cd testrepo/.git && cat >pre-receive.expect <<-EOF && $orgmaster $newmaster refs/heads/master - $_z40 $_z40 refs/heads/nonexistent + $ZERO_OID $ZERO_OID refs/heads/nonexistent EOF cat >update.expect <<-EOF && refs/heads/master $orgmaster $newmaster - refs/heads/nonexistent $_z40 $_z40 + refs/heads/nonexistent $ZERO_OID $ZERO_OID EOF cat >post-receive.expect <<-EOF && @@@ -732,11 -732,11 +732,11 @@@ test_expect_success 'deletion of a non- ( cd testrepo/.git && cat >pre-receive.expect <<-EOF && - $_z40 $_z40 refs/heads/nonexistent + $ZERO_OID $ZERO_OID refs/heads/nonexistent EOF cat >update.expect <<-EOF && - refs/heads/nonexistent $_z40 $_z40 + refs/heads/nonexistent $ZERO_OID $ZERO_OID EOF test_cmp pre-receive.expect pre-receive.actual && @@@ -751,7 -751,7 +751,7 @@@ test_expect_success 'mixed ref updates orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && newmaster=$(git show-ref -s --verify refs/heads/master) && orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && - newnext=$_z40 && + newnext=$ZERO_OID && orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) && newpu=$(git show-ref -s --verify refs/heads/master) && git push testrepo refs/heads/master:refs/heads/master \ @@@ -763,14 -763,14 +763,14 @@@ $orgmaster $newmaster refs/heads/master $orgnext $newnext refs/heads/next $orgpu $newpu refs/heads/pu - $_z40 $_z40 refs/heads/nonexistent + $ZERO_OID $ZERO_OID refs/heads/nonexistent EOF cat >update.expect <<-EOF && refs/heads/master $orgmaster $newmaster refs/heads/next $orgnext $newnext refs/heads/pu $orgpu $newpu - refs/heads/nonexistent $_z40 $_z40 + refs/heads/nonexistent $ZERO_OID $ZERO_OID EOF cat >post-receive.expect <<-EOF && diff --combined t/test-lib.sh index f3771ab195,fed21c3dfc..28315706be --- a/t/test-lib.sh +++ b/t/test-lib.sh @@@ -184,6 -184,8 +184,8 @@@ _x40="$_x35$_x05 # Zero SHA-1 _z40=0000000000000000000000000000000000000000 + OID_REGEX="$_x40" + ZERO_OID=$_z40 EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904 EMPTY_BLOB=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 @@@ -195,7 -197,7 +197,7 @@@ LF= # when case-folding filenames u200c=$(printf '\342\200\214') - export _x05 _x35 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB + export _x05 _x35 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX # Each test should start with something like this, after copyright notices: # @@@ -1106,7 -1108,12 +1108,7 @@@ test_lazy_prereq UTF8_NFD_TO_NFC auml=$(printf "\303\244") aumlcdiar=$(printf "\141\314\210") >"$auml" && - case "$(echo *)" in - "$aumlcdiar") - true ;; - *) - false ;; - esac + test -f "$aumlcdiar" ' test_lazy_prereq AUTOIDENT ' @@@ -1207,3 -1214,10 +1209,10 @@@ test_lazy_prereq TIME_T_IS_64BIT 'test- test_lazy_prereq CURL ' curl --version ' + + # SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests + # which will not work with other hash algorithms and tests that work but don't + # test anything meaningful (e.g. special values which cause short collisions). + test_lazy_prereq SHA1 ' + test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 + '