]>
Commit | Line | Data |
---|---|---|
c3e23dc1 MH |
1 | #!/bin/sh |
2 | ||
3 | test_description='for-each-ref errors for broken refs' | |
4 | ||
03267e86 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
c3e23dc1 MH |
6 | . ./test-lib.sh |
7 | ||
8125a58b | 8 | ZEROS=$ZERO_OID |
c3e23dc1 MH |
9 | |
10 | test_expect_success setup ' | |
abe3db14 | 11 | MISSING=$(test_oid deadbeef) && |
c3e23dc1 MH |
12 | git commit --allow-empty -m "Initial" && |
13 | git tag testtag && | |
14 | git for-each-ref >full-list && | |
15 | git for-each-ref --format="%(objectname) %(refname)" >brief-list | |
16 | ' | |
17 | ||
866a1b90 | 18 | test_expect_success REFFILES 'Broken refs are reported correctly' ' |
c3e23dc1 MH |
19 | r=refs/heads/bogus && |
20 | : >.git/$r && | |
21 | test_when_finished "rm -f .git/$r" && | |
22 | echo "warning: ignoring broken ref $r" >broken-err && | |
23 | git for-each-ref >out 2>err && | |
1108cea7 ÆAB |
24 | test_cmp full-list out && |
25 | test_cmp broken-err err | |
c3e23dc1 MH |
26 | ' |
27 | ||
866a1b90 | 28 | test_expect_success REFFILES 'NULL_SHA1 refs are reported correctly' ' |
c3e23dc1 MH |
29 | r=refs/heads/zeros && |
30 | echo $ZEROS >.git/$r && | |
31 | test_when_finished "rm -f .git/$r" && | |
32 | echo "warning: ignoring broken ref $r" >zeros-err && | |
33 | git for-each-ref >out 2>err && | |
34 | test_cmp full-list out && | |
1108cea7 | 35 | test_cmp zeros-err err && |
c3e23dc1 MH |
36 | git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err && |
37 | test_cmp brief-list brief-out && | |
1108cea7 | 38 | test_cmp zeros-err brief-err |
c3e23dc1 MH |
39 | ' |
40 | ||
41 | test_expect_success 'Missing objects are reported correctly' ' | |
866a1b90 PS |
42 | test_when_finished "git update-ref -d refs/heads/missing" && |
43 | test-tool ref-store main update-ref msg refs/heads/missing "$MISSING" "$ZERO_OID" REF_SKIP_OID_VERIFICATION && | |
44 | echo "fatal: missing object $MISSING for refs/heads/missing" >missing-err && | |
c3e23dc1 | 45 | test_must_fail git for-each-ref 2>err && |
1108cea7 | 46 | test_cmp missing-err err && |
c3e23dc1 MH |
47 | ( |
48 | cat brief-list && | |
866a1b90 | 49 | echo "$MISSING refs/heads/missing" |
c3e23dc1 MH |
50 | ) | sort -k 2 >missing-brief-expected && |
51 | git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err && | |
52 | test_cmp missing-brief-expected brief-out && | |
53 | test_must_be_empty brief-err | |
54 | ' | |
55 | ||
49abcd21 DS |
56 | test_expect_success 'ahead-behind requires an argument' ' |
57 | test_must_fail git for-each-ref \ | |
58 | --format="%(ahead-behind)" 2>err && | |
59 | echo "fatal: expected format: %(ahead-behind:<committish>)" >expect && | |
60 | test_cmp expect err | |
61 | ' | |
62 | ||
63 | test_expect_success 'missing ahead-behind base' ' | |
64 | test_must_fail git for-each-ref \ | |
65 | --format="%(ahead-behind:refs/heads/missing)" 2>err && | |
66 | echo "fatal: failed to find '\''refs/heads/missing'\''" >expect && | |
67 | test_cmp expect err | |
68 | ' | |
69 | ||
c3e23dc1 | 70 | test_done |