Git 2.45
[git/gitster.git] / t / t3201-branch-contains.sh
blob800fc33165a9eff0abe1f6edc27acb2b4978e317
1 #!/bin/sh
3 test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
5 . ./test-lib.sh
7 test_expect_success setup '
9 >file &&
10 git add file &&
11 test_tick &&
12 git commit -m initial &&
13 git branch -M main &&
14 git branch side &&
16 echo 1 >file &&
17 test_tick &&
18 git commit -a -m "second on main" &&
20 git checkout side &&
21 echo 1 >file &&
22 test_tick &&
23 git commit -a -m "second on side" &&
25 git merge main
29 test_expect_success 'branch --contains=main' '
31 git branch --contains=main >actual &&
33 echo " main" && echo "* side"
34 } >expect &&
35 test_cmp expect actual
39 test_expect_success 'branch --contains main' '
41 git branch --contains main >actual &&
43 echo " main" && echo "* side"
44 } >expect &&
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 &&
67 echo "* side"
68 } >expect &&
69 test_cmp expect actual
73 test_expect_success 'branch --no-contains=side' '
75 git branch --no-contains=side >actual &&
77 echo " main"
78 } >expect &&
79 test_cmp expect actual
83 test_expect_success 'branch --contains with pattern implies --list' '
85 git branch --contains=main main >actual &&
87 echo " main"
88 } >expect &&
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 &&
104 echo " main" &&
105 echo "* side"
106 } >expect &&
107 test_cmp expect actual
111 test_expect_success 'branch --merged with pattern implies --list' '
113 git branch --merged=side main >actual &&
115 echo " main"
116 } >expect &&
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' '
130 git checkout main &&
131 git branch --merged >actual &&
133 echo "* main"
134 } >expect &&
135 test_cmp expect actual
139 test_expect_success 'main: branch --no-merged' '
141 git branch --no-merged >actual &&
143 echo " side"
144 } >expect &&
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
168 Some blob
170 ) &&
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 &&
177 >feature &&
178 git add feature &&
179 git commit -m "add feature" &&
180 git checkout -b next main &&
181 git merge side &&
182 git branch --contains side --contains side2 >actual &&
183 cat >expect <<-\EOF &&
184 * next
185 side
186 side2
188 test_cmp expect actual
191 test_expect_success 'multiple branch --merged' '
192 git branch --merged next --merged main >actual &&
193 cat >expect <<-\EOF &&
194 main
195 * next
196 side
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 &&
204 main
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 &&
212 side2
214 test_cmp expect actual
217 test_expect_success 'branch --contains combined with --no-contains' '
218 git checkout -b seen main &&
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
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 &&
232 * seen
233 side2
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
241 # merged).
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 &&
250 test_commit foo &&
251 git branch --merged topic >actual &&
252 cat >expect <<-\EOF &&
253 main
254 * topic
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_cmp expect actual
267 test_done