Git fork
at reftables-rust 426 lines 12 kB view raw
1#!/bin/sh 2 3test_description='rev-list/rev-parse --glob' 4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8. ./test-lib.sh 9 10commit () { 11 test_tick && 12 echo $1 > foo && 13 git add foo && 14 git commit -m "$1" 15} 16 17compare () { 18 # Split arguments on whitespace. 19 git $1 $2 >expected && 20 git $1 $3 >actual && 21 test_cmp expected actual 22} 23 24test_expect_success 'setup' ' 25 26 commit main && 27 git checkout -b subspace/one main && 28 commit one && 29 git checkout -b subspace/two main && 30 commit two && 31 git checkout -b subspace-x main && 32 commit subspace-x && 33 git checkout -b other/three main && 34 commit three && 35 git checkout -b someref main && 36 commit some && 37 git checkout main && 38 commit topic_2 && 39 git tag foo/bar main && 40 commit topic_3 && 41 git update-ref refs/remotes/foo/baz main && 42 commit topic_4 && 43 git update-ref refs/remotes/upstream/one subspace/one && 44 git update-ref refs/remotes/upstream/two subspace/two && 45 git update-ref refs/remotes/upstream/x subspace-x && 46 git tag qux/one subspace/one && 47 git tag qux/two subspace/two && 48 git tag qux/x subspace-x 49' 50 51test_expect_success 'rev-parse --glob=refs/heads/subspace/*' ' 52 53 compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/*" 54 55' 56 57test_expect_success 'rev-parse --glob=heads/subspace/*' ' 58 59 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/*" 60 61' 62 63test_expect_success 'rev-parse --glob=refs/heads/subspace/' ' 64 65 compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/" 66 67' 68 69test_expect_success 'rev-parse --glob=heads/subspace/' ' 70 71 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/" 72 73' 74 75test_expect_success 'rev-parse --glob=heads/subspace' ' 76 77 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace" 78 79' 80 81test_expect_failure 'rev-parse accepts --glob as detached option' ' 82 83 compare rev-parse "subspace/one subspace/two" "--glob heads/subspace" 84 85' 86 87test_expect_failure 'rev-parse is not confused by option-like glob' ' 88 89 compare rev-parse "main" "--glob --symbolic main" 90 91' 92 93test_expect_success 'rev-parse --branches=subspace/*' ' 94 95 compare rev-parse "subspace/one subspace/two" "--branches=subspace/*" 96 97' 98 99test_expect_success 'rev-parse --branches=subspace/' ' 100 101 compare rev-parse "subspace/one subspace/two" "--branches=subspace/" 102 103' 104 105test_expect_success 'rev-parse --branches=subspace' ' 106 107 compare rev-parse "subspace/one subspace/two" "--branches=subspace" 108 109' 110 111test_expect_success 'rev-parse --glob=heads/subspace/* --glob=heads/other/*' ' 112 113 compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*" 114 115' 116 117test_expect_success 'rev-parse --glob=heads/someref/* main' ' 118 119 compare rev-parse "main" "--glob=heads/someref/* main" 120 121' 122 123test_expect_success 'rev-parse --glob=heads/*' ' 124 125 compare rev-parse "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*" 126 127' 128 129test_expect_success 'rev-parse --tags=foo' ' 130 131 compare rev-parse "foo/bar" "--tags=foo" 132 133' 134 135test_expect_success 'rev-parse --remotes=foo' ' 136 137 compare rev-parse "foo/baz" "--remotes=foo" 138 139' 140 141test_expect_success 'rev-parse --exclude with --branches' ' 142 compare rev-parse "--exclude=*/* --branches" "main someref subspace-x" 143' 144 145test_expect_success 'rev-parse --exclude with --all' ' 146 compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags" 147' 148 149test_expect_success 'rev-parse accumulates multiple --exclude' ' 150 compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches 151' 152 153test_expect_success 'rev-parse --branches clears --exclude' ' 154 compare rev-parse "--exclude=* --branches --branches" "--branches" 155' 156 157test_expect_success 'rev-parse --tags clears --exclude' ' 158 compare rev-parse "--exclude=* --tags --tags" "--tags" 159' 160 161test_expect_success 'rev-parse --all clears --exclude' ' 162 compare rev-parse "--exclude=* --all --all" "--all" 163' 164 165test_expect_success 'rev-parse --exclude=glob with --branches=glob' ' 166 compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" 167' 168 169test_expect_success 'rev-parse --exclude=glob with --tags=glob' ' 170 compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two" 171' 172 173test_expect_success 'rev-parse --exclude=glob with --remotes=glob' ' 174 compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" 175' 176 177test_expect_success 'rev-parse --exclude=ref with --branches=glob' ' 178 compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" 179' 180 181test_expect_success 'rev-parse --exclude=ref with --tags=glob' ' 182 compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two" 183' 184 185test_expect_success 'rev-parse --exclude=ref with --remotes=glob' ' 186 compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" 187' 188 189for section in fetch receive uploadpack 190do 191 test_expect_success "rev-parse --exclude-hidden=$section with --all" ' 192 compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags" "--exclude-hidden=$section --all" 193 ' 194 195 test_expect_success "rev-parse --exclude-hidden=$section with --all" ' 196 compare "-c transfer.hideRefs=refs/heads/subspace/ rev-parse" "--exclude=refs/heads/subspace/* --all" "--exclude-hidden=$section --all" 197 ' 198 199 test_expect_success "rev-parse --exclude-hidden=$section with --glob" ' 200 compare "-c transfer.hideRefs=refs/heads/subspace/ rev-parse" "--exclude=refs/heads/subspace/* --glob=refs/heads/*" "--exclude-hidden=$section --glob=refs/heads/*" 201 ' 202 203 test_expect_success "rev-parse --exclude-hidden=$section can be passed once per pseudo-ref" ' 204 compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags --branches --tags" "--exclude-hidden=$section --all --exclude-hidden=$section --all" 205 ' 206 207 test_expect_success "rev-parse --exclude-hidden=$section can only be passed once per pseudo-ref" ' 208 echo "fatal: --exclude-hidden= passed more than once" >expected && 209 test_must_fail git rev-parse --exclude-hidden=$section --exclude-hidden=$section 2>err && 210 test_cmp expected err 211 ' 212 213 for pseudoopt in branches tags remotes 214 do 215 test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt" ' 216 test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt 2>err && 217 test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err 218 ' 219 220 test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt=pattern" ' 221 test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt=pattern 2>err && 222 test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err 223 ' 224 done 225done 226 227test_expect_success 'rev-list --exclude=glob with --branches=glob' ' 228 compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" 229' 230 231test_expect_success 'rev-list --exclude=glob with --tags=glob' ' 232 compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two" 233' 234 235test_expect_success 'rev-list --exclude=glob with --remotes=glob' ' 236 compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" 237' 238 239test_expect_success 'rev-list --exclude=ref with --branches=glob' ' 240 compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" 241' 242 243test_expect_success 'rev-list --exclude=ref with --tags=glob' ' 244 compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two" 245' 246 247test_expect_success 'rev-list --exclude=ref with --remotes=glob' ' 248 compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" 249' 250 251test_expect_success 'rev-list --glob=refs/heads/subspace/*' ' 252 253 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*" 254 255' 256 257test_expect_success 'rev-list --glob refs/heads/subspace/*' ' 258 259 compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*" 260 261' 262 263test_expect_success 'rev-list not confused by option-like --glob arg' ' 264 265 compare rev-list "main" "--glob -0 main" 266 267' 268 269test_expect_success 'rev-list --glob=heads/subspace/*' ' 270 271 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*" 272 273' 274 275test_expect_success 'rev-list --glob=refs/heads/subspace/' ' 276 277 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/" 278 279' 280 281test_expect_success 'rev-list --glob=heads/subspace/' ' 282 283 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/" 284 285' 286 287test_expect_success 'rev-list --glob=heads/subspace' ' 288 289 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace" 290 291' 292 293test_expect_success 'rev-list --branches=subspace/*' ' 294 295 compare rev-list "subspace/one subspace/two" "--branches=subspace/*" 296 297' 298 299test_expect_success 'rev-list --branches=subspace/' ' 300 301 compare rev-list "subspace/one subspace/two" "--branches=subspace/" 302 303' 304 305test_expect_success 'rev-list --branches=subspace' ' 306 307 compare rev-list "subspace/one subspace/two" "--branches=subspace" 308 309' 310 311test_expect_success 'rev-list --branches' ' 312 313 compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches" 314 315' 316 317test_expect_success 'rev-list --glob=heads/someref/* main' ' 318 319 compare rev-list "main" "--glob=heads/someref/* main" 320 321' 322 323test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' ' 324 325 compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*" 326 327' 328 329test_expect_success 'rev-list --glob=heads/*' ' 330 331 compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*" 332 333' 334 335test_expect_success 'rev-list --tags=foo' ' 336 337 compare rev-list "foo/bar" "--tags=foo" 338 339' 340 341test_expect_success 'rev-list --tags' ' 342 343 compare rev-list "foo/bar qux/x qux/two qux/one" "--tags" 344 345' 346 347test_expect_success 'rev-list --remotes=foo' ' 348 349 compare rev-list "foo/baz" "--remotes=foo" 350 351' 352 353test_expect_success 'rev-list --exclude with --branches' ' 354 compare rev-list "--exclude=*/* --branches" "main someref subspace-x" 355' 356 357test_expect_success 'rev-list --exclude with --all' ' 358 compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags" 359' 360 361test_expect_success 'rev-list accumulates multiple --exclude' ' 362 compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches 363' 364 365test_expect_success 'rev-list should succeed with empty output on empty stdin' ' 366 git rev-list --stdin </dev/null >actual && 367 test_must_be_empty actual 368' 369 370test_expect_success 'rev-list should succeed with empty output with all refs excluded' ' 371 git rev-list --exclude=* --all >actual && 372 test_must_be_empty actual 373' 374 375test_expect_success 'rev-list should succeed with empty output with empty --all' ' 376 ( 377 test_create_repo empty && 378 cd empty && 379 git rev-list --all >actual && 380 test_must_be_empty actual 381 ) 382' 383 384test_expect_success 'rev-list should succeed with empty output with empty glob' ' 385 git rev-list --glob=does-not-match-anything >actual && 386 test_must_be_empty actual 387' 388 389test_expect_success 'rev-list should succeed with empty output when ignoring missing' ' 390 git rev-list --ignore-missing $ZERO_OID >actual && 391 test_must_be_empty actual 392' 393 394test_expect_success 'shortlog accepts --glob/--tags/--remotes' ' 395 396 compare shortlog "subspace/one subspace/two" --branches=subspace && 397 compare shortlog \ 398 "main subspace-x someref other/three subspace/one subspace/two" \ 399 --branches && 400 compare shortlog main "--glob=heads/someref/* main" && 401 compare shortlog "subspace/one subspace/two other/three" \ 402 "--glob=heads/subspace/* --glob=heads/other/*" && 403 compare shortlog \ 404 "main other/three someref subspace-x subspace/one subspace/two" \ 405 "--glob=heads/*" && 406 compare shortlog foo/bar --tags=foo && 407 compare shortlog "foo/bar qux/one qux/two qux/x" --tags && 408 compare shortlog foo/baz --remotes=foo 409 410' 411 412test_expect_failure 'shortlog accepts --glob as detached option' ' 413 414 compare shortlog \ 415 "main other/three someref subspace-x subspace/one subspace/two" \ 416 "--glob heads/*" 417 418' 419 420test_expect_failure 'shortlog --glob is not confused by option-like argument' ' 421 422 compare shortlog main "--glob -e main" 423 424' 425 426test_done