3 test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
7 test_expect_success setup '
12 git commit -m initial &&
17 git commit -a -m "second on master" &&
22 git commit -a -m "second on side" &&
28 test_expect_success 'branch --contains=master' '
30 git branch --contains=master >actual &&
32 echo " master" && echo "* side"
34 test_cmp expect actual
38 test_expect_success 'branch --contains master' '
40 git branch --contains master >actual &&
42 echo " master" && echo "* side"
44 test_cmp expect actual
48 test_expect_success 'branch --no-contains=master' '
50 git branch --no-contains=master >actual &&
51 test_must_be_empty actual
55 test_expect_success 'branch --no-contains master' '
57 git branch --no-contains master >actual &&
58 test_must_be_empty actual
62 test_expect_success 'branch --contains=side' '
64 git branch --contains=side >actual &&
68 test_cmp expect actual
72 test_expect_success 'branch --no-contains=side' '
74 git branch --no-contains=side >actual &&
78 test_cmp expect actual
82 test_expect_success 'branch --contains with pattern implies --list' '
84 git branch --contains=master master >actual &&
88 test_cmp expect actual
92 test_expect_success 'branch --no-contains with pattern implies --list' '
94 git branch --no-contains=master master >actual &&
95 test_must_be_empty actual
99 test_expect_success 'side: branch --merged' '
101 git branch --merged >actual &&
106 test_cmp expect actual
110 test_expect_success 'branch --merged with pattern implies --list' '
112 git branch --merged=side master >actual &&
116 test_cmp expect actual
120 test_expect_success 'side: branch --no-merged' '
122 git branch --no-merged >actual &&
123 test_must_be_empty actual
127 test_expect_success 'master: branch --merged' '
129 git checkout master &&
130 git branch --merged >actual &&
134 test_cmp expect actual
138 test_expect_success 'master: branch --no-merged' '
140 git branch --no-merged >actual &&
144 test_cmp expect actual
148 test_expect_success 'branch --no-merged with pattern implies --list' '
150 git branch --no-merged=master master >actual &&
151 test_must_be_empty actual
155 test_expect_success 'implicit --list conflicts with modification options' '
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
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
170 test_must_fail git branch --contains $blob &&
171 test_must_fail git branch --no-contains $blob
174 # We want to set up a case where the walk for the tracking info
175 # of one branch crosses the tip of another branch (and make sure
176 # that the latter walk does not mess up our flag to see if it was
179 # Here "topic" tracks "master" with one extra commit, and "zzz" points to the
180 # same tip as master The name "zzz" must come alphabetically after "topic"
181 # as we process them in that order.
182 test_expect_success 'branch --merged with --verbose' '
183 git branch --track topic master &&
184 git branch zzz topic &&
185 git checkout topic &&
187 git branch --merged topic >actual &&
188 cat >expect <<-\EOF &&
193 test_cmp expect actual &&
194 git branch --verbose --merged topic >actual &&
195 cat >expect <<-EOF &&
196 master $(git rev-parse --short master) second on master
197 * topic $(git rev-parse --short topic ) [ahead 1] foo
198 zzz $(git rev-parse --short zzz ) second on master
200 test_i18ncmp expect actual
203 test_expect_success 'branch --contains combined with --no-contains' '
204 git branch --contains zzz --no-contains topic >actual &&
205 cat >expect <<-\EOF &&
210 test_cmp expect actual