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