3 test_description
='for-each-ref errors for broken refs'
5 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success setup
'
11 MISSING=$(test_oid deadbeef) &&
12 git commit --allow-empty -m "Initial" &&
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' '
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' '
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 &&
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 &&
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 &&