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