Raw
1 #!/bin/sh
2
3 test_description='git rev-list --exclude-hidden test'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8 test_commit_bulk --id=commit --ref=refs/heads/branch 1 &&
9 COMMIT=$(git rev-parse refs/heads/branch) &&
10 test_commit_bulk --id=tag --ref=refs/tags/lightweight 1 &&
11 TAG=$(git rev-parse refs/tags/lightweight) &&
12 test_commit_bulk --id=hidden --ref=refs/hidden/commit 1 &&
13 HIDDEN=$(git rev-parse refs/hidden/commit) &&
14 test_commit_bulk --id=namespace --ref=refs/namespaces/namespace/refs/namespaced/commit 1 &&
15 NAMESPACE=$(git rev-parse refs/namespaces/namespace/refs/namespaced/commit)
16 '
17
18 test_expect_success 'invalid section' '
19 echo "fatal: unsupported section for hidden refs: unsupported" >expected &&
20 test_must_fail git rev-list --exclude-hidden=unsupported 2>err &&
21 test_cmp expected err
22 '
23
24 for section in fetch receive uploadpack
25 do
26 test_expect_success "$section: passed multiple times" '
27 echo "fatal: --exclude-hidden= passed more than once" >expected &&
28 test_must_fail git rev-list --exclude-hidden=$section --exclude-hidden=$section 2>err &&
29 test_cmp expected err
30 '
31
32 test_expect_success "$section: without hiddenRefs" '
33 git rev-list --exclude-hidden=$section --all >out &&
34 cat >expected <<-EOF &&
35 $NAMESPACE
36 $HIDDEN
37 $TAG
38 $COMMIT
39 EOF
40 test_cmp expected out
41 '
42
43 test_expect_success "$section: hidden via transfer.hideRefs" '
44 git -c transfer.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --all >out &&
45 cat >expected <<-EOF &&
46 $NAMESPACE
47 $TAG
48 $COMMIT
49 EOF
50 test_cmp expected out
51 '
52
53 test_expect_success "$section: hidden via $section.hideRefs" '
54 git -c $section.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --all >out &&
55 cat >expected <<-EOF &&
56 $NAMESPACE
57 $TAG
58 $COMMIT
59 EOF
60 test_cmp expected out
61 '
62
63 test_expect_success "$section: respects both transfer.hideRefs and $section.hideRefs" '
64 git -c transfer.hideRefs=refs/tags/ -c $section.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --all >out &&
65 cat >expected <<-EOF &&
66 $NAMESPACE
67 $COMMIT
68 EOF
69 test_cmp expected out
70 '
71
72 test_expect_success "$section: negation without hidden refs marks everything as uninteresting" '
73 git rev-list --all --exclude-hidden=$section --not --all >out &&
74 test_must_be_empty out
75 '
76
77 test_expect_success "$section: negation with hidden refs marks them as interesting" '
78 git -c transfer.hideRefs=refs/hidden/ rev-list --all --exclude-hidden=$section --not --all >out &&
79 cat >expected <<-EOF &&
80 $HIDDEN
81 EOF
82 test_cmp expected out
83 '
84
85 test_expect_success "$section: hidden refs and excludes work together" '
86 git -c transfer.hideRefs=refs/hidden/ rev-list --exclude=refs/tags/* --exclude-hidden=$section --all >out &&
87 cat >expected <<-EOF &&
88 $NAMESPACE
89 $COMMIT
90 EOF
91 test_cmp expected out
92 '
93
94 test_expect_success "$section: excluded hidden refs get reset" '
95 git -c transfer.hideRefs=refs/ rev-list --exclude-hidden=$section --all --all >out &&
96 cat >expected <<-EOF &&
97 $NAMESPACE
98 $HIDDEN
99 $TAG
100 $COMMIT
101 EOF
102 test_cmp expected out
103 '
104
105 test_expect_success "$section: excluded hidden refs can be used with multiple pseudo-refs" '
106 git -c transfer.hideRefs=refs/ rev-list --exclude-hidden=$section --all --exclude-hidden=$section --all >out &&
107 test_must_be_empty out
108 '
109
110 test_expect_success "$section: works with --glob" '
111 git -c transfer.hideRefs=refs/hidden/ rev-list --exclude-hidden=$section --glob=refs/h* >out &&
112 cat >expected <<-EOF &&
113 $COMMIT
114 EOF
115 test_cmp expected out
116 '
117
118 test_expect_success "$section: operates on stripped refs by default" '
119 GIT_NAMESPACE=namespace git -c transfer.hideRefs=refs/namespaced/ rev-list --exclude-hidden=$section --all >out &&
120 cat >expected <<-EOF &&
121 $HIDDEN
122 $TAG
123 $COMMIT
124 EOF
125 test_cmp expected out
126 '
127
128 test_expect_success "$section: does not hide namespace by default" '
129 GIT_NAMESPACE=namespace git -c transfer.hideRefs=refs/namespaces/namespace/ rev-list --exclude-hidden=$section --all >out &&
130 cat >expected <<-EOF &&
131 $NAMESPACE
132 $HIDDEN
133 $TAG
134 $COMMIT
135 EOF
136 test_cmp expected out
137 '
138
139 test_expect_success "$section: can operate on unstripped refs" '
140 GIT_NAMESPACE=namespace git -c transfer.hideRefs=^refs/namespaces/namespace/ rev-list --exclude-hidden=$section --all >out &&
141 cat >expected <<-EOF &&
142 $HIDDEN
143 $TAG
144 $COMMIT
145 EOF
146 test_cmp expected out
147 '
148
149 for pseudoopt in remotes branches tags
150 do
151 test_expect_success "$section: fails with --$pseudoopt" '
152 test_must_fail git rev-list --exclude-hidden=$section --$pseudoopt 2>err &&
153 test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
154 '
155
156 test_expect_success "$section: fails with --$pseudoopt=pattern" '
157 test_must_fail git rev-list --exclude-hidden=$section --$pseudoopt=pattern 2>err &&
158 test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
159 '
160 done
161 done
162
163 test_done