summaryrefslogtreecommitdiffstats
path: root/t/t6021-rev-list-exclude-hidden.sh
blob: 32b2b09413898f400e19de2e536532027556a310 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh

test_description='git rev-list --exclude-hidden test'

. ./test-lib.sh

test_expect_success 'setup' '
	test_commit_bulk --id=commit --ref=refs/heads/branch 1 &&
	COMMIT=$(git rev-parse refs/heads/branch) &&
	test_commit_bulk --id=tag --ref=refs/tags/lightweight 1 &&
	TAG=$(git rev-parse refs/tags/lightweight) &&
	test_commit_bulk --id=hidden --ref=refs/hidden/commit 1 &&
	HIDDEN=$(git rev-parse refs/hidden/commit) &&
	test_commit_bulk --id=namespace --ref=refs/namespaces/namespace/refs/namespaced/commit 1 &&
	NAMESPACE=$(git rev-parse refs/namespaces/namespace/refs/namespaced/commit)
'

test_expect_success 'invalid section' '
	echo "fatal: unsupported section for hidden refs: unsupported" >expected &&
	test_must_fail git rev-list --exclude-hidden=unsupported 2>err &&
	test_cmp expected err
'

for section in receive uploadpack
do
	test_expect_success "$section: passed multiple times" '
		echo "fatal: --exclude-hidden= passed more than once" >expected &&
		test_must_fail git rev-list --exclude-hidden=$section --exclude-hidden=$section 2>err &&
		test_cmp expected err
	'

	test_expect_success "$section: without hiddenRefs" '
		git rev-list --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$NAMESPACE
		$HIDDEN
		$TAG
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: hidden via transfer.hideRefs" '
		git -c transfer.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$NAMESPACE
		$TAG
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: hidden via $section.hideRefs" '
		git -c $section.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$NAMESPACE
		$TAG
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: respects both transfer.hideRefs and $section.hideRefs" '
		git -c transfer.hideRefs=refs/tags/ -c $section.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$NAMESPACE
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: negation without hidden refs marks everything as uninteresting" '
		git rev-list --all --exclude-hidden=$section --not --all >out &&
		test_must_be_empty out
	'

	test_expect_success "$section: negation with hidden refs marks them as interesting" '
		git -c transfer.hideRefs=refs/hidden/ rev-list --all --exclude-hidden=$section --not --all >out &&
		cat >expected <<-EOF &&
		$HIDDEN
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: hidden refs and excludes work together" '
		git -c transfer.hideRefs=refs/hidden/ rev-list --exclude=refs/tags/* --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$NAMESPACE
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: excluded hidden refs get reset" '
		git -c transfer.hideRefs=refs/ rev-list --exclude-hidden=$section --all --all >out &&
		cat >expected <<-EOF &&
		$NAMESPACE
		$HIDDEN
		$TAG
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: excluded hidden refs can be used with multiple pseudo-refs" '
		git -c transfer.hideRefs=refs/ rev-list --exclude-hidden=$section --all --exclude-hidden=$section --all >out &&
		test_must_be_empty out
	'

	test_expect_success "$section: works with --glob" '
		git -c transfer.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --glob=refs/h* >out &&
		cat >expected <<-EOF &&
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: operates on stripped refs by default" '
		GIT_NAMESPACE=namespace git -c transfer.hideRefs=refs/namespaced/ rev-list --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$HIDDEN
		$TAG
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: does not hide namespace by default" '
		GIT_NAMESPACE=namespace git -c transfer.hideRefs=refs/namespaces/namespace/ rev-list --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$NAMESPACE
		$HIDDEN
		$TAG
		$COMMIT
		EOF
		test_cmp expected out
	'

	test_expect_success "$section: can operate on unstripped refs" '
		GIT_NAMESPACE=namespace git -c transfer.hideRefs=^refs/namespaces/namespace/ rev-list --exclude-hidden=$section --all >out &&
		cat >expected <<-EOF &&
		$HIDDEN
		$TAG
		$COMMIT
		EOF
		test_cmp expected out
	'

	for pseudoopt in remotes branches tags
	do
		test_expect_success "$section: fails with --$pseudoopt" '
			test_must_fail git rev-list --exclude-hidden=$section --$pseudoopt 2>err &&
			test_i18ngrep "error: --exclude-hidden cannot be used together with --$pseudoopt" err
		'

		test_expect_success "$section: fails with --$pseudoopt=pattern" '
			test_must_fail git rev-list --exclude-hidden=$section --$pseudoopt=pattern 2>err &&
			test_i18ngrep "error: --exclude-hidden cannot be used together with --$pseudoopt" err
		'
	done
done

test_done