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/t9902-completion.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 / t9902-completion.sh` 3420 lines · 82819 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2012-2020 Felipe Contreras 4 # 5 6 test_description='test bash completion' 7 8 # The Bash completion scripts must not print anything to either stdout or 9 # stderr, which we try to verify. When tracing is enabled without support for 10 # BASH_XTRACEFD this assertion will fail, so we have to mark the test as 11 # untraceable with such ancient Bash versions. 12 test_untraceable=UnfortunatelyYes 13 14 # Override environment and always use main for the default initial branch 15 # name for these tests, so that rev completion candidates are as expected. 16 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 17 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 18 19 . ./lib-bash.sh 20 21 complete () 22 { 23 # do nothing 24 return 0 25 } 26 27 # Be careful when updating these lists: 28 # 29 # (1) The build tree may have build artifact from different branch, or 30 # the user's $PATH may have a random executable that may begin 31 # with "git-check" that are not part of the subcommands this build 32 # will ship, e.g. "check-ignore". The tests for completion for 33 # subcommand names tests how "check" is expanded; we limit the 34 # possible candidates to "checkout" and "check-attr" to make sure 35 # "check-attr", which is known by the filter function as a 36 # subcommand to be thrown out, while excluding other random files 37 # that happen to begin with "check" to avoid letting them get in 38 # the way. 39 # 40 # (2) A test makes sure that common subcommands are included in the 41 # completion for "git ", and a plumbing is excluded. "add", 42 # "rebase" and "ls-files" are listed for this. 43 44 GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files' 45 GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase' 46 47 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" 48 49 # We don't need this function to actually join words or do anything special. 50 # Also, it's cleaner to avoid touching bash's internal completion variables. 51 # So let's override it with a minimal version for testing purposes. 52 _get_comp_words_by_ref () 53 { 54 while [ $# -gt 0 ]; do 55 case "$1" in 56 cur) 57 cur=${_words[_cword]} 58 ;; 59 prev) 60 prev=${_words[_cword-1]} 61 ;; 62 words) 63 words=("${_words[@]}") 64 ;; 65 cword) 66 cword=$_cword 67 ;; 68 esac 69 shift 70 done 71 } 72 73 print_comp () 74 { 75 local IFS=$'\n' 76 printf '%s\n' "${COMPREPLY[*]}" > out 77 } 78 79 run_completion () 80 { 81 local -a COMPREPLY _words 82 local _cword 83 _words=( $1 ) 84 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]='' 85 (( _cword = ${#_words[@]} - 1 )) 86 __git_wrap__git_main && print_comp 87 } 88 89 # Test high-level completion 90 # Arguments are: 91 # 1: typed text so far (cur) 92 # 2: expected completion 93 test_completion () 94 { 95 if test $# -gt 1 96 then 97 printf '%s\n' "$2" >expected 98 else 99 sed -e 's/Z$//' |sort >expected 100 fi && 101 run_completion "$1" >"$TRASH_DIRECTORY"/bash-completion-output 2>&1 && 102 sort out >out_sorted && 103 test_cmp expected out_sorted && 104 test_must_be_empty "$TRASH_DIRECTORY"/bash-completion-output && 105 rm "$TRASH_DIRECTORY"/bash-completion-output 106 } 107 108 # Test __gitcomp. 109 # The first argument is the typed text so far (cur); the rest are 110 # passed to __gitcomp. Expected output comes is read from the 111 # standard input, like test_completion(). 112 test_gitcomp () 113 { 114 local -a COMPREPLY && 115 sed -e 's/Z$//' >expected && 116 local cur="$1" && 117 shift && 118 __gitcomp "$@" && 119 print_comp && 120 test_cmp expected out 121 } 122 123 # Test __gitcomp_nl 124 # Arguments are: 125 # 1: current word (cur) 126 # -: the rest are passed to __gitcomp_nl 127 test_gitcomp_nl () 128 { 129 local -a COMPREPLY && 130 sed -e 's/Z$//' >expected && 131 local cur="$1" && 132 shift && 133 __gitcomp_nl "$@" && 134 print_comp && 135 test_cmp expected out 136 } 137 138 invalid_variable_name='${foo.bar}' 139 140 actual="$TRASH_DIRECTORY/actual" 141 142 if test_have_prereq MINGW 143 then 144 ROOT="$(pwd -W)" 145 else 146 ROOT="$(pwd)" 147 fi 148 149 test_expect_success 'setup for __git_find_repo_path/__gitdir tests' ' 150 mkdir -p subdir/subsubdir && 151 mkdir -p non-repo && 152 git init -b main otherrepo && 153 git init -b main slashrepo 154 ' 155 156 test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' ' 157 echo "$ROOT/otherrepo/.git" >expected && 158 ( 159 __git_dir="$ROOT/otherrepo/.git" && 160 __git_find_repo_path && 161 echo "$__git_repo_path" >"$actual" 162 ) && 163 test_cmp expected "$actual" 164 ' 165 166 test_expect_success '__git_find_repo_path - .git directory in cwd' ' 167 echo ".git" >expected && 168 ( 169 __git_find_repo_path && 170 echo "$__git_repo_path" >"$actual" 171 ) && 172 test_cmp expected "$actual" 173 ' 174 175 test_expect_success '__git_find_repo_path - .git directory in parent' ' 176 echo "$ROOT/.git" >expected && 177 ( 178 cd subdir/subsubdir && 179 __git_find_repo_path && 180 echo "$__git_repo_path" >"$actual" 181 ) && 182 test_cmp expected "$actual" 183 ' 184 185 test_expect_success '__git_find_repo_path - cwd is a .git directory' ' 186 echo "." >expected && 187 ( 188 cd .git && 189 __git_find_repo_path && 190 echo "$__git_repo_path" >"$actual" 191 ) && 192 test_cmp expected "$actual" 193 ' 194 195 test_expect_success '__git_find_repo_path - parent is a .git directory' ' 196 echo "$ROOT/.git" >expected && 197 ( 198 cd .git/objects && 199 __git_find_repo_path && 200 echo "$__git_repo_path" >"$actual" 201 ) && 202 test_cmp expected "$actual" 203 ' 204 205 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' ' 206 echo "$ROOT/otherrepo/.git" >expected && 207 ( 208 GIT_DIR="$ROOT/otherrepo/.git" && 209 export GIT_DIR && 210 __git_find_repo_path && 211 echo "$__git_repo_path" >"$actual" 212 ) && 213 test_cmp expected "$actual" 214 ' 215 216 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' ' 217 echo "$ROOT/otherrepo/.git" >expected && 218 ( 219 GIT_DIR="$ROOT/otherrepo/.git" && 220 export GIT_DIR && 221 cd subdir && 222 __git_find_repo_path && 223 echo "$__git_repo_path" >"$actual" 224 ) && 225 test_cmp expected "$actual" 226 ' 227 228 test_expect_success '__git_find_repo_path - from command line while "git -C"' ' 229 echo "$ROOT/.git" >expected && 230 ( 231 __git_dir="$ROOT/.git" && 232 __git_C_args=(-C otherrepo) && 233 __git_find_repo_path && 234 echo "$__git_repo_path" >"$actual" 235 ) && 236 test_cmp expected "$actual" 237 ' 238 239 test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' ' 240 echo "$ROOT/otherrepo/.git" >expected && 241 ( 242 cd subdir && 243 __git_dir="otherrepo/.git" && 244 __git_C_args=(-C ..) && 245 __git_find_repo_path && 246 echo "$__git_repo_path" >"$actual" 247 ) && 248 test_cmp expected "$actual" 249 ' 250 251 test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' ' 252 echo "$ROOT/.git" >expected && 253 ( 254 GIT_DIR="$ROOT/.git" && 255 export GIT_DIR && 256 __git_C_args=(-C otherrepo) && 257 __git_find_repo_path && 258 echo "$__git_repo_path" >"$actual" 259 ) && 260 test_cmp expected "$actual" 261 ' 262 263 test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' ' 264 echo "$ROOT/otherrepo/.git" >expected && 265 ( 266 cd subdir && 267 GIT_DIR="otherrepo/.git" && 268 export GIT_DIR && 269 __git_C_args=(-C ..) && 270 __git_find_repo_path && 271 echo "$__git_repo_path" >"$actual" 272 ) && 273 test_cmp expected "$actual" 274 ' 275 276 test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' ' 277 echo "$ROOT/otherrepo/.git" >expected && 278 ( 279 __git_C_args=(-C otherrepo) && 280 __git_find_repo_path && 281 echo "$__git_repo_path" >"$actual" 282 ) && 283 test_cmp expected "$actual" 284 ' 285 286 test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' ' 287 echo "$ROOT/otherrepo/.git" >expected && 288 ( 289 cd .git && 290 __git_C_args=(-C .. -C otherrepo) && 291 __git_find_repo_path && 292 echo "$__git_repo_path" >"$actual" 293 ) && 294 test_cmp expected "$actual" 295 ' 296 297 test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' ' 298 echo "$ROOT/otherrepo/.git" >expected && 299 ( 300 cd subdir && 301 __git_C_args=(-C .. -C otherrepo) && 302 __git_find_repo_path && 303 echo "$__git_repo_path" >"$actual" 304 ) && 305 test_cmp expected "$actual" 306 ' 307 308 test_expect_success '__git_find_repo_path - non-existing path in "git -C"' ' 309 ( 310 __git_C_args=(-C non-existing) && 311 test_must_fail __git_find_repo_path && 312 printf "$__git_repo_path" >"$actual" 313 ) && 314 test_must_be_empty "$actual" 315 ' 316 317 test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' ' 318 ( 319 __git_dir="non-existing" && 320 test_must_fail __git_find_repo_path && 321 printf "$__git_repo_path" >"$actual" 322 ) && 323 test_must_be_empty "$actual" 324 ' 325 326 test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' ' 327 ( 328 GIT_DIR="$ROOT/non-existing" && 329 export GIT_DIR && 330 test_must_fail __git_find_repo_path && 331 printf "$__git_repo_path" >"$actual" 332 ) && 333 test_must_be_empty "$actual" 334 ' 335 336 test_expect_success '__git_find_repo_path - gitfile in cwd' ' 337 echo "$ROOT/otherrepo/.git" >expected && 338 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && 339 test_when_finished "rm -f subdir/.git" && 340 ( 341 cd subdir && 342 __git_find_repo_path && 343 echo "$__git_repo_path" >"$actual" 344 ) && 345 test_cmp expected "$actual" 346 ' 347 348 test_expect_success '__git_find_repo_path - gitfile in parent' ' 349 echo "$ROOT/otherrepo/.git" >expected && 350 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && 351 test_when_finished "rm -f subdir/.git" && 352 ( 353 cd subdir/subsubdir && 354 __git_find_repo_path && 355 echo "$__git_repo_path" >"$actual" 356 ) && 357 test_cmp expected "$actual" 358 ' 359 360 test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' ' 361 echo "$ROOT/otherrepo/.git" >expected && 362 mkdir otherrepo/dir && 363 test_when_finished "rm -rf otherrepo/dir" && 364 ln -s otherrepo/dir link && 365 test_when_finished "rm -f link" && 366 ( 367 cd link && 368 __git_find_repo_path && 369 echo "$__git_repo_path" >"$actual" 370 ) && 371 test_cmp expected "$actual" 372 ' 373 374 test_expect_success '__git_find_repo_path - not a git repository' ' 375 ( 376 cd non-repo && 377 GIT_CEILING_DIRECTORIES="$ROOT" && 378 export GIT_CEILING_DIRECTORIES && 379 test_must_fail __git_find_repo_path && 380 printf "$__git_repo_path" >"$actual" 381 ) && 382 test_must_be_empty "$actual" 383 ' 384 385 test_expect_success '__gitdir - finds repo' ' 386 echo "$ROOT/.git" >expected && 387 ( 388 cd subdir/subsubdir && 389 __gitdir >"$actual" 390 ) && 391 test_cmp expected "$actual" 392 ' 393 394 395 test_expect_success '__gitdir - returns error when cannot find repo' ' 396 ( 397 __git_dir="non-existing" && 398 test_must_fail __gitdir >"$actual" 399 ) && 400 test_must_be_empty "$actual" 401 ' 402 403 test_expect_success '__gitdir - repo as argument' ' 404 echo "otherrepo/.git" >expected && 405 ( 406 __gitdir "otherrepo" >"$actual" 407 ) && 408 test_cmp expected "$actual" 409 ' 410 411 test_expect_success '__gitdir - remote as argument' ' 412 echo "remote" >expected && 413 ( 414 __gitdir "remote" >"$actual" 415 ) && 416 test_cmp expected "$actual" 417 ' 418 419 420 test_expect_success '__git_dequote - plain unquoted word' ' 421 __git_dequote unquoted-word && 422 test unquoted-word = "$dequoted_word" 423 ' 424 425 # input: b\a\c\k\'\\\"s\l\a\s\h\es 426 # expected: back'\"slashes 427 test_expect_success '__git_dequote - backslash escaped' ' 428 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" && 429 test "back'\''\\\"slashes" = "$dequoted_word" 430 ' 431 432 # input: sin'gle\' '"quo'ted 433 # expected: single\ "quoted 434 test_expect_success '__git_dequote - single quoted' ' 435 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" && 436 test '\''single\ "quoted'\'' = "$dequoted_word" 437 ' 438 439 # input: dou"ble\\" "\"\quot"ed 440 # expected: double\ "\quoted 441 test_expect_success '__git_dequote - double quoted' ' 442 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' && 443 test '\''double\ "\quoted'\'' = "$dequoted_word" 444 ' 445 446 # input: 'open single quote 447 test_expect_success '__git_dequote - open single quote' ' 448 __git_dequote "'\''open single quote" && 449 test "open single quote" = "$dequoted_word" 450 ' 451 452 # input: "open double quote 453 test_expect_success '__git_dequote - open double quote' ' 454 __git_dequote "\"open double quote" && 455 test "open double quote" = "$dequoted_word" 456 ' 457 458 459 test_expect_success '__git_count_path_components - no slashes' ' 460 echo 1 >expected && 461 __git_count_path_components a >"$actual" && 462 test_cmp expected "$actual" 463 ' 464 465 test_expect_success '__git_count_path_components - relative' ' 466 echo 3 >expected && 467 __git_count_path_components a/b/c >"$actual" && 468 test_cmp expected "$actual" 469 470 ' 471 472 test_expect_success '__git_count_path_components - absolute' ' 473 echo 3 >expected && 474 __git_count_path_components /a/b/c >"$actual" && 475 test_cmp expected "$actual" 476 ' 477 478 test_expect_success '__git_count_path_components - trailing slash' ' 479 echo 3 >expected && 480 __git_count_path_components a/b/c/ >"$actual" && 481 test_cmp expected "$actual" 482 ' 483 484 485 test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' ' 486 sed -e "s/Z$//g" >expected <<-EOF && 487 with-trailing-space Z 488 without-trailing-spaceZ 489 --option Z 490 --option=Z 491 $invalid_variable_name Z 492 EOF 493 ( 494 cur=should_be_ignored && 495 __gitcomp_direct "$(cat expected)" && 496 print_comp 497 ) && 498 test_cmp expected out 499 ' 500 501 test_expect_success '__gitcomp - trailing space - options' ' 502 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message= 503 --reset-author" <<-EOF 504 --reuse-message=Z 505 --reedit-message=Z 506 --reset-author Z 507 EOF 508 ' 509 510 test_expect_success '__gitcomp - trailing space - config keys' ' 511 test_gitcomp "br" "branch. branch.autosetupmerge 512 branch.autosetuprebase browser." <<-\EOF 513 branch.Z 514 branch.autosetupmerge Z 515 branch.autosetuprebase Z 516 browser.Z 517 EOF 518 ' 519 520 test_expect_success '__gitcomp - option parameter' ' 521 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \ 522 "" "re" <<-\EOF 523 recursive Z 524 resolve Z 525 EOF 526 ' 527 528 test_expect_success '__gitcomp - prefix' ' 529 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \ 530 "branch.maint." "me" <<-\EOF 531 branch.maint.merge Z 532 branch.maint.mergeoptions Z 533 EOF 534 ' 535 536 test_expect_success '__gitcomp - suffix' ' 537 test_gitcomp "branch.me" "master maint next seen" "branch." \ 538 "ma" "." <<-\EOF 539 branch.master.Z 540 branch.maint.Z 541 EOF 542 ' 543 544 test_expect_success '__gitcomp - ignore optional negative options' ' 545 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF 546 --abc Z 547 --def Z 548 --no-one Z 549 --no-... Z 550 EOF 551 ' 552 553 test_expect_success '__gitcomp - ignore/narrow optional negative options' ' 554 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF 555 --abc Z 556 --abcdef Z 557 EOF 558 ' 559 560 test_expect_success '__gitcomp - ignore/narrow optional negative options' ' 561 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF 562 --no-one Z 563 --no-... Z 564 EOF 565 ' 566 567 test_expect_success '__gitcomp - expand all negative options' ' 568 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF 569 --no-one Z 570 --no-two Z 571 EOF 572 ' 573 574 test_expect_success '__gitcomp - expand/narrow all negative options' ' 575 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF 576 --no-one Z 577 EOF 578 ' 579 580 test_expect_success '__gitcomp - equal skip' ' 581 test_gitcomp "--option=" "--option=" <<-\EOF && 582 583 EOF 584 test_gitcomp "option=" "option=" <<-\EOF 585 586 EOF 587 ' 588 589 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' 590 __gitcomp "$invalid_variable_name" 591 ' 592 593 refs='main 594 maint 595 next 596 seen' 597 598 test_expect_success '__gitcomp_nl - trailing space' ' 599 test_gitcomp_nl "m" "$refs" <<-EOF 600 main Z 601 maint Z 602 EOF 603 ' 604 605 test_expect_success '__gitcomp_nl - prefix' ' 606 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF 607 --fixup=main Z 608 --fixup=maint Z 609 EOF 610 ' 611 612 test_expect_success '__gitcomp_nl - suffix' ' 613 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF 614 branch.main.Z 615 branch.maint.Z 616 EOF 617 ' 618 619 test_expect_success '__gitcomp_nl - no suffix' ' 620 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF 621 mainZ 622 maintZ 623 EOF 624 ' 625 626 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' ' 627 __gitcomp_nl "$invalid_variable_name" 628 ' 629 630 test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' ' 631 cat >expect <<-EOF && 632 remote_from_file_1 633 remote_from_file_2 634 remote_in_config_1 635 remote_in_config_2 636 EOF 637 test_when_finished "rm -rf .git/remotes" && 638 mkdir -p .git/remotes && 639 >.git/remotes/remote_from_file_1 && 640 >.git/remotes/remote_from_file_2 && 641 test_when_finished "git remote remove remote_in_config_1" && 642 git remote add remote_in_config_1 git://remote_1 && 643 test_when_finished "git remote remove remote_in_config_2" && 644 git remote add remote_in_config_2 git://remote_2 && 645 ( 646 __git_remotes >actual 647 ) && 648 test_cmp expect actual 649 ' 650 651 test_expect_success '__git_is_configured_remote' ' 652 test_when_finished "git remote remove remote_1" && 653 git remote add remote_1 git://remote_1 && 654 test_when_finished "git remote remove remote_2" && 655 git remote add remote_2 git://remote_2 && 656 ( 657 __git_is_configured_remote remote_2 && 658 test_must_fail __git_is_configured_remote non-existent 659 ) 660 ' 661 662 test_expect_success 'setup for ref completion' ' 663 git commit --allow-empty -m initial && 664 git branch -M main && 665 git branch matching-branch && 666 git tag matching-tag && 667 ( 668 cd otherrepo && 669 git commit --allow-empty -m initial && 670 git branch -m main main-in-other && 671 git branch branch-in-other && 672 git tag tag-in-other 673 ) && 674 git remote add other "$ROOT/otherrepo/.git" && 675 git fetch --no-tags other && 676 ( 677 cd slashrepo && 678 git commit --allow-empty -m initial && 679 git branch -m main branch/with/slash 680 ) && 681 git remote add remote/with/slash "$ROOT/slashrepo/.git" && 682 git fetch --no-tags remote/with/slash && 683 rm -f .git/FETCH_HEAD && 684 git init thirdrepo 685 ' 686 687 test_expect_success '__git_refs - simple' ' 688 cat >expected <<-EOF && 689 HEAD 690 main 691 matching-branch 692 other/HEAD 693 other/branch-in-other 694 other/main-in-other 695 remote/with/slash/HEAD 696 remote/with/slash/branch/with/slash 697 matching-tag 698 EOF 699 ( 700 cur= && 701 __git_refs >"$actual" 702 ) && 703 test_cmp expected "$actual" 704 ' 705 706 test_expect_success '__git_refs - full refs' ' 707 cat >expected <<-EOF && 708 refs/heads/main 709 refs/heads/matching-branch 710 refs/remotes/other/HEAD 711 refs/remotes/other/branch-in-other 712 refs/remotes/other/main-in-other 713 refs/remotes/remote/with/slash/HEAD 714 refs/remotes/remote/with/slash/branch/with/slash 715 refs/tags/matching-tag 716 EOF 717 ( 718 cur=refs/heads/ && 719 __git_refs >"$actual" 720 ) && 721 test_cmp expected "$actual" 722 ' 723 724 test_expect_success '__git_refs - repo given on the command line' ' 725 cat >expected <<-EOF && 726 HEAD 727 branch-in-other 728 main-in-other 729 tag-in-other 730 EOF 731 ( 732 __git_dir="$ROOT/otherrepo/.git" && 733 cur= && 734 __git_refs >"$actual" 735 ) && 736 test_cmp expected "$actual" 737 ' 738 739 test_expect_success '__git_refs - remote on local file system' ' 740 cat >expected <<-EOF && 741 HEAD 742 branch-in-other 743 main-in-other 744 tag-in-other 745 EOF 746 ( 747 cur= && 748 __git_refs otherrepo >"$actual" 749 ) && 750 test_cmp expected "$actual" 751 ' 752 753 test_expect_success '__git_refs - remote on local file system - full refs' ' 754 cat >expected <<-EOF && 755 refs/heads/branch-in-other 756 refs/heads/main-in-other 757 refs/tags/tag-in-other 758 EOF 759 ( 760 cur=refs/ && 761 __git_refs otherrepo >"$actual" 762 ) && 763 test_cmp expected "$actual" 764 ' 765 766 test_expect_success '__git_refs - configured remote' ' 767 cat >expected <<-EOF && 768 HEAD 769 HEAD 770 branch-in-other 771 main-in-other 772 EOF 773 ( 774 cur= && 775 __git_refs other >"$actual" 776 ) && 777 test_cmp expected "$actual" 778 ' 779 780 test_expect_success '__git_refs - configured remote - with slash' ' 781 cat >expected <<-EOF && 782 HEAD 783 HEAD 784 branch/with/slash 785 EOF 786 ( 787 cur= && 788 __git_refs remote/with/slash >"$actual" 789 ) && 790 test_cmp expected "$actual" 791 ' 792 793 test_expect_success '__git_refs - configured remote - full refs' ' 794 cat >expected <<-EOF && 795 HEAD 796 refs/heads/branch-in-other 797 refs/heads/main-in-other 798 refs/tags/tag-in-other 799 EOF 800 ( 801 cur=refs/ && 802 __git_refs other >"$actual" 803 ) && 804 test_cmp expected "$actual" 805 ' 806 807 test_expect_success '__git_refs - configured remote - repo given on the command line' ' 808 cat >expected <<-EOF && 809 HEAD 810 HEAD 811 branch-in-other 812 main-in-other 813 EOF 814 ( 815 cd thirdrepo && 816 __git_dir="$ROOT/.git" && 817 cur= && 818 __git_refs other >"$actual" 819 ) && 820 test_cmp expected "$actual" 821 ' 822 823 test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' ' 824 cat >expected <<-EOF && 825 HEAD 826 refs/heads/branch-in-other 827 refs/heads/main-in-other 828 refs/tags/tag-in-other 829 EOF 830 ( 831 cd thirdrepo && 832 __git_dir="$ROOT/.git" && 833 cur=refs/ && 834 __git_refs other >"$actual" 835 ) && 836 test_cmp expected "$actual" 837 ' 838 839 test_expect_success '__git_refs - configured remote - remote name matches a directory' ' 840 cat >expected <<-EOF && 841 HEAD 842 HEAD 843 branch-in-other 844 main-in-other 845 EOF 846 mkdir other && 847 test_when_finished "rm -rf other" && 848 ( 849 cur= && 850 __git_refs other >"$actual" 851 ) && 852 test_cmp expected "$actual" 853 ' 854 855 test_expect_success '__git_refs - URL remote' ' 856 cat >expected <<-EOF && 857 HEAD 858 branch-in-other 859 main-in-other 860 tag-in-other 861 EOF 862 ( 863 cur= && 864 __git_refs "file://$ROOT/otherrepo/.git" >"$actual" 865 ) && 866 test_cmp expected "$actual" 867 ' 868 869 test_expect_success '__git_refs - URL remote - full refs' ' 870 cat >expected <<-EOF && 871 HEAD 872 refs/heads/branch-in-other 873 refs/heads/main-in-other 874 refs/tags/tag-in-other 875 EOF 876 ( 877 cur=refs/ && 878 __git_refs "file://$ROOT/otherrepo/.git" >"$actual" 879 ) && 880 test_cmp expected "$actual" 881 ' 882 883 test_expect_success '__git_refs - non-existing remote' ' 884 ( 885 cur= && 886 __git_refs non-existing >"$actual" 887 ) && 888 test_must_be_empty "$actual" 889 ' 890 891 test_expect_success '__git_refs - non-existing remote - full refs' ' 892 ( 893 cur=refs/ && 894 __git_refs non-existing >"$actual" 895 ) && 896 test_must_be_empty "$actual" 897 ' 898 899 test_expect_success '__git_refs - non-existing URL remote' ' 900 ( 901 cur= && 902 __git_refs "file://$ROOT/non-existing" >"$actual" 903 ) && 904 test_must_be_empty "$actual" 905 ' 906 907 test_expect_success '__git_refs - non-existing URL remote - full refs' ' 908 ( 909 cur=refs/ && 910 __git_refs "file://$ROOT/non-existing" >"$actual" 911 ) && 912 test_must_be_empty "$actual" 913 ' 914 915 test_expect_success '__git_refs - not in a git repository' ' 916 ( 917 GIT_CEILING_DIRECTORIES="$ROOT" && 918 export GIT_CEILING_DIRECTORIES && 919 cd subdir && 920 cur= && 921 __git_refs >"$actual" 922 ) && 923 test_must_be_empty "$actual" 924 ' 925 926 test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' ' 927 cat >expected <<-EOF && 928 HEAD 929 main 930 matching-branch 931 other/HEAD 932 other/ambiguous 933 other/branch-in-other 934 other/main-in-other 935 remote/with/slash/HEAD 936 remote/with/slash/ambiguous 937 remote/with/slash/branch-in-remote 938 remote/with/slash/branch/with/slash 939 matching-tag 940 branch-in-other 941 branch-in-remote 942 branch/with/slash 943 main-in-other 944 EOF 945 for remote_ref in refs/remotes/other/ambiguous \ 946 refs/remotes/remote/with/slash/ambiguous \ 947 refs/remotes/remote/with/slash/branch-in-remote 948 do 949 git update-ref $remote_ref main && 950 test_when_finished "git update-ref -d $remote_ref" || return 1 951 done && 952 ( 953 cur= && 954 __git_refs "" 1 >"$actual" 955 ) && 956 test_cmp expected "$actual" 957 ' 958 959 test_expect_success '__git_refs - after --opt=' ' 960 cat >expected <<-EOF && 961 HEAD 962 main 963 matching-branch 964 other/HEAD 965 other/branch-in-other 966 other/main-in-other 967 remote/with/slash/HEAD 968 remote/with/slash/branch/with/slash 969 matching-tag 970 EOF 971 ( 972 cur="--opt=" && 973 __git_refs "" "" "" "" >"$actual" 974 ) && 975 test_cmp expected "$actual" 976 ' 977 978 test_expect_success '__git_refs - after --opt= - full refs' ' 979 cat >expected <<-EOF && 980 refs/heads/main 981 refs/heads/matching-branch 982 refs/remotes/other/HEAD 983 refs/remotes/other/branch-in-other 984 refs/remotes/other/main-in-other 985 refs/remotes/remote/with/slash/HEAD 986 refs/remotes/remote/with/slash/branch/with/slash 987 refs/tags/matching-tag 988 EOF 989 ( 990 cur="--opt=refs/" && 991 __git_refs "" "" "" refs/ >"$actual" 992 ) && 993 test_cmp expected "$actual" 994 ' 995 996 test_expect_success '__git refs - excluding refs' ' 997 cat >expected <<-EOF && 998 ^HEAD 999 ^main 1000 ^matching-branch 1001 ^other/HEAD 1002 ^other/branch-in-other 1003 ^other/main-in-other 1004 ^remote/with/slash/HEAD 1005 ^remote/with/slash/branch/with/slash 1006 ^matching-tag 1007 EOF 1008 ( 1009 cur=^ && 1010 __git_refs >"$actual" 1011 ) && 1012 test_cmp expected "$actual" 1013 ' 1014 1015 test_expect_success '__git refs - excluding full refs' ' 1016 cat >expected <<-EOF && 1017 ^refs/heads/main 1018 ^refs/heads/matching-branch 1019 ^refs/remotes/other/HEAD 1020 ^refs/remotes/other/branch-in-other 1021 ^refs/remotes/other/main-in-other 1022 ^refs/remotes/remote/with/slash/HEAD 1023 ^refs/remotes/remote/with/slash/branch/with/slash 1024 ^refs/tags/matching-tag 1025 EOF 1026 ( 1027 cur=^refs/ && 1028 __git_refs >"$actual" 1029 ) && 1030 test_cmp expected "$actual" 1031 ' 1032 1033 test_expect_success 'setup for filtering matching refs' ' 1034 git branch matching/branch && 1035 git tag matching/tag && 1036 git -C otherrepo branch matching/branch-in-other && 1037 git fetch --no-tags other && 1038 rm -f .git/FETCH_HEAD 1039 ' 1040 1041 test_expect_success '__git_refs - do not filter refs unless told so' ' 1042 cat >expected <<-EOF && 1043 HEAD 1044 main 1045 matching-branch 1046 matching/branch 1047 other/HEAD 1048 other/branch-in-other 1049 other/main-in-other 1050 other/matching/branch-in-other 1051 remote/with/slash/HEAD 1052 remote/with/slash/branch/with/slash 1053 matching-tag 1054 matching/tag 1055 EOF 1056 ( 1057 cur=main && 1058 __git_refs >"$actual" 1059 ) && 1060 test_cmp expected "$actual" 1061 ' 1062 1063 test_expect_success '__git_refs - only matching refs' ' 1064 cat >expected <<-EOF && 1065 matching-branch 1066 matching/branch 1067 matching-tag 1068 matching/tag 1069 EOF 1070 ( 1071 cur=mat && 1072 __git_refs "" "" "" "$cur" >"$actual" 1073 ) && 1074 test_cmp expected "$actual" 1075 ' 1076 1077 test_expect_success '__git_refs - only matching refs - full refs' ' 1078 cat >expected <<-EOF && 1079 refs/heads/matching-branch 1080 refs/heads/matching/branch 1081 EOF 1082 ( 1083 cur=refs/heads/mat && 1084 __git_refs "" "" "" "$cur" >"$actual" 1085 ) && 1086 test_cmp expected "$actual" 1087 ' 1088 1089 test_expect_success '__git_refs - only matching refs - remote on local file system' ' 1090 cat >expected <<-EOF && 1091 main-in-other 1092 matching/branch-in-other 1093 EOF 1094 ( 1095 cur=ma && 1096 __git_refs otherrepo "" "" "$cur" >"$actual" 1097 ) && 1098 test_cmp expected "$actual" 1099 ' 1100 1101 test_expect_success '__git_refs - only matching refs - configured remote' ' 1102 cat >expected <<-EOF && 1103 main-in-other 1104 matching/branch-in-other 1105 EOF 1106 ( 1107 cur=ma && 1108 __git_refs other "" "" "$cur" >"$actual" 1109 ) && 1110 test_cmp expected "$actual" 1111 ' 1112 1113 test_expect_success '__git_refs - only matching refs - remote - full refs' ' 1114 cat >expected <<-EOF && 1115 refs/heads/main-in-other 1116 refs/heads/matching/branch-in-other 1117 EOF 1118 ( 1119 cur=refs/heads/ma && 1120 __git_refs other "" "" "$cur" >"$actual" 1121 ) && 1122 test_cmp expected "$actual" 1123 ' 1124 1125 test_expect_success '__git_refs - only matching refs - checkout DWIMery' ' 1126 cat >expected <<-EOF && 1127 matching-branch 1128 matching/branch 1129 matching-tag 1130 matching/tag 1131 matching/branch-in-other 1132 EOF 1133 for remote_ref in refs/remotes/other/ambiguous \ 1134 refs/remotes/remote/ambiguous \ 1135 refs/remotes/remote/branch-in-remote 1136 do 1137 git update-ref $remote_ref main && 1138 test_when_finished "git update-ref -d $remote_ref" || return 1 1139 done && 1140 ( 1141 cur=mat && 1142 __git_refs "" 1 "" "$cur" >"$actual" 1143 ) && 1144 test_cmp expected "$actual" 1145 ' 1146 1147 test_expect_success 'teardown after filtering matching refs' ' 1148 git branch -d matching/branch && 1149 git tag -d matching/tag && 1150 git update-ref -d refs/remotes/other/matching/branch-in-other && 1151 git -C otherrepo branch -D matching/branch-in-other 1152 ' 1153 1154 test_expect_success '__git_refs - for-each-ref format specifiers in prefix' ' 1155 cat >expected <<-EOF && 1156 evil-%%-%42-%(refname)..main 1157 EOF 1158 ( 1159 cur="evil-%%-%42-%(refname)..mai" && 1160 __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual" 1161 ) && 1162 test_cmp expected "$actual" 1163 ' 1164 1165 test_expect_success '__git_complete_refs - simple' ' 1166 sed -e "s/Z$//" >expected <<-EOF && 1167 HEAD Z 1168 main Z 1169 matching-branch Z 1170 other/HEAD Z 1171 other/branch-in-other Z 1172 other/main-in-other Z 1173 remote/with/slash/HEAD Z 1174 remote/with/slash/branch/with/slash Z 1175 matching-tag Z 1176 EOF 1177 ( 1178 cur= && 1179 __git_complete_refs && 1180 print_comp 1181 ) && 1182 test_cmp expected out 1183 ' 1184 1185 test_expect_success '__git_complete_refs - matching' ' 1186 sed -e "s/Z$//" >expected <<-EOF && 1187 matching-branch Z 1188 matching-tag Z 1189 EOF 1190 ( 1191 cur=mat && 1192 __git_complete_refs && 1193 print_comp 1194 ) && 1195 test_cmp expected out 1196 ' 1197 1198 test_expect_success '__git_complete_refs - remote' ' 1199 sed -e "s/Z$//" >expected <<-EOF && 1200 HEAD Z 1201 HEAD Z 1202 branch-in-other Z 1203 main-in-other Z 1204 EOF 1205 ( 1206 cur= && 1207 __git_complete_refs --remote=other && 1208 print_comp 1209 ) && 1210 test_cmp expected out 1211 ' 1212 1213 test_expect_success '__git_complete_refs - remote - with slash' ' 1214 sed -e "s/Z$//" >expected <<-EOF && 1215 HEAD Z 1216 HEAD Z 1217 branch/with/slash Z 1218 EOF 1219 ( 1220 cur= && 1221 __git_complete_refs --remote=remote/with/slash && 1222 print_comp 1223 ) && 1224 test_cmp expected out 1225 ' 1226 1227 test_expect_success '__git_complete_refs - track' ' 1228 sed -e "s/Z$//" >expected <<-EOF && 1229 HEAD Z 1230 main Z 1231 matching-branch Z 1232 other/HEAD Z 1233 other/branch-in-other Z 1234 other/main-in-other Z 1235 remote/with/slash/HEAD Z 1236 remote/with/slash/branch/with/slash Z 1237 matching-tag Z 1238 branch-in-other Z 1239 branch/with/slash Z 1240 main-in-other Z 1241 EOF 1242 ( 1243 cur= && 1244 __git_complete_refs --track && 1245 print_comp 1246 ) && 1247 test_cmp expected out 1248 ' 1249 1250 test_expect_success '__git_complete_refs - current word' ' 1251 sed -e "s/Z$//" >expected <<-EOF && 1252 matching-branch Z 1253 matching-tag Z 1254 EOF 1255 ( 1256 cur="--option=mat" && 1257 __git_complete_refs --cur="${cur#*=}" && 1258 print_comp 1259 ) && 1260 test_cmp expected out 1261 ' 1262 1263 test_expect_success '__git_complete_refs - prefix' ' 1264 sed -e "s/Z$//" >expected <<-EOF && 1265 v1.0..matching-branch Z 1266 v1.0..matching-tag Z 1267 EOF 1268 ( 1269 cur=v1.0..mat && 1270 __git_complete_refs --pfx=v1.0.. --cur=mat && 1271 print_comp 1272 ) && 1273 test_cmp expected out 1274 ' 1275 1276 test_expect_success '__git_complete_refs - suffix' ' 1277 cat >expected <<-EOF && 1278 HEAD. 1279 main. 1280 matching-branch. 1281 other/HEAD. 1282 other/branch-in-other. 1283 other/main-in-other. 1284 remote/with/slash/HEAD. 1285 remote/with/slash/branch/with/slash. 1286 matching-tag. 1287 EOF 1288 ( 1289 cur= && 1290 __git_complete_refs --sfx=. && 1291 print_comp 1292 ) && 1293 test_cmp expected out 1294 ' 1295 1296 test_expect_success '__git_complete_fetch_refspecs - simple' ' 1297 sed -e "s/Z$//" >expected <<-EOF && 1298 HEAD:HEAD Z 1299 HEAD:HEAD Z 1300 branch-in-other:branch-in-other Z 1301 main-in-other:main-in-other Z 1302 EOF 1303 ( 1304 cur= && 1305 __git_complete_fetch_refspecs other && 1306 print_comp 1307 ) && 1308 test_cmp expected out 1309 ' 1310 1311 test_expect_success '__git_complete_fetch_refspecs - with slash' ' 1312 sed -e "s/Z$//" >expected <<-EOF && 1313 HEAD:HEAD Z 1314 HEAD:HEAD Z 1315 branch/with/slash:branch/with/slash Z 1316 EOF 1317 ( 1318 cur= && 1319 __git_complete_fetch_refspecs remote/with/slash && 1320 print_comp 1321 ) && 1322 test_cmp expected out 1323 ' 1324 1325 test_expect_success '__git_complete_fetch_refspecs - matching' ' 1326 sed -e "s/Z$//" >expected <<-EOF && 1327 branch-in-other:branch-in-other Z 1328 EOF 1329 ( 1330 cur=br && 1331 __git_complete_fetch_refspecs other "" br && 1332 print_comp 1333 ) && 1334 test_cmp expected out 1335 ' 1336 1337 test_expect_success '__git_complete_fetch_refspecs - prefix' ' 1338 sed -e "s/Z$//" >expected <<-EOF && 1339 +HEAD:HEAD Z 1340 +HEAD:HEAD Z 1341 +branch-in-other:branch-in-other Z 1342 +main-in-other:main-in-other Z 1343 EOF 1344 ( 1345 cur="+" && 1346 __git_complete_fetch_refspecs other "+" "" && 1347 print_comp 1348 ) && 1349 test_cmp expected out 1350 ' 1351 1352 test_expect_success '__git_complete_fetch_refspecs - fully qualified' ' 1353 sed -e "s/Z$//" >expected <<-EOF && 1354 refs/heads/branch-in-other:refs/heads/branch-in-other Z 1355 refs/heads/main-in-other:refs/heads/main-in-other Z 1356 refs/tags/tag-in-other:refs/tags/tag-in-other Z 1357 EOF 1358 ( 1359 cur=refs/ && 1360 __git_complete_fetch_refspecs other "" refs/ && 1361 print_comp 1362 ) && 1363 test_cmp expected out 1364 ' 1365 1366 test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' 1367 sed -e "s/Z$//" >expected <<-EOF && 1368 +refs/heads/branch-in-other:refs/heads/branch-in-other Z 1369 +refs/heads/main-in-other:refs/heads/main-in-other Z 1370 +refs/tags/tag-in-other:refs/tags/tag-in-other Z 1371 EOF 1372 ( 1373 cur=+refs/ && 1374 __git_complete_fetch_refspecs other + refs/ && 1375 print_comp 1376 ) && 1377 test_cmp expected out 1378 ' 1379 1380 test_expect_success '__git_complete_worktree_paths' ' 1381 test_when_finished "git worktree remove other_wt" && 1382 git worktree add --orphan other_wt && 1383 run_completion "git worktree remove " && 1384 test_grep other_wt out 1385 ' 1386 1387 test_expect_success '__git_complete_worktree_paths - not a git repository' ' 1388 ( 1389 cd non-repo && 1390 GIT_CEILING_DIRECTORIES="$ROOT" && 1391 export GIT_CEILING_DIRECTORIES && 1392 test_completion "git worktree remove " "" 1393 ) 1394 ' 1395 1396 test_expect_success '__git_complete_worktree_paths with -C' ' 1397 test_when_finished "git -C otherrepo worktree remove otherrepo_wt" && 1398 git -C otherrepo worktree add --orphan otherrepo_wt && 1399 run_completion "git -C otherrepo worktree remove " && 1400 test_grep otherrepo_wt out 1401 ' 1402 1403 test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' ' 1404 test_completion "git switch " <<-\EOF 1405 branch-in-other Z 1406 branch/with/slash Z 1407 main Z 1408 main-in-other Z 1409 matching-branch Z 1410 EOF 1411 ' 1412 1413 test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' ' 1414 test_completion "git bisect " <<-\EOF 1415 replay Z 1416 start Z 1417 EOF 1418 ' 1419 1420 test_expect_success 'git bisect - complete options to start subcommand' ' 1421 test_completion "git bisect start --" <<-\EOF 1422 --term-new Z 1423 --term-bad Z 1424 --term-old Z 1425 --term-good Z 1426 --no-checkout Z 1427 --first-parent Z 1428 EOF 1429 ' 1430 1431 test_expect_success 'setup for git-bisect tests requiring a repo' ' 1432 git init git-bisect && 1433 ( 1434 cd git-bisect && 1435 echo "initial contents" >file && 1436 git add file && 1437 git commit -am "Initial commit" && 1438 git tag initial && 1439 echo "new line" >>file && 1440 git commit -am "First change" && 1441 echo "another new line" >>file && 1442 git commit -am "Second change" && 1443 git tag final 1444 ) 1445 ' 1446 1447 test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' ' 1448 ( 1449 cd git-bisect && 1450 test_completion "git bisect start " <<-\EOF 1451 HEAD Z 1452 final Z 1453 initial Z 1454 main Z 1455 EOF 1456 ) 1457 ' 1458 1459 # Note that these arguments are s, which in practice the fallback 1460 # completion (not the git completion) later ends up completing as paths. 1461 test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' ' 1462 ( 1463 cd git-bisect && 1464 test_completion "git bisect start final initial -- " "" 1465 ) 1466 ' 1467 1468 test_expect_success 'setup for git-bisect tests requiring ongoing bisection' ' 1469 ( 1470 cd git-bisect && 1471 git bisect start --term-new=custom_new --term-old=custom_old final initial 1472 ) 1473 ' 1474 1475 test_expect_success 'git-bisect - when bisecting all subcommands are candidates' ' 1476 ( 1477 cd git-bisect && 1478 test_completion "git bisect " <<-\EOF 1479 start Z 1480 bad Z 1481 custom_new Z 1482 custom_old Z 1483 new Z 1484 good Z 1485 old Z 1486 terms Z 1487 skip Z 1488 reset Z 1489 visualize Z 1490 replay Z 1491 log Z 1492 run Z 1493 help Z 1494 EOF 1495 ) 1496 ' 1497 1498 test_expect_success 'git-bisect - options to terms subcommand are candidates' ' 1499 ( 1500 cd git-bisect && 1501 test_completion "git bisect terms --" <<-\EOF 1502 --term-bad Z 1503 --term-good Z 1504 --term-new Z 1505 --term-old Z 1506 EOF 1507 ) 1508 ' 1509 1510 test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' ' 1511 ( 1512 cd git-bisect && 1513 # The completion used for git-log and here does not complete 1514 # every git-log option, so rather than hope to stay in sync 1515 # with exactly what it does we will just spot-test here. 1516 test_completion "git bisect visualize --sta" <<-\EOF && 1517 --stat Z 1518 EOF 1519 test_completion "git bisect visualize --summar" <<-\EOF 1520 --summary Z 1521 EOF 1522 ) 1523 ' 1524 1525 test_expect_success 'git-bisect - view subcommand is not a candidate' ' 1526 ( 1527 cd git-bisect && 1528 test_completion "git bisect vi" <<-\EOF 1529 visualize Z 1530 EOF 1531 ) 1532 ' 1533 1534 test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' ' 1535 ( 1536 cd git-bisect && 1537 # The completion used for git-log and here does not complete 1538 # every git-log option, so rather than hope to stay in sync 1539 # with exactly what it does we will just spot-test here. 1540 test_completion "git bisect view --sta" <<-\EOF && 1541 --stat Z 1542 EOF 1543 test_completion "git bisect view --summar" <<-\EOF 1544 --summary Z 1545 EOF 1546 ) 1547 ' 1548 1549 test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' ' 1550 test_completion "git checkout " <<-\EOF 1551 HEAD Z 1552 branch-in-other Z 1553 branch/with/slash Z 1554 main Z 1555 main-in-other Z 1556 matching-branch Z 1557 matching-tag Z 1558 other/HEAD Z 1559 other/branch-in-other Z 1560 other/main-in-other Z 1561 remote/with/slash/HEAD Z 1562 remote/with/slash/branch/with/slash Z 1563 EOF 1564 ' 1565 1566 test_expect_success 'git switch - with --no-guess, complete only local branches' ' 1567 test_completion "git switch --no-guess " <<-\EOF 1568 main Z 1569 matching-branch Z 1570 EOF 1571 ' 1572 1573 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' ' 1574 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF 1575 main Z 1576 matching-branch Z 1577 EOF 1578 ' 1579 1580 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' ' 1581 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF 1582 branch-in-other Z 1583 branch/with/slash Z 1584 main Z 1585 main-in-other Z 1586 matching-branch Z 1587 EOF 1588 ' 1589 1590 test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' ' 1591 test_completion "git switch --no-guess --guess " <<-\EOF 1592 branch-in-other Z 1593 branch/with/slash Z 1594 main Z 1595 main-in-other Z 1596 matching-branch Z 1597 EOF 1598 ' 1599 1600 test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' ' 1601 test_completion "git switch --guess --no-guess " <<-\EOF 1602 main Z 1603 matching-branch Z 1604 EOF 1605 ' 1606 1607 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' ' 1608 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF 1609 HEAD Z 1610 main Z 1611 matching-branch Z 1612 matching-tag Z 1613 other/HEAD Z 1614 other/branch-in-other Z 1615 other/main-in-other Z 1616 remote/with/slash/HEAD Z 1617 remote/with/slash/branch/with/slash Z 1618 EOF 1619 ' 1620 1621 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' 1622 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF 1623 HEAD Z 1624 branch-in-other Z 1625 branch/with/slash Z 1626 main Z 1627 main-in-other Z 1628 matching-branch Z 1629 matching-tag Z 1630 other/HEAD Z 1631 other/branch-in-other Z 1632 other/main-in-other Z 1633 remote/with/slash/HEAD Z 1634 remote/with/slash/branch/with/slash Z 1635 EOF 1636 ' 1637 1638 test_expect_success 'git checkout - with --no-guess, only completes refs' ' 1639 test_completion "git checkout --no-guess " <<-\EOF 1640 HEAD Z 1641 main Z 1642 matching-branch Z 1643 matching-tag Z 1644 other/HEAD Z 1645 other/branch-in-other Z 1646 other/main-in-other Z 1647 remote/with/slash/HEAD Z 1648 remote/with/slash/branch/with/slash Z 1649 EOF 1650 ' 1651 1652 test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' 1653 test_completion "git checkout --no-guess --guess " <<-\EOF 1654 HEAD Z 1655 branch-in-other Z 1656 branch/with/slash Z 1657 main Z 1658 main-in-other Z 1659 matching-branch Z 1660 matching-tag Z 1661 other/HEAD Z 1662 other/branch-in-other Z 1663 other/main-in-other Z 1664 remote/with/slash/HEAD Z 1665 remote/with/slash/branch/with/slash Z 1666 EOF 1667 ' 1668 1669 test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' ' 1670 test_completion "git checkout --guess --no-guess " <<-\EOF 1671 HEAD Z 1672 main Z 1673 matching-branch Z 1674 matching-tag Z 1675 other/HEAD Z 1676 other/branch-in-other Z 1677 other/main-in-other Z 1678 remote/with/slash/HEAD Z 1679 remote/with/slash/branch/with/slash Z 1680 EOF 1681 ' 1682 1683 test_expect_success 'git checkout - with checkout.guess = false, only completes refs' ' 1684 test_config checkout.guess false && 1685 test_completion "git checkout " <<-\EOF 1686 HEAD Z 1687 main Z 1688 matching-branch Z 1689 matching-tag Z 1690 other/HEAD Z 1691 other/branch-in-other Z 1692 other/main-in-other Z 1693 remote/with/slash/HEAD Z 1694 remote/with/slash/branch/with/slash Z 1695 EOF 1696 ' 1697 1698 test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' ' 1699 test_config checkout.guess true && 1700 test_completion "git checkout " <<-\EOF 1701 HEAD Z 1702 branch-in-other Z 1703 branch/with/slash Z 1704 main Z 1705 main-in-other Z 1706 matching-branch Z 1707 matching-tag Z 1708 other/HEAD Z 1709 other/branch-in-other Z 1710 other/main-in-other Z 1711 remote/with/slash/HEAD Z 1712 remote/with/slash/branch/with/slash Z 1713 EOF 1714 ' 1715 1716 test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' ' 1717 test_config checkout.guess false && 1718 test_completion "git checkout --guess " <<-\EOF 1719 HEAD Z 1720 branch-in-other Z 1721 branch/with/slash Z 1722 main Z 1723 main-in-other Z 1724 matching-branch Z 1725 matching-tag Z 1726 other/HEAD Z 1727 other/branch-in-other Z 1728 other/main-in-other Z 1729 remote/with/slash/HEAD Z 1730 remote/with/slash/branch/with/slash Z 1731 EOF 1732 ' 1733 1734 test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' ' 1735 test_config checkout.guess true && 1736 test_completion "git checkout --no-guess " <<-\EOF 1737 HEAD Z 1738 main Z 1739 matching-branch Z 1740 matching-tag Z 1741 other/HEAD Z 1742 other/branch-in-other Z 1743 other/main-in-other Z 1744 remote/with/slash/HEAD Z 1745 remote/with/slash/branch/with/slash Z 1746 EOF 1747 ' 1748 1749 test_expect_success 'git switch - with --detach, complete all references' ' 1750 test_completion "git switch --detach " <<-\EOF 1751 HEAD Z 1752 main Z 1753 matching-branch Z 1754 matching-tag Z 1755 other/HEAD Z 1756 other/branch-in-other Z 1757 other/main-in-other Z 1758 remote/with/slash/HEAD Z 1759 remote/with/slash/branch/with/slash Z 1760 EOF 1761 ' 1762 1763 test_expect_success 'git checkout - with --detach, complete only references' ' 1764 test_completion "git checkout --detach " <<-\EOF 1765 HEAD Z 1766 main Z 1767 matching-branch Z 1768 matching-tag Z 1769 other/HEAD Z 1770 other/branch-in-other Z 1771 other/main-in-other Z 1772 remote/with/slash/HEAD Z 1773 remote/with/slash/branch/with/slash Z 1774 EOF 1775 ' 1776 1777 test_expect_success 'setup sparse-checkout tests' ' 1778 # set up sparse-checkout repo 1779 git init sparse-checkout && 1780 ( 1781 cd sparse-checkout && 1782 mkdir -p folder1/0/1 folder2/0 folder3 && 1783 touch folder1/0/1/t.txt && 1784 touch folder2/0/t.txt && 1785 touch folder3/t.txt && 1786 git add . && 1787 git commit -am "Initial commit" 1788 ) 1789 ' 1790 1791 test_expect_success 'sparse-checkout completes subcommands' ' 1792 test_completion "git sparse-checkout " <<-\EOF 1793 list Z 1794 init Z 1795 set Z 1796 add Z 1797 reapply Z 1798 disable Z 1799 EOF 1800 ' 1801 1802 test_expect_success 'cone mode sparse-checkout completes directory names' ' 1803 # initialize sparse-checkout definitions 1804 git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 && 1805 1806 # test tab completion 1807 ( 1808 cd sparse-checkout && 1809 test_completion "git sparse-checkout set f" <<-\EOF 1810 folder1/ 1811 folder2/ 1812 folder3/ 1813 EOF 1814 ) && 1815 1816 ( 1817 cd sparse-checkout && 1818 test_completion "git sparse-checkout set folder1/" <<-\EOF 1819 folder1/0/ 1820 EOF 1821 ) && 1822 1823 ( 1824 cd sparse-checkout && 1825 test_completion "git sparse-checkout set folder1/0/" <<-\EOF 1826 folder1/0/1/ 1827 EOF 1828 ) && 1829 1830 ( 1831 cd sparse-checkout/folder1 && 1832 test_completion "git sparse-checkout add 0" <<-\EOF 1833 0/ 1834 EOF 1835 ) 1836 ' 1837 1838 test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' ' 1839 # reset sparse-checkout 1840 git -C sparse-checkout sparse-checkout disable && 1841 ( 1842 cd sparse-checkout && 1843 mkdir "directory with spaces" && 1844 mkdir "directory-with-áccent" && 1845 >"directory with spaces/randomfile" && 1846 >"directory-with-áccent/randomfile" && 1847 git add . && 1848 git commit -m "Add directory with spaces and directory with accent" && 1849 git sparse-checkout set --cone "directory with spaces" \ 1850 "directory-with-áccent" && 1851 test_completion "git sparse-checkout add dir" <<-\EOF && 1852 directory with spaces/ 1853 directory-with-áccent/ 1854 EOF 1855 rm -rf "directory with spaces" && 1856 rm -rf "directory-with-áccent" && 1857 git add . && 1858 git commit -m "Remove directory with spaces and directory with accent" 1859 ) 1860 ' 1861 1862 # use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths 1863 test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' ' 1864 # reset sparse-checkout 1865 git -C sparse-checkout sparse-checkout disable && 1866 ( 1867 cd sparse-checkout && 1868 mkdir "$(printf "directory\twith\ttabs")" && 1869 >"$(printf "directory\twith\ttabs")/randomfile" && 1870 git add . && 1871 git commit -m "Add directory with tabs" && 1872 git sparse-checkout set --cone \ 1873 "$(printf "directory\twith\ttabs")" && 1874 test_completion "git sparse-checkout add dir" <<-\EOF && 1875 directory with tabs/ 1876 EOF 1877 rm -rf "$(printf "directory\twith\ttabs")" && 1878 git add . && 1879 git commit -m "Remove directory with tabs" 1880 ) 1881 ' 1882 1883 # use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths 1884 test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' ' 1885 # reset sparse-checkout 1886 git -C sparse-checkout sparse-checkout disable && 1887 ( 1888 cd sparse-checkout && 1889 mkdir "directory\with\backslashes" && 1890 >"directory\with\backslashes/randomfile" && 1891 git add . && 1892 git commit -m "Add directory with backslashes" && 1893 git sparse-checkout set --cone \ 1894 "directory\with\backslashes" && 1895 test_completion "git sparse-checkout add dir" <<-\EOF && 1896 directory\with\backslashes/ 1897 EOF 1898 rm -rf "directory\with\backslashes" && 1899 git add . && 1900 git commit -m "Remove directory with backslashes" 1901 ) 1902 ' 1903 1904 test_expect_success 'non-cone mode sparse-checkout gives rooted paths' ' 1905 # reset sparse-checkout repo to non-cone mode 1906 git -C sparse-checkout sparse-checkout disable && 1907 git -C sparse-checkout sparse-checkout set --no-cone && 1908 1909 ( 1910 cd sparse-checkout && 1911 # expected to be empty since we have not configured 1912 # custom completion for non-cone mode 1913 test_completion "git sparse-checkout set f" <<-\EOF 1914 /folder1/0/1/t.txt Z 1915 /folder1/expected Z 1916 /folder1/out Z 1917 /folder1/out_sorted Z 1918 /folder2/0/t.txt Z 1919 /folder3/t.txt Z 1920 EOF 1921 ) 1922 ' 1923 1924 test_expect_success 'git sparse-checkout set --cone completes directory names' ' 1925 git -C sparse-checkout sparse-checkout disable && 1926 1927 ( 1928 cd sparse-checkout && 1929 test_completion "git sparse-checkout set --cone f" <<-\EOF 1930 folder1/ 1931 folder2/ 1932 folder3/ 1933 EOF 1934 ) 1935 ' 1936 1937 test_expect_success 'git switch - with -d, complete all references' ' 1938 test_completion "git switch -d " <<-\EOF 1939 HEAD Z 1940 main Z 1941 matching-branch Z 1942 matching-tag Z 1943 other/HEAD Z 1944 other/branch-in-other Z 1945 other/main-in-other Z 1946 remote/with/slash/HEAD Z 1947 remote/with/slash/branch/with/slash Z 1948 EOF 1949 ' 1950 1951 test_expect_success 'git checkout - with -d, complete only references' ' 1952 test_completion "git checkout -d " <<-\EOF 1953 HEAD Z 1954 main Z 1955 matching-branch Z 1956 matching-tag Z 1957 other/HEAD Z 1958 other/branch-in-other Z 1959 other/main-in-other Z 1960 remote/with/slash/HEAD Z 1961 remote/with/slash/branch/with/slash Z 1962 EOF 1963 ' 1964 1965 test_expect_success 'git switch - with --track, complete only remote branches' ' 1966 test_completion "git switch --track " <<-\EOF && 1967 other/HEAD Z 1968 other/branch-in-other Z 1969 other/main-in-other Z 1970 remote/with/slash/HEAD Z 1971 remote/with/slash/branch/with/slash Z 1972 EOF 1973 test_completion "git switch -t " <<-\EOF 1974 other/HEAD Z 1975 other/branch-in-other Z 1976 other/main-in-other Z 1977 remote/with/slash/HEAD Z 1978 remote/with/slash/branch/with/slash Z 1979 EOF 1980 ' 1981 1982 test_expect_success 'git checkout - with --track, complete only remote branches' ' 1983 test_completion "git checkout --track " <<-\EOF && 1984 other/HEAD Z 1985 other/branch-in-other Z 1986 other/main-in-other Z 1987 remote/with/slash/HEAD Z 1988 remote/with/slash/branch/with/slash Z 1989 EOF 1990 test_completion "git checkout -t " <<-\EOF 1991 other/HEAD Z 1992 other/branch-in-other Z 1993 other/main-in-other Z 1994 remote/with/slash/HEAD Z 1995 remote/with/slash/branch/with/slash Z 1996 EOF 1997 ' 1998 1999 test_expect_success 'git switch - with --no-track, complete only local branch names' ' 2000 test_completion "git switch --no-track " <<-\EOF 2001 main Z 2002 matching-branch Z 2003 EOF 2004 ' 2005 2006 test_expect_success 'git checkout - with --no-track, complete only local references' ' 2007 test_completion "git checkout --no-track " <<-\EOF 2008 HEAD Z 2009 main Z 2010 matching-branch Z 2011 matching-tag Z 2012 other/HEAD Z 2013 other/branch-in-other Z 2014 other/main-in-other Z 2015 remote/with/slash/HEAD Z 2016 remote/with/slash/branch/with/slash Z 2017 EOF 2018 ' 2019 2020 test_expect_success 'git switch - with -c, complete all references' ' 2021 test_completion "git switch -c new-branch " <<-\EOF 2022 HEAD Z 2023 main Z 2024 matching-branch Z 2025 matching-tag Z 2026 other/HEAD Z 2027 other/branch-in-other Z 2028 other/main-in-other Z 2029 remote/with/slash/HEAD Z 2030 remote/with/slash/branch/with/slash Z 2031 EOF 2032 ' 2033 2034 test_expect_success 'git switch - with -C, complete all references' ' 2035 test_completion "git switch -C new-branch " <<-\EOF 2036 HEAD Z 2037 main Z 2038 matching-branch Z 2039 matching-tag Z 2040 other/HEAD Z 2041 other/branch-in-other Z 2042 other/main-in-other Z 2043 remote/with/slash/HEAD Z 2044 remote/with/slash/branch/with/slash Z 2045 EOF 2046 ' 2047 2048 test_expect_success 'git switch - with -c and --track, complete all references' ' 2049 test_completion "git switch -c new-branch --track " <<-EOF 2050 HEAD Z 2051 main Z 2052 matching-branch Z 2053 matching-tag Z 2054 other/HEAD Z 2055 other/branch-in-other Z 2056 other/main-in-other Z 2057 remote/with/slash/HEAD Z 2058 remote/with/slash/branch/with/slash Z 2059 EOF 2060 ' 2061 2062 test_expect_success 'git switch - with -C and --track, complete all references' ' 2063 test_completion "git switch -C new-branch --track " <<-EOF 2064 HEAD Z 2065 main Z 2066 matching-branch Z 2067 matching-tag Z 2068 other/HEAD Z 2069 other/branch-in-other Z 2070 other/main-in-other Z 2071 remote/with/slash/HEAD Z 2072 remote/with/slash/branch/with/slash Z 2073 EOF 2074 ' 2075 2076 test_expect_success 'git switch - with -c and --no-track, complete all references' ' 2077 test_completion "git switch -c new-branch --no-track " <<-\EOF 2078 HEAD Z 2079 main Z 2080 matching-branch Z 2081 matching-tag Z 2082 other/HEAD Z 2083 other/branch-in-other Z 2084 other/main-in-other Z 2085 remote/with/slash/HEAD Z 2086 remote/with/slash/branch/with/slash Z 2087 EOF 2088 ' 2089 2090 test_expect_success 'git switch - with -C and --no-track, complete all references' ' 2091 test_completion "git switch -C new-branch --no-track " <<-\EOF 2092 HEAD Z 2093 main Z 2094 matching-branch Z 2095 matching-tag Z 2096 other/HEAD Z 2097 other/branch-in-other Z 2098 other/main-in-other Z 2099 remote/with/slash/HEAD Z 2100 remote/with/slash/branch/with/slash Z 2101 EOF 2102 ' 2103 2104 test_expect_success 'git checkout - with -b, complete all references' ' 2105 test_completion "git checkout -b new-branch " <<-\EOF 2106 HEAD Z 2107 main Z 2108 matching-branch Z 2109 matching-tag Z 2110 other/HEAD Z 2111 other/branch-in-other Z 2112 other/main-in-other Z 2113 remote/with/slash/HEAD Z 2114 remote/with/slash/branch/with/slash Z 2115 EOF 2116 ' 2117 2118 test_expect_success 'git checkout - with -B, complete all references' ' 2119 test_completion "git checkout -B new-branch " <<-\EOF 2120 HEAD Z 2121 main Z 2122 matching-branch Z 2123 matching-tag Z 2124 other/HEAD Z 2125 other/branch-in-other Z 2126 other/main-in-other Z 2127 remote/with/slash/HEAD Z 2128 remote/with/slash/branch/with/slash Z 2129 EOF 2130 ' 2131 2132 test_expect_success 'git checkout - with -b and --track, complete all references' ' 2133 test_completion "git checkout -b new-branch --track " <<-EOF 2134 HEAD Z 2135 main Z 2136 matching-branch Z 2137 matching-tag Z 2138 other/HEAD Z 2139 other/branch-in-other Z 2140 other/main-in-other Z 2141 remote/with/slash/HEAD Z 2142 remote/with/slash/branch/with/slash Z 2143 EOF 2144 ' 2145 2146 test_expect_success 'git checkout - with -B and --track, complete all references' ' 2147 test_completion "git checkout -B new-branch --track " <<-EOF 2148 HEAD Z 2149 main Z 2150 matching-branch Z 2151 matching-tag Z 2152 other/HEAD Z 2153 other/branch-in-other Z 2154 other/main-in-other Z 2155 remote/with/slash/HEAD Z 2156 remote/with/slash/branch/with/slash Z 2157 EOF 2158 ' 2159 2160 test_expect_success 'git checkout - with -b and --no-track, complete all references' ' 2161 test_completion "git checkout -b new-branch --no-track " <<-\EOF 2162 HEAD Z 2163 main Z 2164 matching-branch Z 2165 matching-tag Z 2166 other/HEAD Z 2167 other/branch-in-other Z 2168 other/main-in-other Z 2169 remote/with/slash/HEAD Z 2170 remote/with/slash/branch/with/slash Z 2171 EOF 2172 ' 2173 2174 test_expect_success 'git checkout - with -B and --no-track, complete all references' ' 2175 test_completion "git checkout -B new-branch --no-track " <<-\EOF 2176 HEAD Z 2177 main Z 2178 matching-branch Z 2179 matching-tag Z 2180 other/HEAD Z 2181 other/branch-in-other Z 2182 other/main-in-other Z 2183 remote/with/slash/HEAD Z 2184 remote/with/slash/branch/with/slash Z 2185 EOF 2186 ' 2187 2188 test_expect_success 'git switch - for -c, complete local branches and unique remote branches' ' 2189 test_completion "git switch -c " <<-\EOF 2190 branch-in-other Z 2191 branch/with/slash Z 2192 main Z 2193 main-in-other Z 2194 matching-branch Z 2195 EOF 2196 ' 2197 2198 test_expect_success 'git switch - for -C, complete local branches and unique remote branches' ' 2199 test_completion "git switch -C " <<-\EOF 2200 branch-in-other Z 2201 branch/with/slash Z 2202 main Z 2203 main-in-other Z 2204 matching-branch Z 2205 EOF 2206 ' 2207 2208 test_expect_success 'git switch - for -c with --no-guess, complete local branches only' ' 2209 test_completion "git switch --no-guess -c " <<-\EOF 2210 main Z 2211 matching-branch Z 2212 EOF 2213 ' 2214 2215 test_expect_success 'git switch - for -C with --no-guess, complete local branches only' ' 2216 test_completion "git switch --no-guess -C " <<-\EOF 2217 main Z 2218 matching-branch Z 2219 EOF 2220 ' 2221 2222 test_expect_success 'git switch - for -c with --no-track, complete local branches only' ' 2223 test_completion "git switch --no-track -c " <<-\EOF 2224 main Z 2225 matching-branch Z 2226 EOF 2227 ' 2228 2229 test_expect_success 'git switch - for -C with --no-track, complete local branches only' ' 2230 test_completion "git switch --no-track -C " <<-\EOF 2231 main Z 2232 matching-branch Z 2233 EOF 2234 ' 2235 2236 test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' ' 2237 test_completion "git checkout -b " <<-\EOF 2238 branch-in-other Z 2239 branch/with/slash Z 2240 main Z 2241 main-in-other Z 2242 matching-branch Z 2243 EOF 2244 ' 2245 2246 test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' ' 2247 test_completion "git checkout -B " <<-\EOF 2248 branch-in-other Z 2249 branch/with/slash Z 2250 main Z 2251 main-in-other Z 2252 matching-branch Z 2253 EOF 2254 ' 2255 2256 test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' ' 2257 test_completion "git checkout --no-guess -b " <<-\EOF 2258 main Z 2259 matching-branch Z 2260 EOF 2261 ' 2262 2263 test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' ' 2264 test_completion "git checkout --no-guess -B " <<-\EOF 2265 main Z 2266 matching-branch Z 2267 EOF 2268 ' 2269 2270 test_expect_success 'git checkout - for -b with --no-track, complete local branches only' ' 2271 test_completion "git checkout --no-track -b " <<-\EOF 2272 main Z 2273 matching-branch Z 2274 EOF 2275 ' 2276 2277 test_expect_success 'git checkout - for -B with --no-track, complete local branches only' ' 2278 test_completion "git checkout --no-track -B " <<-\EOF 2279 main Z 2280 matching-branch Z 2281 EOF 2282 ' 2283 2284 test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' ' 2285 test_completion "git switch --orphan " <<-\EOF 2286 branch-in-other Z 2287 branch/with/slash Z 2288 main Z 2289 main-in-other Z 2290 matching-branch Z 2291 EOF 2292 ' 2293 2294 test_expect_success 'git switch - --orphan with branch already provided completes nothing else' ' 2295 test_completion "git switch --orphan main " <<-\EOF 2296 2297 EOF 2298 ' 2299 2300 test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' ' 2301 test_completion "git checkout --orphan " <<-\EOF 2302 branch-in-other Z 2303 branch/with/slash Z 2304 main Z 2305 main-in-other Z 2306 matching-branch Z 2307 EOF 2308 ' 2309 2310 test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' ' 2311 test_completion "git checkout --orphan main " <<-\EOF 2312 HEAD Z 2313 main Z 2314 matching-branch Z 2315 matching-tag Z 2316 other/HEAD Z 2317 other/branch-in-other Z 2318 other/main-in-other Z 2319 remote/with/slash/HEAD Z 2320 remote/with/slash/branch/with/slash Z 2321 EOF 2322 ' 2323 2324 test_expect_success 'git restore completes modified files' ' 2325 test_commit A a.file && 2326 echo B >a.file && 2327 test_completion "git restore a." <<-\EOF 2328 a.file 2329 EOF 2330 ' 2331 2332 test_expect_success 'teardown after ref completion' ' 2333 git branch -d matching-branch && 2334 git tag -d matching-tag && 2335 git remote remove other && 2336 git remote remove remote/with/slash 2337 ' 2338 2339 2340 test_path_completion () 2341 { 2342 test $# = 2 || BUG "not 2 parameters to test_path_completion" 2343 2344 local cur="$1" expected="$2" 2345 echo "$expected" >expected && 2346 ( 2347 # In the following tests calling this function we only 2348 # care about how __git_complete_index_file() deals with 2349 # unusual characters in path names. By requesting only 2350 # untracked files we do not have to bother adding any 2351 # paths to the index in those tests. 2352 __git_complete_index_file --others && 2353 print_comp 2354 ) && 2355 test_cmp expected out 2356 } 2357 2358 test_expect_success 'setup for path completion tests' ' 2359 mkdir simple-dir \ 2360 "spaces in dir" \ 2361 árvíztűrő && 2362 touch simple-dir/simple-file \ 2363 "spaces in dir/spaces in file" \ 2364 "árvíztűrő/Сайн яваарай" && 2365 if test_have_prereq !MINGW && 2366 mkdir BS\\dir \ 2367 '$'separators\034in\035dir'' && 2368 touch BS\\dir/DQ\"file \ 2369 '$'separators\034in\035dir/sep\036in\037file'' 2370 then 2371 test_set_prereq FUNNIERNAMES 2372 else 2373 rm -rf BS\\dir '$'separators\034in\035dir'' 2374 fi 2375 ' 2376 2377 test_expect_success '__git_complete_index_file - simple' ' 2378 test_path_completion simple simple-dir && # Bash is supposed to 2379 # add the trailing /. 2380 test_path_completion simple-dir/simple simple-dir/simple-file 2381 ' 2382 2383 test_expect_success \ 2384 '__git_complete_index_file - escaped characters on cmdline' ' 2385 test_path_completion spac "spaces in dir" && # Bash will turn this 2386 # into "spaces\ in\ dir" 2387 test_path_completion "spaces\\ i" \ 2388 "spaces in dir" && 2389 test_path_completion "spaces\\ in\\ dir/s" \ 2390 "spaces in dir/spaces in file" && 2391 test_path_completion "spaces\\ in\\ dir/spaces\\ i" \ 2392 "spaces in dir/spaces in file" 2393 ' 2394 2395 test_expect_success \ 2396 '__git_complete_index_file - quoted characters on cmdline' ' 2397 # Testing with an opening but without a corresponding closing 2398 # double quote is important. 2399 test_path_completion \"spac "spaces in dir" && 2400 test_path_completion "\"spaces i" \ 2401 "spaces in dir" && 2402 test_path_completion "\"spaces in dir/s" \ 2403 "spaces in dir/spaces in file" && 2404 test_path_completion "\"spaces in dir/spaces i" \ 2405 "spaces in dir/spaces in file" 2406 ' 2407 2408 test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' ' 2409 test_path_completion á árvíztűrő && 2410 test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай" 2411 ' 2412 2413 test_expect_success FUNNIERNAMES \ 2414 '__git_complete_index_file - C-style escapes in ls-files output' ' 2415 test_path_completion BS \ 2416 BS\\dir && 2417 test_path_completion BS\\\\d \ 2418 BS\\dir && 2419 test_path_completion BS\\\\dir/DQ \ 2420 BS\\dir/DQ\"file && 2421 test_path_completion BS\\\\dir/DQ\\\"f \ 2422 BS\\dir/DQ\"file 2423 ' 2424 2425 test_expect_success FUNNIERNAMES \ 2426 '__git_complete_index_file - \nnn-escaped characters in ls-files output' ' 2427 test_path_completion sep '$'separators\034in\035dir'' && 2428 test_path_completion '$'separators\034i'' \ 2429 '$'separators\034in\035dir'' && 2430 test_path_completion '$'separators\034in\035dir/sep'' \ 2431 '$'separators\034in\035dir/sep\036in\037file'' && 2432 test_path_completion '$'separators\034in\035dir/sep\036i'' \ 2433 '$'separators\034in\035dir/sep\036in\037file'' 2434 ' 2435 2436 test_expect_success FUNNYNAMES \ 2437 '__git_complete_index_file - removing repeated quoted path components' ' 2438 test_when_finished rm -r repeated-quoted && 2439 mkdir repeated-quoted && # A directory whose name in itself 2440 # would not be quoted ... 2441 >repeated-quoted/0-file && 2442 >repeated-quoted/1\"file && # ... but here the file makes the 2443 # dirname quoted ... 2444 >repeated-quoted/2-file && 2445 >repeated-quoted/3\"file && # ... and here, too. 2446 2447 # Still, we should list the directory name only once. 2448 test_path_completion repeated repeated-quoted 2449 ' 2450 2451 test_expect_success 'teardown after path completion tests' ' 2452 rm -rf simple-dir "spaces in dir" árvíztűrő \ 2453 BS\\dir '$'separators\034in\035dir'' 2454 ' 2455 2456 test_expect_success '__git_find_on_cmdline - single match' ' 2457 echo list >expect && 2458 ( 2459 words=(git command --opt list) && 2460 cword=${#words[@]} && 2461 __git_cmd_idx=1 && 2462 __git_find_on_cmdline "add list remove" >actual 2463 ) && 2464 test_cmp expect actual 2465 ' 2466 2467 test_expect_success '__git_find_on_cmdline - multiple matches' ' 2468 echo remove >expect && 2469 ( 2470 words=(git command -o --opt remove list add) && 2471 cword=${#words[@]} && 2472 __git_cmd_idx=1 && 2473 __git_find_on_cmdline "add list remove" >actual 2474 ) && 2475 test_cmp expect actual 2476 ' 2477 2478 test_expect_success '__git_find_on_cmdline - no match' ' 2479 ( 2480 words=(git command --opt branch) && 2481 cword=${#words[@]} && 2482 __git_cmd_idx=1 && 2483 __git_find_on_cmdline "add list remove" >actual 2484 ) && 2485 test_must_be_empty actual 2486 ' 2487 2488 test_expect_success '__git_find_on_cmdline - single match with index' ' 2489 echo "3 list" >expect && 2490 ( 2491 words=(git command --opt list) && 2492 cword=${#words[@]} && 2493 __git_cmd_idx=1 && 2494 __git_find_on_cmdline --show-idx "add list remove" >actual 2495 ) && 2496 test_cmp expect actual 2497 ' 2498 2499 test_expect_success '__git_find_on_cmdline - multiple matches with index' ' 2500 echo "4 remove" >expect && 2501 ( 2502 words=(git command -o --opt remove list add) && 2503 cword=${#words[@]} && 2504 __git_cmd_idx=1 && 2505 __git_find_on_cmdline --show-idx "add list remove" >actual 2506 ) && 2507 test_cmp expect actual 2508 ' 2509 2510 test_expect_success '__git_find_on_cmdline - no match with index' ' 2511 ( 2512 words=(git command --opt branch) && 2513 cword=${#words[@]} && 2514 __git_cmd_idx=1 && 2515 __git_find_on_cmdline --show-idx "add list remove" >actual 2516 ) && 2517 test_must_be_empty actual 2518 ' 2519 2520 test_expect_success '__git_find_on_cmdline - ignores matches before command with index' ' 2521 echo "6 remove" >expect && 2522 ( 2523 words=(git -C remove command -o --opt remove list add) && 2524 cword=${#words[@]} && 2525 __git_cmd_idx=3 && 2526 __git_find_on_cmdline --show-idx "add list remove" >actual 2527 ) && 2528 test_cmp expect actual 2529 ' 2530 2531 test_expect_success '__git_get_config_variables' ' 2532 cat >expect <<-EOF && 2533 name-1 2534 name-2 2535 EOF 2536 test_config interesting.name-1 good && 2537 test_config interesting.name-2 good && 2538 test_config subsection.interesting.name-3 bad && 2539 __git_get_config_variables interesting >actual && 2540 test_cmp expect actual 2541 ' 2542 2543 test_expect_success '__git_pretty_aliases' ' 2544 cat >expect <<-EOF && 2545 author 2546 hash 2547 EOF 2548 test_config pretty.author "%an %ae" && 2549 test_config pretty.hash %H && 2550 __git_pretty_aliases >actual && 2551 test_cmp expect actual 2552 ' 2553 2554 test_expect_success 'basic' ' 2555 run_completion "git " && 2556 # built-in 2557 test_grep -q "^add \$" out && 2558 # script 2559 test_grep -q "^rebase \$" out && 2560 # plumbing 2561 test_grep ! -q "^ls-files \$" out && 2562 2563 run_completion "git r" && 2564 test_grep ! -q -v "^r" out 2565 ' 2566 2567 test_expect_success 'double dash "git" itself' ' 2568 test_completion "git --" <<-\EOF 2569 --paginate Z 2570 --no-pager Z 2571 --git-dir= 2572 --bare Z 2573 --version Z 2574 --exec-path Z 2575 --exec-path= 2576 --html-path Z 2577 --man-path Z 2578 --info-path Z 2579 --work-tree= 2580 --namespace= 2581 --no-replace-objects Z 2582 --help Z 2583 EOF 2584 ' 2585 2586 test_expect_success 'double dash "git checkout"' ' 2587 test_completion "git checkout --" <<-\EOF 2588 --quiet Z 2589 --detach Z 2590 --track Z 2591 --orphan=Z 2592 --ours Z 2593 --theirs Z 2594 --merge Z 2595 --conflict=Z 2596 --patch Z 2597 --unified=Z 2598 --inter-hunk-context=Z 2599 --ignore-skip-worktree-bits Z 2600 --ignore-other-worktrees Z 2601 --recurse-submodules Z 2602 --auto-advance Z 2603 --progress Z 2604 --guess Z 2605 --no-guess Z 2606 --no-... Z 2607 --overlay Z 2608 --pathspec-file-nul Z 2609 --pathspec-from-file=Z 2610 EOF 2611 ' 2612 2613 test_expect_success 'general options' ' 2614 test_completion "git --ver" "--version " && 2615 test_completion "git --hel" "--help " && 2616 test_completion "git --exe" <<-\EOF && 2617 --exec-path Z 2618 --exec-path= 2619 EOF 2620 test_completion "git --htm" "--html-path " && 2621 test_completion "git --pag" "--paginate " && 2622 test_completion "git --no-p" "--no-pager " && 2623 test_completion "git --git" "--git-dir=" && 2624 test_completion "git --wor" "--work-tree=" && 2625 test_completion "git --nam" "--namespace=" && 2626 test_completion "git --bar" "--bare " && 2627 test_completion "git --inf" "--info-path " && 2628 test_completion "git --no-r" "--no-replace-objects " 2629 ' 2630 2631 test_expect_success 'general options plus command' ' 2632 test_completion "git --version check" "checkout " && 2633 test_completion "git --paginate check" "checkout " && 2634 test_completion "git --git-dir=foo check" "checkout " && 2635 test_completion "git --bare check" "checkout " && 2636 test_completion "git --exec-path=foo check" "checkout " && 2637 test_completion "git --html-path check" "checkout " && 2638 test_completion "git --no-pager check" "checkout " && 2639 test_completion "git --work-tree=foo check" "checkout " && 2640 test_completion "git --namespace=foo check" "checkout " && 2641 test_completion "git --paginate check" "checkout " && 2642 test_completion "git --info-path check" "checkout " && 2643 test_completion "git --no-replace-objects check" "checkout " && 2644 test_completion "git --git-dir some/path check" "checkout " && 2645 test_completion "git -c conf.var=value check" "checkout " && 2646 test_completion "git -C some/path check" "checkout " && 2647 test_completion "git --work-tree some/path check" "checkout " && 2648 test_completion "git --namespace name/space check" "checkout " 2649 ' 2650 2651 test_expect_success 'git --help completion' ' 2652 test_completion "git --help ad" "add " && 2653 test_completion "git --help core" "core-tutorial " 2654 ' 2655 2656 test_expect_success 'completion.commands removes multiple commands' ' 2657 test_config completion.commands "-cherry -mergetool" && 2658 git --list-cmds=list-mainporcelain,list-complete,config >out && 2659 test_grep ! -E "^(cherry|mergetool)$" out 2660 ' 2661 2662 test_expect_success 'setup for integration tests' ' 2663 echo content >file1 && 2664 echo more >file2 && 2665 git add file1 file2 && 2666 echo untracked >file3 && 2667 echo untracked >ufile && 2668 git commit -m one && 2669 git branch mybranch && 2670 git tag mytag 2671 ' 2672 2673 test_expect_success 'checkout completes ref names' ' 2674 test_completion "git checkout m" <<-\EOF 2675 main Z 2676 mybranch Z 2677 mytag Z 2678 EOF 2679 ' 2680 2681 test_expect_success 'checkout does not match ref names of a different case' ' 2682 test_completion "git checkout M" "" 2683 ' 2684 2685 test_expect_success 'checkout matches case insensitively with GIT_COMPLETION_IGNORE_CASE' ' 2686 ( 2687 GIT_COMPLETION_IGNORE_CASE=1 && 2688 test_completion "git checkout M" <<-\EOF 2689 main Z 2690 mybranch Z 2691 mytag Z 2692 EOF 2693 ) 2694 ' 2695 2696 test_expect_success 'checkout completes pseudo refs' ' 2697 test_completion "git checkout H" <<-\EOF 2698 HEAD Z 2699 EOF 2700 ' 2701 2702 test_expect_success 'checkout completes pseudo refs case insensitively with GIT_COMPLETION_IGNORE_CASE' ' 2703 ( 2704 GIT_COMPLETION_IGNORE_CASE=1 && 2705 test_completion "git checkout h" <<-\EOF 2706 HEAD Z 2707 EOF 2708 ) 2709 ' 2710 2711 test_expect_success 'git -C checkout uses the right repo' ' 2712 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF 2713 branch-in-other Z 2714 EOF 2715 ' 2716 2717 test_expect_success 'git checkout completes tracked paths when no refs match' ' 2718 # file1 and file2 are tracked but file3 is not 2719 # there is no ref that begins with f 2720 test_completion "git checkout f" <<-\EOF && 2721 file1 2722 file2 2723 EOF 2724 test_completion "git checkout -- f" <<-\EOF 2725 file1 2726 file2 2727 EOF 2728 ' 2729 2730 test_expect_success 'git checkout completes untracked paths, too' ' 2731 # ufile is not tracked and there is no ref that begins with u 2732 test_completion "git checkout u" <<-\EOF && 2733 ufile 2734 EOF 2735 test_completion "git checkout -- u" <<-\EOF 2736 ufile 2737 EOF 2738 ' 2739 2740 test_expect_success 'git -C checkout completes paths in specified repo' ' 2741 # otherfile is tracked, oops is not 2742 # lostfile is tracked but lost, ufile is untracked. 2743 test_when_finished "rm -rf repo-for-checkout" && 2744 git init repo-for-checkout && 2745 echo content >repo-for-checkout/otherfile && 2746 echo content >repo-for-checkout/lostfile && 2747 git -C repo-for-checkout add otherfile && 2748 git -C repo-for-checkout add lostfile && 2749 git -C repo-for-checkout commit -m otherfile && 2750 echo untracked >repo-for-checkout/oops && 2751 echo untracked >repo-for-checkout/ufile && 2752 rm -f repo-for-checkout/lostfile && 2753 test_completion "git -C repo-for-checkout checkout o" <<-\EOF && 2754 otherfile 2755 EOF 2756 test_completion "git -C repo-for-checkout checkout -- o" <<-\EOF && 2757 otherfile 2758 EOF 2759 test_completion "git -C repo-for-checkout checkout l" <<-\EOF && 2760 lostfile 2761 EOF 2762 test_completion "git -C repo-for-checkout checkout -- l" <<-\EOF && 2763 lostfile 2764 EOF 2765 test_completion "git -C repo-for-checkout checkout u" <<-\EOF && 2766 ufile 2767 EOF 2768 test_completion "git -C repo-for-checkout checkout -- u" <<-\EOF 2769 ufile 2770 EOF 2771 ' 2772 2773 test_expect_success 'git diff completes tracked paths when no refs match' ' 2774 # file1 and file2 are tracked but file3 is not 2775 # there is no ref that begins with f 2776 test_completion "git diff f" <<-\EOF && 2777 file1 2778 file2 2779 EOF 2780 test_completion "git diff -- f" <<-\EOF 2781 file1 2782 file2 2783 EOF 2784 ' 2785 2786 test_expect_success 'git diff [--] completes untracked paths, too' ' 2787 # ufile is not tracked and there is no ref that begins with u 2788 test_completion "git diff u" <<-\EOF && 2789 ufile 2790 EOF 2791 test_completion "git diff -- u" <<-\EOF 2792 ufile 2793 EOF 2794 ' 2795 2796 test_expect_success 'git -C diff completes paths in specified repo' ' 2797 test_when_finished "rm -rf repo-for-diff" && 2798 git init repo-for-diff && 2799 echo content >repo-for-diff/otherfile && 2800 echo content >repo-for-diff/lostfile && 2801 git -C repo-for-diff add otherfile && 2802 git -C repo-for-diff add lostfile && 2803 git -C repo-for-diff commit -m otherfile && 2804 echo untracked >repo-for-diff/oops && 2805 echo untracked >repo-for-diff/ufile && 2806 rm -f repo-for-diff/lostfile && 2807 2808 test_completion "git -C repo-for-diff diff o" <<-\EOF && 2809 otherfile 2810 EOF 2811 test_completion "git -C repo-for-diff diff l" <<-\EOF && 2812 lostfile 2813 EOF 2814 test_completion "git -C repo-for-diff diff u" <<-\EOF && 2815 ufile 2816 EOF 2817 2818 test_completion "git -C repo-for-diff diff -- o" <<-\EOF && 2819 otherfile 2820 EOF 2821 test_completion "git -C repo-for-diff diff -- l" <<-\EOF && 2822 lostfile 2823 EOF 2824 test_completion "git -C repo-for-diff diff -- u" <<-\EOF 2825 ufile 2826 EOF 2827 ' 2828 2829 test_expect_success 'show completes all refs' ' 2830 test_completion "git show m" <<-\EOF 2831 main Z 2832 mybranch Z 2833 mytag Z 2834 EOF 2835 ' 2836 2837 test_expect_success ': completes paths' ' 2838 test_completion "git show mytag:f" <<-\EOF 2839 file1Z 2840 file2Z 2841 EOF 2842 ' 2843 2844 test_expect_success 'complete tree filename with spaces' ' 2845 echo content >"name with spaces" && 2846 git add "name with spaces" && 2847 git commit -m spaces && 2848 test_completion "git show HEAD:nam" <<-\EOF 2849 name with spacesZ 2850 EOF 2851 ' 2852 2853 test_expect_success 'complete tree filename with metacharacters' ' 2854 echo content >"name with \${meta}" && 2855 git add "name with \${meta}" && 2856 git commit -m meta && 2857 test_completion "git show HEAD:nam" <<-\EOF 2858 name with ${meta}Z 2859 name with spacesZ 2860 EOF 2861 ' 2862 2863 test_expect_success 'symbolic-ref completes builtin options' ' 2864 test_completion "git symbolic-ref --d" <<-\EOF 2865 --delete Z 2866 EOF 2867 ' 2868 2869 test_expect_success 'symbolic-ref completes short ref names' ' 2870 test_completion "git symbolic-ref foo m" <<-\EOF 2871 main Z 2872 mybranch Z 2873 mytag Z 2874 EOF 2875 ' 2876 2877 test_expect_success 'symbolic-ref completes full ref names' ' 2878 test_completion "git symbolic-ref foo refs/" <<-\EOF 2879 refs/heads/main Z 2880 refs/heads/mybranch Z 2881 refs/tags/mytag Z 2882 refs/tags/A Z 2883 EOF 2884 ' 2885 2886 test_expect_success PERL 'send-email' ' 2887 test_completion "git send-email --cov" <<-\EOF && 2888 --cover-from-description=Z 2889 --cover-letter Z 2890 EOF 2891 test_completion "git send-email --val" <<-\EOF && 2892 --validate Z 2893 EOF 2894 test_completion "git send-email ma" "main " 2895 ' 2896 2897 test_expect_success 'complete files' ' 2898 git init tmp && cd tmp && 2899 test_when_finished "cd .. && rm -rf tmp" && 2900 2901 echo "expected" > .gitignore && 2902 echo "out" >> .gitignore && 2903 echo "out_sorted" >> .gitignore && 2904 2905 git add .gitignore && 2906 test_completion "git commit " ".gitignore" && 2907 2908 git commit -m ignore && 2909 2910 touch new && 2911 test_completion "git add " "new" && 2912 2913 git add new && 2914 git commit -a -m new && 2915 test_completion "git add " "" && 2916 2917 git mv new modified && 2918 echo modify > modified && 2919 test_completion "git add " "modified" && 2920 2921 mkdir -p some/deep && 2922 touch some/deep/path && 2923 test_completion "git add some/" "some/deep" && 2924 git clean -f some && 2925 2926 touch untracked && 2927 2928 : TODO .gitignore should not be here && 2929 test_completion "git rm " <<-\EOF && 2930 .gitignore 2931 modified 2932 EOF 2933 2934 test_completion "git clean " "untracked" && 2935 2936 : TODO .gitignore should not be here && 2937 test_completion "git mv " <<-\EOF && 2938 .gitignore 2939 modified 2940 EOF 2941 2942 mkdir dir && 2943 touch dir/file-in-dir && 2944 git add dir/file-in-dir && 2945 git commit -m dir && 2946 2947 mkdir untracked-dir && 2948 2949 : TODO .gitignore should not be here && 2950 test_completion "git mv modified " <<-\EOF && 2951 .gitignore 2952 dir 2953 modified 2954 untracked 2955 untracked-dir 2956 EOF 2957 2958 test_completion "git commit " "modified" && 2959 2960 : TODO .gitignore should not be here && 2961 test_completion "git ls-files " <<-\EOF && 2962 .gitignore 2963 dir 2964 modified 2965 EOF 2966 2967 touch momified && 2968 test_completion "git add mom" "momified" 2969 ' 2970 2971 test_expect_success "simple alias" ' 2972 test_config alias.co checkout && 2973 test_completion "git co m" <<-\EOF 2974 main Z 2975 mybranch Z 2976 mytag Z 2977 EOF 2978 ' 2979 2980 test_expect_success "recursive alias" ' 2981 test_config alias.co checkout && 2982 test_config alias.cod "co --detached" && 2983 test_completion "git cod m" <<-\EOF 2984 main Z 2985 mybranch Z 2986 mytag Z 2987 EOF 2988 ' 2989 2990 test_expect_success "completion uses completion for alias: !sh -c 'git ...'" ' 2991 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && 2992 test_completion "git co m" <<-\EOF 2993 main Z 2994 mybranch Z 2995 mytag Z 2996 EOF 2997 ' 2998 2999 test_expect_success 'completion uses completion for alias: !f () { VAR=val git ... }' ' 3000 test_config alias.co "!f () { VAR=val git checkout ... ; } f" && 3001 test_completion "git co m" <<-\EOF 3002 main Z 3003 mybranch Z 3004 mytag Z 3005 EOF 3006 ' 3007 3008 test_expect_success 'completion used completion for alias: !f() { : git ; ... }' ' 3009 test_config alias.co "!f() { : git checkout ; if ... } f" && 3010 test_completion "git co m" <<-\EOF 3011 main Z 3012 mybranch Z 3013 mytag Z 3014 EOF 3015 ' 3016 3017 test_expect_success 'completion used completion for alias: !f() { : ; ... }' ' 3018 test_config alias.co "!f() { : checkout ; if ... } f" && 3019 test_completion "git co m" <<-\EOF 3020 main Z 3021 mybranch Z 3022 mytag Z 3023 EOF 3024 ' 3025 3026 test_expect_success 'completion used completion for alias: !f() { : ; ... }' ' 3027 test_config alias.co "!f() { : checkout; if ... } f" && 3028 test_completion "git co m" <<-\EOF 3029 main Z 3030 mybranch Z 3031 mytag Z 3032 EOF 3033 ' 3034 3035 test_expect_success 'completion without explicit _git_xxx function' ' 3036 test_completion "git version --" <<-\EOF 3037 --build-options Z 3038 --no-build-options Z 3039 EOF 3040 ' 3041 3042 test_expect_failure 'complete with tilde expansion' ' 3043 git init tmp && cd tmp && 3044 test_when_finished "cd .. && rm -rf tmp" && 3045 3046 touch ~/tmp/file && 3047 3048 test_completion "git add ~/tmp/" "~/tmp/file" 3049 ' 3050 3051 test_expect_success 'setup other remote for remote reference completion' ' 3052 git remote add other otherrepo && 3053 git fetch other 3054 ' 3055 3056 for flag in -d --delete 3057 do 3058 test_expect_success "__git_complete_remote_or_refspec - push $flag other" ' 3059 sed -e "s/Z$//" >expected <<-EOF && 3060 main-in-other Z 3061 EOF 3062 ( 3063 words=(git push '$flag' other ma) && 3064 cword=${#words[@]} cur=${words[cword-1]} && 3065 __git_cmd_idx=1 && 3066 __git_complete_remote_or_refspec && 3067 print_comp 3068 ) && 3069 test_cmp expected out 3070 ' 3071 3072 test_expect_failure "__git_complete_remote_or_refspec - push other $flag" ' 3073 sed -e "s/Z$//" >expected <<-EOF && 3074 main-in-other Z 3075 EOF 3076 ( 3077 words=(git push other '$flag' ma) && 3078 cword=${#words[@]} cur=${words[cword-1]} && 3079 __git_cmd_idx=1 && 3080 __git_complete_remote_or_refspec && 3081 print_comp 3082 ) && 3083 test_cmp expected out 3084 ' 3085 done 3086 3087 test_expect_success 'git config subcommand' ' 3088 test_completion "git config " <<-\EOF 3089 edit Z 3090 get Z 3091 list Z 3092 remove-section Z 3093 rename-section Z 3094 set Z 3095 unset Z 3096 EOF 3097 ' 3098 3099 test_expect_success 'git config subcommand options' ' 3100 test_completion "git config get --show-" <<-\EOF 3101 --show-names Z 3102 --show-origin Z 3103 --show-scope Z 3104 EOF 3105 ' 3106 3107 test_expect_success 'git config get' ' 3108 test_when_finished "rm -f cfgfile" && 3109 git config set --file cfgfile foo.bar baz && 3110 test_completion "git config get --file cfgfile foo." <<-\EOF 3111 foo.bar Z 3112 EOF 3113 ' 3114 3115 test_expect_success 'git config set - section' ' 3116 test_completion "git config set br" <<-\EOF 3117 branch.Z 3118 browser.Z 3119 EOF 3120 ' 3121 3122 test_expect_success 'git config set - section include, includeIf' ' 3123 test_completion "git config set inclu" <<-\EOF 3124 include.Z 3125 includeIf.Z 3126 EOF 3127 ' 3128 3129 test_expect_success 'git config set - variable name' ' 3130 test_completion "git config set log.d" <<-\EOF 3131 log.date Z 3132 log.decorate Z 3133 log.diffMerges Z 3134 EOF 3135 ' 3136 3137 test_expect_success 'git config set - variable name include' ' 3138 test_completion "git config set include.p" <<-\EOF 3139 include.path Z 3140 EOF 3141 ' 3142 3143 test_expect_success 'setup for git config submodule tests' ' 3144 test_create_repo sub && 3145 test_commit -C sub initial && 3146 git submodule add ./sub 3147 ' 3148 3149 test_expect_success 'git config set - variable name - submodule and __git_compute_first_level_config_vars_for_section' ' 3150 test_completion "git config set submodule." <<-\EOF 3151 submodule.active Z 3152 submodule.alternateErrorStrategy Z 3153 submodule.alternateLocation Z 3154 submodule.fetchJobs Z 3155 submodule.propagateBranches Z 3156 submodule.recurse Z 3157 submodule.sub.Z 3158 EOF 3159 ' 3160 3161 test_expect_success 'git config set - variable name - __git_compute_second_level_config_vars_for_section' ' 3162 test_completion "git config set submodule.sub." <<-\EOF 3163 submodule.sub.url Z 3164 submodule.sub.update Z 3165 submodule.sub.branch Z 3166 submodule.sub.fetchRecurseSubmodules Z 3167 submodule.sub.ignore Z 3168 submodule.sub.active Z 3169 submodule.sub.gitdir Z 3170 EOF 3171 ' 3172 3173 test_expect_success 'git config set - value' ' 3174 test_completion "git config set color.pager " <<-\EOF 3175 false Z 3176 true Z 3177 EOF 3178 ' 3179 3180 test_expect_success 'git -c - section' ' 3181 test_completion "git -c br" <<-\EOF 3182 branch.Z 3183 browser.Z 3184 EOF 3185 ' 3186 3187 test_expect_success 'git -c - variable name' ' 3188 test_completion "git -c log.d" <<-\EOF 3189 log.date=Z 3190 log.decorate=Z 3191 log.diffMerges=Z 3192 EOF 3193 ' 3194 3195 test_expect_success 'git -c - value' ' 3196 test_completion "git -c color.pager=" <<-\EOF 3197 false Z 3198 true Z 3199 EOF 3200 ' 3201 3202 test_expect_success 'git clone --config= - section' ' 3203 test_completion "git clone --config=br" <<-\EOF 3204 branch.Z 3205 browser.Z 3206 EOF 3207 ' 3208 3209 test_expect_success 'git clone --config= - variable name' ' 3210 test_completion "git clone --config=log.d" <<-\EOF 3211 log.date=Z 3212 log.decorate=Z 3213 log.diffMerges=Z 3214 EOF 3215 ' 3216 3217 test_expect_success 'git clone --config= - value' ' 3218 test_completion "git clone --config=color.pager=" <<-\EOF 3219 false Z 3220 true Z 3221 EOF 3222 ' 3223 3224 test_expect_success 'git history subcommands' ' 3225 test_completion "git history " <<-\EOF && 3226 drop Z 3227 fixup Z 3228 reword Z 3229 split Z 3230 squash Z 3231 EOF 3232 test_completion "git history --" "" 3233 ' 3234 3235 test_expect_success 'git history subcommand options' ' 3236 test_completion "git history split main --" <<-\EOF && 3237 --update-refs=Z 3238 --dry-run Z 3239 --gpg-sign Z 3240 --no-... Z 3241 --no-dry-run Z 3242 EOF 3243 test_completion "git history fixup --upd" "--update-refs=" && 3244 test_completion "git history fixup --ree" "--reedit-message " && 3245 test_completion "git history split --upd" "--update-refs=" && 3246 test_completion "git history split main --dry" "--dry-run " && 3247 test_completion "git history reword main -- --d" "" && 3248 test_completion "git history fixup --empty=ke" "keep " && 3249 test_completion "git history fixup --empty=drop" "drop " && 3250 test_completion "git history drop --empty=ab" "abort " && 3251 test_completion "git history reword --empty=ke" "" && 3252 test_completion "git history fixup --update-refs=branch" "branches " && 3253 test_completion "git history split --update-refs=he" "head " && 3254 test_completion "git history reword main -- --update-refs=he" "" 3255 ' 3256 3257 test_expect_success 'git history revisions' ' 3258 test_completion "git history split ma" "main " && 3259 test_completion "git history split --update-refs=head ma" "main " && 3260 test_completion "git history fixup --empty=drop ma" "main " && 3261 test_completion "git history reword main m" "" 3262 ' 3263 3264 test_expect_success 'git history split pathspecs' ' 3265 test_completion "git history split main -- --update-refs=h" "" && 3266 test_completion "git history split main -- --update-refs h" "" && 3267 test_completion "git history split --dry-run main file" <<-\EOF && 3268 file1Z 3269 file2Z 3270 EOF 3271 test_completion "git history split main -- file" <<-\EOF 3272 file1Z 3273 file2Z 3274 EOF 3275 ' 3276 3277 test_expect_success 'git reflog show' ' 3278 test_when_finished "git checkout - && git branch -d shown" && 3279 git checkout -b shown && 3280 test_completion "git reflog sho" <<-\EOF && 3281 show Z 3282 shown Z 3283 EOF 3284 test_completion "git reflog show sho" "shown " && 3285 test_completion "git reflog shown sho" "shown " && 3286 test_completion "git reflog --unt" "--until=" && 3287 test_completion "git reflog show --unt" "--until=" && 3288 test_completion "git reflog shown --unt" "--until=" 3289 ' 3290 3291 test_expect_success 'options with value' ' 3292 test_completion "git merge -X diff-algorithm=" <<-\EOF 3293 3294 EOF 3295 ' 3296 3297 test_expect_success 'sourcing the completion script clears cached commands' ' 3298 ( 3299 __git_compute_all_commands && 3300 test -n "$__git_all_commands" && 3301 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && 3302 test -z "$__git_all_commands" 3303 ) 3304 ' 3305 3306 test_expect_success 'sourcing the completion script clears cached merge strategies' ' 3307 ( 3308 __git_compute_merge_strategies && 3309 test -n "$__git_merge_strategies" && 3310 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && 3311 test -z "$__git_merge_strategies" 3312 ) 3313 ' 3314 3315 test_expect_success 'sourcing the completion script clears cached --options' ' 3316 ( 3317 __gitcomp_builtin checkout && 3318 test -n "$__gitcomp_builtin_checkout" && 3319 __gitcomp_builtin notes_edit && 3320 test -n "$__gitcomp_builtin_notes_edit" && 3321 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && 3322 test -z "$__gitcomp_builtin_checkout" && 3323 test -z "$__gitcomp_builtin_notes_edit" 3324 ) 3325 ' 3326 3327 test_expect_success 'option aliases are not shown by default' ' 3328 test_completion "git clone --recurs" "--recurse-submodules " 3329 ' 3330 3331 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' ' 3332 ( 3333 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && 3334 GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL && 3335 test_completion "git clone --recurs" <<-\EOF 3336 --recurse-submodules Z 3337 --recursive Z 3338 EOF 3339 ) 3340 ' 3341 3342 test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' ' 3343 ( 3344 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && 3345 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST && 3346 3347 # Just mainporcelain, not plumbing commands 3348 run_completion "git c" && 3349 test_grep checkout out && 3350 test_grep ! cat-file out 3351 ) 3352 ' 3353 3354 test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' ' 3355 ( 3356 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && 3357 GIT_COMPLETION_SHOW_ALL_COMMANDS=1 && 3358 export GIT_COMPLETION_SHOW_ALL_COMMANDS && 3359 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST && 3360 3361 # Both mainporcelain and plumbing commands 3362 run_completion "git c" && 3363 test_grep checkout out && 3364 test_grep cat-file out && 3365 3366 # Check "gitk", a "main" command, but not a built-in + more plumbing 3367 run_completion "git g" && 3368 test_grep gitk out && 3369 test_grep get-tar-commit-id out 3370 ) 3371 ' 3372 3373 test_expect_success '__git_complete' ' 3374 unset -f __git_wrap__git_main && 3375 3376 __git_complete foo __git_main && 3377 __git_have_func __git_wrap__git_main && 3378 unset -f __git_wrap__git_main && 3379 3380 __git_complete gf _git_fetch && 3381 __git_have_func __git_wrap_git_fetch && 3382 3383 __git_complete foo git && 3384 __git_have_func __git_wrap__git_main && 3385 unset -f __git_wrap__git_main && 3386 3387 __git_complete gd git_diff && 3388 __git_have_func __git_wrap_git_diff && 3389 3390 test_must_fail __git_complete ga missing 3391 ' 3392 3393 test_expect_success '__git_pseudoref_exists' ' 3394 test_when_finished "rm -rf repo" && 3395 git init repo && 3396 ( 3397 cd repo && 3398 sane_unset __git_repo_path && 3399 3400 # HEAD should exist, even if it points to an unborn branch. 3401 __git_pseudoref_exists HEAD >output 2>&1 && 3402 test_must_be_empty output && 3403 3404 # HEAD points to an existing branch, so it should exist. 3405 test_commit A && 3406 __git_pseudoref_exists HEAD >output 2>&1 && 3407 test_must_be_empty output && 3408 3409 # CHERRY_PICK_HEAD does not exist, so the existence check should fail. 3410 ! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 && 3411 test_must_be_empty output && 3412 3413 # CHERRY_PICK_HEAD points to a commit, so it should exist. 3414 git update-ref CHERRY_PICK_HEAD A && 3415 __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 && 3416 test_must_be_empty output 3417 ) 3418 ' 3419 3420 test_done