summaryrefslogtreecommitdiffstats
path: root/t/t6301-for-each-ref-errors.sh
blob: 2667dd13fe33893086e2bdf14a94a6f3c8648d84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh

test_description='for-each-ref errors for broken refs'

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

ZEROS=$ZERO_OID

test_expect_success setup '
	MISSING=$(test_oid deadbeef) &&
	git commit --allow-empty -m "Initial" &&
	git tag testtag &&
	git for-each-ref >full-list &&
	git for-each-ref --format="%(objectname) %(refname)" >brief-list
'

test_expect_success 'Broken refs are reported correctly' '
	r=refs/heads/bogus &&
	: >.git/$r &&
	test_when_finished "rm -f .git/$r" &&
	echo "warning: ignoring broken ref $r" >broken-err &&
	git for-each-ref >out 2>err &&
	test_cmp full-list out &&
	test_cmp broken-err err
'

test_expect_success 'NULL_SHA1 refs are reported correctly' '
	r=refs/heads/zeros &&
	echo $ZEROS >.git/$r &&
	test_when_finished "rm -f .git/$r" &&
	echo "warning: ignoring broken ref $r" >zeros-err &&
	git for-each-ref >out 2>err &&
	test_cmp full-list out &&
	test_cmp zeros-err err &&
	git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
	test_cmp brief-list brief-out &&
	test_cmp zeros-err brief-err
'

test_expect_success 'Missing objects are reported correctly' '
	r=refs/heads/missing &&
	echo $MISSING >.git/$r &&
	test_when_finished "rm -f .git/$r" &&
	echo "fatal: missing object $MISSING for $r" >missing-err &&
	test_must_fail git for-each-ref 2>err &&
	test_cmp missing-err err &&
	(
		cat brief-list &&
		echo "$MISSING $r"
	) | sort -k 2 >missing-brief-expected &&
	git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
	test_cmp missing-brief-expected brief-out &&
	test_must_be_empty brief-err
'

test_expect_success 'ahead-behind requires an argument' '
	test_must_fail git for-each-ref \
		--format="%(ahead-behind)" 2>err &&
	echo "fatal: expected format: %(ahead-behind:<committish>)" >expect &&
	test_cmp expect err
'

test_expect_success 'missing ahead-behind base' '
	test_must_fail git for-each-ref \
		--format="%(ahead-behind:refs/heads/missing)" 2>err &&
	echo "fatal: failed to find '\''refs/heads/missing'\''" >expect &&
	test_cmp expect err
'

test_done