Merge branch 'jk/repack-leakfix'
[git.git] / t / t6301-for-each-ref-errors.sh
blob2667dd13fe33893086e2bdf14a94a6f3c8648d84
1 #!/bin/sh
3 test_description='for-each-ref errors for broken refs'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 ZEROS=$ZERO_OID
10 test_expect_success setup '
11 MISSING=$(test_oid deadbeef) &&
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
18 test_expect_success 'Broken refs are reported correctly' '
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 &&
24 test_cmp full-list out &&
25 test_cmp broken-err err
28 test_expect_success 'NULL_SHA1 refs are reported correctly' '
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 &&
35 test_cmp zeros-err err &&
36 git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
37 test_cmp brief-list brief-out &&
38 test_cmp zeros-err brief-err
41 test_expect_success 'Missing objects are reported correctly' '
42 r=refs/heads/missing &&
43 echo $MISSING >.git/$r &&
44 test_when_finished "rm -f .git/$r" &&
45 echo "fatal: missing object $MISSING for $r" >missing-err &&
46 test_must_fail git for-each-ref 2>err &&
47 test_cmp missing-err err &&
49 cat brief-list &&
50 echo "$MISSING $r"
51 ) | sort -k 2 >missing-brief-expected &&
52 git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
53 test_cmp missing-brief-expected brief-out &&
54 test_must_be_empty brief-err
57 test_expect_success 'ahead-behind requires an argument' '
58 test_must_fail git for-each-ref \
59 --format="%(ahead-behind)" 2>err &&
60 echo "fatal: expected format: %(ahead-behind:<committish>)" >expect &&
61 test_cmp expect err
64 test_expect_success 'missing ahead-behind base' '
65 test_must_fail git for-each-ref \
66 --format="%(ahead-behind:refs/heads/missing)" 2>err &&
67 echo "fatal: failed to find '\''refs/heads/missing'\''" >expect &&
68 test_cmp expect err
71 test_done