Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 3 | test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged' |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 4 | |
Johannes Schindelin | d6c6b10 | 2020-11-18 23:44:23 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 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 && |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 16 | git branch -M main && |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 17 | git branch side && |
| 18 | |
| 19 | echo 1 >file && |
| 20 | test_tick && |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 21 | git commit -a -m "second on main" && |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 22 | |
| 23 | git checkout side && |
| 24 | echo 1 >file && |
| 25 | test_tick && |
| 26 | git commit -a -m "second on side" && |
| 27 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 28 | git merge main |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 29 | |
| 30 | ' |
| 31 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 32 | test_expect_success 'branch --contains=main' ' |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 33 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 34 | git branch --contains=main >actual && |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 35 | { |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 36 | echo " main" && echo "* side" |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 37 | } >expect && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 38 | test_cmp expect actual |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 39 | |
| 40 | ' |
| 41 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 42 | test_expect_success 'branch --contains main' ' |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 43 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 44 | git branch --contains main >actual && |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 45 | { |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 46 | echo " main" && echo "* side" |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 47 | } >expect && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 48 | test_cmp expect actual |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 49 | |
| 50 | ' |
| 51 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 52 | test_expect_success 'branch --no-contains=main' ' |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 53 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 54 | git branch --no-contains=main >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 55 | test_must_be_empty actual |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 56 | |
| 57 | ' |
| 58 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 59 | test_expect_success 'branch --no-contains main' ' |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 60 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 61 | git branch --no-contains main >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 62 | test_must_be_empty actual |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 63 | |
| 64 | ' |
| 65 | |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 66 | test_expect_success 'branch --contains=side' ' |
| 67 | |
| 68 | git branch --contains=side >actual && |
| 69 | { |
| 70 | echo "* side" |
| 71 | } >expect && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 72 | test_cmp expect actual |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 73 | |
| 74 | ' |
| 75 | |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 76 | test_expect_success 'branch --no-contains=side' ' |
| 77 | |
| 78 | git branch --no-contains=side >actual && |
| 79 | { |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 80 | echo " main" |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 81 | } >expect && |
| 82 | test_cmp expect actual |
| 83 | |
| 84 | ' |
| 85 | |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 86 | test_expect_success 'branch --contains with pattern implies --list' ' |
| 87 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 88 | git branch --contains=main main >actual && |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 89 | { |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 90 | echo " main" |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 91 | } >expect && |
| 92 | test_cmp expect actual |
| 93 | |
| 94 | ' |
| 95 | |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 96 | test_expect_success 'branch --no-contains with pattern implies --list' ' |
| 97 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 98 | git branch --no-contains=main main >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 99 | test_must_be_empty actual |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 100 | |
| 101 | ' |
| 102 | |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 103 | test_expect_success 'side: branch --merged' ' |
| 104 | |
| 105 | git branch --merged >actual && |
| 106 | { |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 107 | echo " main" && |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 108 | echo "* side" |
| 109 | } >expect && |
| 110 | test_cmp expect actual |
| 111 | |
| 112 | ' |
| 113 | |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 114 | test_expect_success 'branch --merged with pattern implies --list' ' |
| 115 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 116 | git branch --merged=side main >actual && |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 117 | { |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 118 | echo " main" |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 119 | } >expect && |
| 120 | test_cmp expect actual |
| 121 | |
| 122 | ' |
| 123 | |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 124 | test_expect_success 'side: branch --no-merged' ' |
| 125 | |
| 126 | git branch --no-merged >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 127 | test_must_be_empty actual |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 128 | |
| 129 | ' |
| 130 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 131 | test_expect_success 'main: branch --merged' ' |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 132 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 133 | git checkout main && |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 134 | git branch --merged >actual && |
| 135 | { |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 136 | echo "* main" |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 137 | } >expect && |
| 138 | test_cmp expect actual |
| 139 | |
| 140 | ' |
| 141 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 142 | test_expect_success 'main: branch --no-merged' ' |
Lars Hjemli | f9fd521 | 2008-04-18 18:30:15 +0200 | [diff] [blame] | 143 | |
| 144 | git branch --no-merged >actual && |
| 145 | { |
| 146 | echo " side" |
| 147 | } >expect && |
| 148 | test_cmp expect actual |
| 149 | |
| 150 | ' |
| 151 | |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 152 | test_expect_success 'branch --no-merged with pattern implies --list' ' |
| 153 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 154 | git branch --no-merged=main main >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 155 | test_must_be_empty actual |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 156 | |
| 157 | ' |
| 158 | |
| 159 | test_expect_success 'implicit --list conflicts with modification options' ' |
| 160 | |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 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 |
Jeff King | d040350 | 2013-01-31 01:46:11 -0500 | [diff] [blame] | 165 | |
| 166 | ' |
| 167 | |
Ævar Arnfjörð Bjarmason | b643827 | 2017-03-23 13:05:18 +0000 | [diff] [blame] | 168 | test_expect_success 'Assert that --contains only works on commits, not trees & blobs' ' |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 169 | test_must_fail git branch --contains main^{tree} && |
Ævar Arnfjörð Bjarmason | b643827 | 2017-03-23 13:05:18 +0000 | [diff] [blame] | 170 | blob=$(git hash-object -w --stdin <<-\EOF |
| 171 | Some blob |
| 172 | EOF |
| 173 | ) && |
Ævar Arnfjörð Bjarmason | ac3f5a3 | 2017-03-24 18:40:57 +0000 | [diff] [blame] | 174 | test_must_fail git branch --contains $blob && |
| 175 | test_must_fail git branch --no-contains $blob |
Ævar Arnfjörð Bjarmason | b643827 | 2017-03-23 13:05:18 +0000 | [diff] [blame] | 176 | ' |
| 177 | |
Aaron Lipman | b775d81 | 2020-09-15 22:08:38 -0400 | [diff] [blame] | 178 | test_expect_success 'multiple branch --contains' ' |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 179 | git checkout -b side2 main && |
Aaron Lipman | b775d81 | 2020-09-15 22:08:38 -0400 | [diff] [blame] | 180 | >feature && |
| 181 | git add feature && |
| 182 | git commit -m "add feature" && |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 183 | git checkout -b next main && |
Aaron Lipman | b775d81 | 2020-09-15 22:08:38 -0400 | [diff] [blame] | 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 | |
Aaron Lipman | 21bf933 | 2020-09-15 22:08:40 -0400 | [diff] [blame] | 194 | test_expect_success 'multiple branch --merged' ' |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 195 | git branch --merged next --merged main >actual && |
Aaron Lipman | 21bf933 | 2020-09-15 22:08:40 -0400 | [diff] [blame] | 196 | cat >expect <<-\EOF && |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 197 | main |
Aaron Lipman | 21bf933 | 2020-09-15 22:08:40 -0400 | [diff] [blame] | 198 | * next |
| 199 | side |
| 200 | EOF |
| 201 | test_cmp expect actual |
| 202 | ' |
| 203 | |
Aaron Lipman | b775d81 | 2020-09-15 22:08:38 -0400 | [diff] [blame] | 204 | test_expect_success 'multiple branch --no-contains' ' |
| 205 | git branch --no-contains side --no-contains side2 >actual && |
| 206 | cat >expect <<-\EOF && |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 207 | main |
Aaron Lipman | b775d81 | 2020-09-15 22:08:38 -0400 | [diff] [blame] | 208 | EOF |
| 209 | test_cmp expect actual |
| 210 | ' |
| 211 | |
Aaron Lipman | 21bf933 | 2020-09-15 22:08:40 -0400 | [diff] [blame] | 212 | test_expect_success 'multiple branch --no-merged' ' |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 213 | git branch --no-merged next --no-merged main >actual && |
Aaron Lipman | 21bf933 | 2020-09-15 22:08:40 -0400 | [diff] [blame] | 214 | cat >expect <<-\EOF && |
| 215 | side2 |
| 216 | EOF |
| 217 | test_cmp expect actual |
| 218 | ' |
| 219 | |
Aaron Lipman | b775d81 | 2020-09-15 22:08:38 -0400 | [diff] [blame] | 220 | test_expect_success 'branch --contains combined with --no-contains' ' |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 221 | git checkout -b seen main && |
Aaron Lipman | b775d81 | 2020-09-15 22:08:38 -0400 | [diff] [blame] | 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 | |
Aaron Lipman | 21bf933 | 2020-09-15 22:08:40 -0400 | [diff] [blame] | 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 | |
Jeff King | 8376a70 | 2014-09-18 06:49:43 -0400 | [diff] [blame] | 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 | # |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 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" |
Jeff King | 8376a70 | 2014-09-18 06:49:43 -0400 | [diff] [blame] | 248 | # as we process them in that order. |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 249 | test_expect_success 'branch --merged with --verbose' ' |
| 250 | git branch --track topic main && |
Jeff King | 8376a70 | 2014-09-18 06:49:43 -0400 | [diff] [blame] | 251 | git branch zzz topic && |
| 252 | git checkout topic && |
| 253 | test_commit foo && |
| 254 | git branch --merged topic >actual && |
| 255 | cat >expect <<-\EOF && |
Johannes Schindelin | 94287e7 | 2020-12-17 01:07:02 +0000 | [diff] [blame] | 256 | main |
Jeff King | 8376a70 | 2014-09-18 06:49:43 -0400 | [diff] [blame] | 257 | * topic |
| 258 | zzz |
| 259 | EOF |
| 260 | test_cmp expect actual && |
| 261 | git branch --verbose --merged topic >actual && |
brian m. carlson | a5f61c7 | 2019-08-18 19:16:33 +0000 | [diff] [blame] | 262 | cat >expect <<-EOF && |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 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 |
Jeff King | 8376a70 | 2014-09-18 06:49:43 -0400 | [diff] [blame] | 266 | EOF |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 267 | test_cmp expect actual |
Jeff King | 8376a70 | 2014-09-18 06:49:43 -0400 | [diff] [blame] | 268 | ' |
| 269 | |
Junio C Hamano | 3f7dfe7 | 2007-11-18 22:22:00 -0800 | [diff] [blame] | 270 | test_done |