]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3201-branch-contains.sh
The third batch
[thirdparty/git.git] / t / t3201-branch-contains.sh
CommitLineData
3f7dfe77
JH
1#!/bin/sh
2
ac3f5a34 3test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
3f7dfe77
JH
4
5. ./test-lib.sh
6
7test_expect_success setup '
8
9 >file &&
10 git add file &&
11 test_tick &&
12 git commit -m initial &&
94287e78 13 git branch -M main &&
3f7dfe77
JH
14 git branch side &&
15
16 echo 1 >file &&
17 test_tick &&
94287e78 18 git commit -a -m "second on main" &&
3f7dfe77
JH
19
20 git checkout side &&
21 echo 1 >file &&
22 test_tick &&
23 git commit -a -m "second on side" &&
24
94287e78 25 git merge main
3f7dfe77
JH
26
27'
28
94287e78 29test_expect_success 'branch --contains=main' '
3f7dfe77 30
94287e78 31 git branch --contains=main >actual &&
3f7dfe77 32 {
94287e78 33 echo " main" && echo "* side"
3f7dfe77 34 } >expect &&
82ebb0b6 35 test_cmp expect actual
3f7dfe77
JH
36
37'
38
94287e78 39test_expect_success 'branch --contains main' '
3f7dfe77 40
94287e78 41 git branch --contains main >actual &&
3f7dfe77 42 {
94287e78 43 echo " main" && echo "* side"
3f7dfe77 44 } >expect &&
82ebb0b6 45 test_cmp expect actual
3f7dfe77
JH
46
47'
48
94287e78 49test_expect_success 'branch --no-contains=main' '
ac3f5a34 50
94287e78 51 git branch --no-contains=main >actual &&
d3c6751b 52 test_must_be_empty actual
ac3f5a34
ÆAB
53
54'
55
94287e78 56test_expect_success 'branch --no-contains main' '
ac3f5a34 57
94287e78 58 git branch --no-contains main >actual &&
d3c6751b 59 test_must_be_empty actual
ac3f5a34
ÆAB
60
61'
62
3f7dfe77
JH
63test_expect_success 'branch --contains=side' '
64
65 git branch --contains=side >actual &&
66 {
67 echo "* side"
68 } >expect &&
82ebb0b6 69 test_cmp expect actual
3f7dfe77
JH
70
71'
72
ac3f5a34
ÆAB
73test_expect_success 'branch --no-contains=side' '
74
75 git branch --no-contains=side >actual &&
76 {
94287e78 77 echo " main"
ac3f5a34
ÆAB
78 } >expect &&
79 test_cmp expect actual
80
81'
82
d0403508
JK
83test_expect_success 'branch --contains with pattern implies --list' '
84
94287e78 85 git branch --contains=main main >actual &&
d0403508 86 {
94287e78 87 echo " main"
d0403508
JK
88 } >expect &&
89 test_cmp expect actual
90
91'
92
ac3f5a34
ÆAB
93test_expect_success 'branch --no-contains with pattern implies --list' '
94
94287e78 95 git branch --no-contains=main main >actual &&
d3c6751b 96 test_must_be_empty actual
ac3f5a34
ÆAB
97
98'
99
f9fd5210
LH
100test_expect_success 'side: branch --merged' '
101
102 git branch --merged >actual &&
103 {
94287e78 104 echo " main" &&
f9fd5210
LH
105 echo "* side"
106 } >expect &&
107 test_cmp expect actual
108
109'
110
d0403508
JK
111test_expect_success 'branch --merged with pattern implies --list' '
112
94287e78 113 git branch --merged=side main >actual &&
d0403508 114 {
94287e78 115 echo " main"
d0403508
JK
116 } >expect &&
117 test_cmp expect actual
118
119'
120
f9fd5210
LH
121test_expect_success 'side: branch --no-merged' '
122
123 git branch --no-merged >actual &&
d3c6751b 124 test_must_be_empty actual
f9fd5210
LH
125
126'
127
94287e78 128test_expect_success 'main: branch --merged' '
f9fd5210 129
94287e78 130 git checkout main &&
f9fd5210
LH
131 git branch --merged >actual &&
132 {
94287e78 133 echo "* main"
f9fd5210
LH
134 } >expect &&
135 test_cmp expect actual
136
137'
138
94287e78 139test_expect_success 'main: branch --no-merged' '
f9fd5210
LH
140
141 git branch --no-merged >actual &&
142 {
143 echo " side"
144 } >expect &&
145 test_cmp expect actual
146
147'
148
d0403508
JK
149test_expect_success 'branch --no-merged with pattern implies --list' '
150
94287e78 151 git branch --no-merged=main main >actual &&
d3c6751b 152 test_must_be_empty actual
d0403508
JK
153
154'
155
156test_expect_success 'implicit --list conflicts with modification options' '
157
94287e78
JS
158 test_must_fail git branch --contains=main -d &&
159 test_must_fail git branch --contains=main -m foo &&
160 test_must_fail git branch --no-contains=main -d &&
161 test_must_fail git branch --no-contains=main -m foo
d0403508
JK
162
163'
164
b643827b 165test_expect_success 'Assert that --contains only works on commits, not trees & blobs' '
94287e78 166 test_must_fail git branch --contains main^{tree} &&
b643827b
ÆAB
167 blob=$(git hash-object -w --stdin <<-\EOF
168 Some blob
169 EOF
170 ) &&
ac3f5a34
ÆAB
171 test_must_fail git branch --contains $blob &&
172 test_must_fail git branch --no-contains $blob
b643827b
ÆAB
173'
174
b775d812 175test_expect_success 'multiple branch --contains' '
94287e78 176 git checkout -b side2 main &&
b775d812
AL
177 >feature &&
178 git add feature &&
179 git commit -m "add feature" &&
94287e78 180 git checkout -b next main &&
b775d812
AL
181 git merge side &&
182 git branch --contains side --contains side2 >actual &&
183 cat >expect <<-\EOF &&
184 * next
185 side
186 side2
187 EOF
188 test_cmp expect actual
189'
190
21bf9339 191test_expect_success 'multiple branch --merged' '
94287e78 192 git branch --merged next --merged main >actual &&
21bf9339 193 cat >expect <<-\EOF &&
94287e78 194 main
21bf9339
AL
195 * next
196 side
197 EOF
198 test_cmp expect actual
199'
200
b775d812
AL
201test_expect_success 'multiple branch --no-contains' '
202 git branch --no-contains side --no-contains side2 >actual &&
203 cat >expect <<-\EOF &&
94287e78 204 main
b775d812
AL
205 EOF
206 test_cmp expect actual
207'
208
21bf9339 209test_expect_success 'multiple branch --no-merged' '
94287e78 210 git branch --no-merged next --no-merged main >actual &&
21bf9339
AL
211 cat >expect <<-\EOF &&
212 side2
213 EOF
214 test_cmp expect actual
215'
216
b775d812 217test_expect_success 'branch --contains combined with --no-contains' '
94287e78 218 git checkout -b seen main &&
b775d812
AL
219 git merge side &&
220 git merge side2 &&
221 git branch --contains side --no-contains side2 >actual &&
222 cat >expect <<-\EOF &&
223 next
224 side
225 EOF
226 test_cmp expect actual
227'
228
21bf9339
AL
229test_expect_success 'branch --merged combined with --no-merged' '
230 git branch --merged seen --no-merged next >actual &&
231 cat >expect <<-\EOF &&
232 * seen
233 side2
234 EOF
235 test_cmp expect actual
236'
237
8376a704
JK
238# We want to set up a case where the walk for the tracking info
239# of one branch crosses the tip of another branch (and make sure
240# that the latter walk does not mess up our flag to see if it was
241# merged).
242#
94287e78
JS
243# Here "topic" tracks "main" with one extra commit, and "zzz" points to the
244# same tip as main The name "zzz" must come alphabetically after "topic"
8376a704 245# as we process them in that order.
94287e78
JS
246test_expect_success 'branch --merged with --verbose' '
247 git branch --track topic main &&
8376a704
JK
248 git branch zzz topic &&
249 git checkout topic &&
250 test_commit foo &&
251 git branch --merged topic >actual &&
252 cat >expect <<-\EOF &&
94287e78 253 main
8376a704
JK
254 * topic
255 zzz
256 EOF
257 test_cmp expect actual &&
258 git branch --verbose --merged topic >actual &&
a5f61c7d 259 cat >expect <<-EOF &&
66713e84
JS
260 main $(git rev-parse --short main) second on main
261 * topic $(git rev-parse --short topic ) [ahead 1] foo
262 zzz $(git rev-parse --short zzz ) second on main
8376a704 263 EOF
1108cea7 264 test_cmp expect actual
8376a704
JK
265'
266
3f7dfe77 267test_done