3 test_description
='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
7 test_expect_success setup
'
12 git commit -m initial &&
18 git commit -a -m "second on main" &&
23 git commit -a -m "second on side" &&
29 test_expect_success
'branch --contains=main' '
31 git branch --contains=main >actual &&
33 echo " main" && echo "* side"
35 test_cmp expect actual
39 test_expect_success
'branch --contains main' '
41 git branch --contains main >actual &&
43 echo " main" && echo "* side"
45 test_cmp expect actual
49 test_expect_success
'branch --no-contains=main' '
51 git branch --no-contains=main >actual &&
52 test_must_be_empty actual
56 test_expect_success
'branch --no-contains main' '
58 git branch --no-contains main >actual &&
59 test_must_be_empty actual
63 test_expect_success
'branch --contains=side' '
65 git branch --contains=side >actual &&
69 test_cmp expect actual
73 test_expect_success
'branch --no-contains=side' '
75 git branch --no-contains=side >actual &&
79 test_cmp expect actual
83 test_expect_success
'branch --contains with pattern implies --list' '
85 git branch --contains=main main >actual &&
89 test_cmp expect actual
93 test_expect_success
'branch --no-contains with pattern implies --list' '
95 git branch --no-contains=main main >actual &&
96 test_must_be_empty actual
100 test_expect_success
'side: branch --merged' '
102 git branch --merged >actual &&
107 test_cmp expect actual
111 test_expect_success
'branch --merged with pattern implies --list' '
113 git branch --merged=side main >actual &&
117 test_cmp expect actual
121 test_expect_success
'side: branch --no-merged' '
123 git branch --no-merged >actual &&
124 test_must_be_empty actual
128 test_expect_success
'main: branch --merged' '
131 git branch --merged >actual &&
135 test_cmp expect actual
139 test_expect_success
'main: branch --no-merged' '
141 git branch --no-merged >actual &&
145 test_cmp expect actual
149 test_expect_success
'branch --no-merged with pattern implies --list' '
151 git branch --no-merged=main main >actual &&
152 test_must_be_empty actual
156 test_expect_success
'implicit --list conflicts with modification options' '
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
165 test_expect_success
'Assert that --contains only works on commits, not trees & blobs' '
166 test_must_fail git branch --contains main^{tree} &&
167 blob=$(git hash-object -w --stdin <<-\EOF
171 test_must_fail git branch --contains $blob &&
172 test_must_fail git branch --no-contains $blob
175 test_expect_success
'multiple branch --contains' '
176 git checkout -b side2 main &&
179 git commit -m "add feature" &&
180 git checkout -b next main &&
182 git branch --contains side --contains side2 >actual &&
183 cat >expect <<-\EOF &&
188 test_cmp expect actual
191 test_expect_success
'multiple branch --merged' '
192 git branch --merged next --merged main >actual &&
193 cat >expect <<-\EOF &&
198 test_cmp expect actual
201 test_expect_success
'multiple branch --no-contains' '
202 git branch --no-contains side --no-contains side2 >actual &&
203 cat >expect <<-\EOF &&
206 test_cmp expect actual
209 test_expect_success
'multiple branch --no-merged' '
210 git branch --no-merged next --no-merged main >actual &&
211 cat >expect <<-\EOF &&
214 test_cmp expect actual
217 test_expect_success
'branch --contains combined with --no-contains' '
218 git checkout -b seen main &&
221 git branch --contains side --no-contains side2 >actual &&
222 cat >expect <<-\EOF &&
226 test_cmp expect actual
229 test_expect_success
'branch --merged combined with --no-merged' '
230 git branch --merged seen --no-merged next >actual &&
231 cat >expect <<-\EOF &&
235 test_cmp expect actual
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
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"
245 # as we process them in that order.
246 test_expect_success
'branch --merged with --verbose' '
247 git branch --track topic main &&
248 git branch zzz topic &&
249 git checkout topic &&
251 git branch --merged topic >actual &&
252 cat >expect <<-\EOF &&
257 test_cmp expect actual &&
258 git branch --verbose --merged topic >actual &&
259 cat >expect <<-EOF &&
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
264 test_i18ncmp expect actual