Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t3201-branch-contains.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t3201-branch-contains.sh` 267 lines ยท 5425 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='branch --contains , --no-contains --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 -M main && 14 git branch side && 15 16 echo 1 >file && 17 test_tick && 18 git commit -a -m "second on main" && 19 20 git checkout side && 21 echo 1 >file && 22 test_tick && 23 git commit -a -m "second on side" && 24 25 git merge main 26 27 ' 28 29 test_expect_success 'branch --contains=main' ' 30 31 git branch --contains=main >actual && 32 { 33 echo " main" && echo "* side" 34 } >expect && 35 test_cmp expect actual 36 37 ' 38 39 test_expect_success 'branch --contains main' ' 40 41 git branch --contains main >actual && 42 { 43 echo " main" && echo "* side" 44 } >expect && 45 test_cmp expect actual 46 47 ' 48 49 test_expect_success 'branch --no-contains=main' ' 50 51 git branch --no-contains=main >actual && 52 test_must_be_empty actual 53 54 ' 55 56 test_expect_success 'branch --no-contains main' ' 57 58 git branch --no-contains main >actual && 59 test_must_be_empty actual 60 61 ' 62 63 test_expect_success 'branch --contains=side' ' 64 65 git branch --contains=side >actual && 66 { 67 echo "* side" 68 } >expect && 69 test_cmp expect actual 70 71 ' 72 73 test_expect_success 'branch --no-contains=side' ' 74 75 git branch --no-contains=side >actual && 76 { 77 echo " main" 78 } >expect && 79 test_cmp expect actual 80 81 ' 82 83 test_expect_success 'branch --contains with pattern implies --list' ' 84 85 git branch --contains=main main >actual && 86 { 87 echo " main" 88 } >expect && 89 test_cmp expect actual 90 91 ' 92 93 test_expect_success 'branch --no-contains with pattern implies --list' ' 94 95 git branch --no-contains=main main >actual && 96 test_must_be_empty actual 97 98 ' 99 100 test_expect_success 'side: branch --merged' ' 101 102 git branch --merged >actual && 103 { 104 echo " main" && 105 echo "* side" 106 } >expect && 107 test_cmp expect actual 108 109 ' 110 111 test_expect_success 'branch --merged with pattern implies --list' ' 112 113 git branch --merged=side main >actual && 114 { 115 echo " main" 116 } >expect && 117 test_cmp expect actual 118 119 ' 120 121 test_expect_success 'side: branch --no-merged' ' 122 123 git branch --no-merged >actual && 124 test_must_be_empty actual 125 126 ' 127 128 test_expect_success 'main: branch --merged' ' 129 130 git checkout main && 131 git branch --merged >actual && 132 { 133 echo "* main" 134 } >expect && 135 test_cmp expect actual 136 137 ' 138 139 test_expect_success 'main: branch --no-merged' ' 140 141 git branch --no-merged >actual && 142 { 143 echo " side" 144 } >expect && 145 test_cmp expect actual 146 147 ' 148 149 test_expect_success 'branch --no-merged with pattern implies --list' ' 150 151 git branch --no-merged=main main >actual && 152 test_must_be_empty actual 153 154 ' 155 156 test_expect_success 'implicit --list conflicts with modification options' ' 157 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 162 163 ' 164 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 169 EOF 170 ) && 171 test_must_fail git branch --contains $blob && 172 test_must_fail git branch --no-contains $blob 173 ' 174 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 187 EOF 188 test_cmp expect actual 189 ' 190 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 197 EOF 198 test_cmp expect actual 199 ' 200 201 test_expect_success 'multiple branch --no-contains' ' 202 git branch --no-contains side --no-contains side2 >actual && 203 cat >expect <<-\EOF && 204 main 205 EOF 206 test_cmp expect actual 207 ' 208 209 test_expect_success 'multiple branch --no-merged' ' 210 git branch --no-merged next --no-merged main >actual && 211 cat >expect <<-\EOF && 212 side2 213 EOF 214 test_cmp expect actual 215 ' 216 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 225 EOF 226 test_cmp expect actual 227 ' 228 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 234 EOF 235 test_cmp expect actual 236 ' 237 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). 242 # 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 255 zzz 256 EOF 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 263 EOF 264 test_cmp expect actual 265 ' 266 267 test_done