The twelfth batch
[git/gitster.git] / t / t3201-branch-contains.sh
blob6e587d27d7a5e3867d27d05d300f7e8149e77587
1 #!/bin/sh
3 test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success setup '
10 >file &&
11 git add file &&
12 test_tick &&
13 git commit -m initial &&
14 git branch -M main &&
15 git branch side &&
17 echo 1 >file &&
18 test_tick &&
19 git commit -a -m "second on main" &&
21 git checkout side &&
22 echo 1 >file &&
23 test_tick &&
24 git commit -a -m "second on side" &&
26 git merge main
30 test_expect_success 'branch --contains=main' '
32 git branch --contains=main >actual &&
34 echo " main" && echo "* side"
35 } >expect &&
36 test_cmp expect actual
40 test_expect_success 'branch --contains main' '
42 git branch --contains main >actual &&
44 echo " main" && echo "* side"
45 } >expect &&
46 test_cmp expect actual
50 test_expect_success 'branch --no-contains=main' '
52 git branch --no-contains=main >actual &&
53 test_must_be_empty actual
57 test_expect_success 'branch --no-contains main' '
59 git branch --no-contains main >actual &&
60 test_must_be_empty actual
64 test_expect_success 'branch --contains=side' '
66 git branch --contains=side >actual &&
68 echo "* side"
69 } >expect &&
70 test_cmp expect actual
74 test_expect_success 'branch --no-contains=side' '
76 git branch --no-contains=side >actual &&
78 echo " main"
79 } >expect &&
80 test_cmp expect actual
84 test_expect_success 'branch --contains with pattern implies --list' '
86 git branch --contains=main main >actual &&
88 echo " main"
89 } >expect &&
90 test_cmp expect actual
94 test_expect_success 'branch --no-contains with pattern implies --list' '
96 git branch --no-contains=main main >actual &&
97 test_must_be_empty actual
101 test_expect_success 'side: branch --merged' '
103 git branch --merged >actual &&
105 echo " main" &&
106 echo "* side"
107 } >expect &&
108 test_cmp expect actual
112 test_expect_success 'branch --merged with pattern implies --list' '
114 git branch --merged=side main >actual &&
116 echo " main"
117 } >expect &&
118 test_cmp expect actual
122 test_expect_success 'side: branch --no-merged' '
124 git branch --no-merged >actual &&
125 test_must_be_empty actual
129 test_expect_success 'main: branch --merged' '
131 git checkout main &&
132 git branch --merged >actual &&
134 echo "* main"
135 } >expect &&
136 test_cmp expect actual
140 test_expect_success 'main: branch --no-merged' '
142 git branch --no-merged >actual &&
144 echo " side"
145 } >expect &&
146 test_cmp expect actual
150 test_expect_success 'branch --no-merged with pattern implies --list' '
152 git branch --no-merged=main main >actual &&
153 test_must_be_empty actual
157 test_expect_success 'implicit --list conflicts with modification options' '
159 test_must_fail git branch --contains=main -d &&
160 test_must_fail git branch --contains=main -m foo &&
161 test_must_fail git branch --no-contains=main -d &&
162 test_must_fail git branch --no-contains=main -m foo
166 test_expect_success 'Assert that --contains only works on commits, not trees & blobs' '
167 test_must_fail git branch --contains main^{tree} &&
168 blob=$(git hash-object -w --stdin <<-\EOF
169 Some blob
171 ) &&
172 test_must_fail git branch --contains $blob &&
173 test_must_fail git branch --no-contains $blob
176 test_expect_success 'multiple branch --contains' '
177 git checkout -b side2 main &&
178 >feature &&
179 git add feature &&
180 git commit -m "add feature" &&
181 git checkout -b next main &&
182 git merge side &&
183 git branch --contains side --contains side2 >actual &&
184 cat >expect <<-\EOF &&
185 * next
186 side
187 side2
189 test_cmp expect actual
192 test_expect_success 'multiple branch --merged' '
193 git branch --merged next --merged main >actual &&
194 cat >expect <<-\EOF &&
195 main
196 * next
197 side
199 test_cmp expect actual
202 test_expect_success 'multiple branch --no-contains' '
203 git branch --no-contains side --no-contains side2 >actual &&
204 cat >expect <<-\EOF &&
205 main
207 test_cmp expect actual
210 test_expect_success 'multiple branch --no-merged' '
211 git branch --no-merged next --no-merged main >actual &&
212 cat >expect <<-\EOF &&
213 side2
215 test_cmp expect actual
218 test_expect_success 'branch --contains combined with --no-contains' '
219 git checkout -b seen main &&
220 git merge side &&
221 git merge side2 &&
222 git branch --contains side --no-contains side2 >actual &&
223 cat >expect <<-\EOF &&
224 next
225 side
227 test_cmp expect actual
230 test_expect_success 'branch --merged combined with --no-merged' '
231 git branch --merged seen --no-merged next >actual &&
232 cat >expect <<-\EOF &&
233 * seen
234 side2
236 test_cmp expect actual
239 # We want to set up a case where the walk for the tracking info
240 # of one branch crosses the tip of another branch (and make sure
241 # that the latter walk does not mess up our flag to see if it was
242 # merged).
244 # Here "topic" tracks "main" with one extra commit, and "zzz" points to the
245 # same tip as main The name "zzz" must come alphabetically after "topic"
246 # as we process them in that order.
247 test_expect_success 'branch --merged with --verbose' '
248 git branch --track topic main &&
249 git branch zzz topic &&
250 git checkout topic &&
251 test_commit foo &&
252 git branch --merged topic >actual &&
253 cat >expect <<-\EOF &&
254 main
255 * topic
258 test_cmp expect actual &&
259 git branch --verbose --merged topic >actual &&
260 cat >expect <<-EOF &&
261 main $(git rev-parse --short main) second on main
262 * topic $(git rev-parse --short topic ) [ahead 1] foo
263 zzz $(git rev-parse --short zzz ) second on main
265 test_cmp expect actual
268 test_done