diff options
Diffstat (limited to 't/t9902-completion.sh')
-rwxr-xr-x | t/t9902-completion.sh | 812 |
1 files changed, 739 insertions, 73 deletions
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 54f8ce18cb..5decc3b269 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1,10 +1,13 @@ #!/bin/sh # -# Copyright (c) 2012 Felipe Contreras +# Copyright (c) 2012-2020 Felipe Contreras # test_description='test bash completion' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./lib-bash.sh complete () @@ -136,7 +139,7 @@ fi test_expect_success 'setup for __git_find_repo_path/__gitdir tests' ' mkdir -p subdir/subsubdir && mkdir -p non-repo && - git init otherrepo + git init -b main otherrepo ' test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' ' @@ -378,7 +381,7 @@ test_expect_success '__gitdir - finds repo' ' ' -test_expect_success '__gitdir - returns error when cant find repo' ' +test_expect_success '__gitdir - returns error when cannot find repo' ' ( __git_dir="non-existing" && test_must_fail __gitdir >"$actual" @@ -494,7 +497,7 @@ test_expect_success '__gitcomp - prefix' ' ' test_expect_success '__gitcomp - suffix' ' - test_gitcomp "branch.me" "master maint next pu" "branch." \ + test_gitcomp "branch.me" "master maint next seen" "branch." \ "ma" "." <<-\EOF branch.master.Z branch.maint.Z @@ -537,42 +540,51 @@ test_expect_success '__gitcomp - expand/narrow all negative options' ' EOF ' +test_expect_success '__gitcomp - equal skip' ' + test_gitcomp "--option=" "--option=" <<-\EOF && + + EOF + test_gitcomp "option=" "option=" <<-\EOF + + EOF +' + test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' __gitcomp "$invalid_variable_name" ' read -r -d "" refs <<-\EOF +main maint -master next -pu +seen EOF test_expect_success '__gitcomp_nl - trailing space' ' test_gitcomp_nl "m" "$refs" <<-EOF + main Z maint Z - master Z EOF ' test_expect_success '__gitcomp_nl - prefix' ' test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF + --fixup=main Z --fixup=maint Z - --fixup=master Z EOF ' test_expect_success '__gitcomp_nl - suffix' ' test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF + branch.main.Z branch.maint.Z - branch.master.Z EOF ' test_expect_success '__gitcomp_nl - no suffix' ' test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF + mainZ maintZ - masterZ EOF ' @@ -614,12 +626,13 @@ test_expect_success '__git_is_configured_remote' ' test_expect_success 'setup for ref completion' ' git commit --allow-empty -m initial && + git branch -M main && git branch matching-branch && git tag matching-tag && ( cd otherrepo && git commit --allow-empty -m initial && - git branch -m master master-in-other && + git branch -m main main-in-other && git branch branch-in-other && git tag tag-in-other ) && @@ -632,10 +645,10 @@ test_expect_success 'setup for ref completion' ' test_expect_success '__git_refs - simple' ' cat >expected <<-EOF && HEAD - master + main matching-branch other/branch-in-other - other/master-in-other + other/main-in-other matching-tag EOF ( @@ -647,10 +660,10 @@ test_expect_success '__git_refs - simple' ' test_expect_success '__git_refs - full refs' ' cat >expected <<-EOF && - refs/heads/master + refs/heads/main refs/heads/matching-branch refs/remotes/other/branch-in-other - refs/remotes/other/master-in-other + refs/remotes/other/main-in-other refs/tags/matching-tag EOF ( @@ -664,7 +677,7 @@ test_expect_success '__git_refs - repo given on the command line' ' cat >expected <<-EOF && HEAD branch-in-other - master-in-other + main-in-other tag-in-other EOF ( @@ -679,7 +692,7 @@ test_expect_success '__git_refs - remote on local file system' ' cat >expected <<-EOF && HEAD branch-in-other - master-in-other + main-in-other tag-in-other EOF ( @@ -692,7 +705,7 @@ test_expect_success '__git_refs - remote on local file system' ' test_expect_success '__git_refs - remote on local file system - full refs' ' cat >expected <<-EOF && refs/heads/branch-in-other - refs/heads/master-in-other + refs/heads/main-in-other refs/tags/tag-in-other EOF ( @@ -706,7 +719,7 @@ test_expect_success '__git_refs - configured remote' ' cat >expected <<-EOF && HEAD branch-in-other - master-in-other + main-in-other EOF ( cur= && @@ -719,7 +732,7 @@ test_expect_success '__git_refs - configured remote - full refs' ' cat >expected <<-EOF && HEAD refs/heads/branch-in-other - refs/heads/master-in-other + refs/heads/main-in-other refs/tags/tag-in-other EOF ( @@ -733,7 +746,7 @@ test_expect_success '__git_refs - configured remote - repo given on the command cat >expected <<-EOF && HEAD branch-in-other - master-in-other + main-in-other EOF ( cd thirdrepo && @@ -748,7 +761,7 @@ test_expect_success '__git_refs - configured remote - full refs - repo given on cat >expected <<-EOF && HEAD refs/heads/branch-in-other - refs/heads/master-in-other + refs/heads/main-in-other refs/tags/tag-in-other EOF ( @@ -764,7 +777,7 @@ test_expect_success '__git_refs - configured remote - remote name matches a dire cat >expected <<-EOF && HEAD branch-in-other - master-in-other + main-in-other EOF mkdir other && test_when_finished "rm -rf other" && @@ -779,7 +792,7 @@ test_expect_success '__git_refs - URL remote' ' cat >expected <<-EOF && HEAD branch-in-other - master-in-other + main-in-other tag-in-other EOF ( @@ -793,7 +806,7 @@ test_expect_success '__git_refs - URL remote - full refs' ' cat >expected <<-EOF && HEAD refs/heads/branch-in-other - refs/heads/master-in-other + refs/heads/main-in-other refs/tags/tag-in-other EOF ( @@ -849,23 +862,23 @@ test_expect_success '__git_refs - not in a git repository' ' test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' ' cat >expected <<-EOF && HEAD - master + main matching-branch other/ambiguous other/branch-in-other - other/master-in-other + other/main-in-other remote/ambiguous remote/branch-in-remote matching-tag branch-in-other branch-in-remote - master-in-other + main-in-other EOF for remote_ref in refs/remotes/other/ambiguous \ refs/remotes/remote/ambiguous \ refs/remotes/remote/branch-in-remote do - git update-ref $remote_ref master && + git update-ref $remote_ref main && test_when_finished "git update-ref -d $remote_ref" done && ( @@ -878,10 +891,10 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer test_expect_success '__git_refs - after --opt=' ' cat >expected <<-EOF && HEAD - master + main matching-branch other/branch-in-other - other/master-in-other + other/main-in-other matching-tag EOF ( @@ -893,10 +906,10 @@ test_expect_success '__git_refs - after --opt=' ' test_expect_success '__git_refs - after --opt= - full refs' ' cat >expected <<-EOF && - refs/heads/master + refs/heads/main refs/heads/matching-branch refs/remotes/other/branch-in-other - refs/remotes/other/master-in-other + refs/remotes/other/main-in-other refs/tags/matching-tag EOF ( @@ -906,13 +919,13 @@ test_expect_success '__git_refs - after --opt= - full refs' ' test_cmp expected "$actual" ' -test_expect_success '__git refs - exluding refs' ' +test_expect_success '__git refs - excluding refs' ' cat >expected <<-EOF && ^HEAD - ^master + ^main ^matching-branch ^other/branch-in-other - ^other/master-in-other + ^other/main-in-other ^matching-tag EOF ( @@ -922,12 +935,12 @@ test_expect_success '__git refs - exluding refs' ' test_cmp expected "$actual" ' -test_expect_success '__git refs - exluding full refs' ' +test_expect_success '__git refs - excluding full refs' ' cat >expected <<-EOF && - ^refs/heads/master + ^refs/heads/main ^refs/heads/matching-branch ^refs/remotes/other/branch-in-other - ^refs/remotes/other/master-in-other + ^refs/remotes/other/main-in-other ^refs/tags/matching-tag EOF ( @@ -945,20 +958,20 @@ test_expect_success 'setup for filtering matching refs' ' rm -f .git/FETCH_HEAD ' -test_expect_success '__git_refs - dont filter refs unless told so' ' +test_expect_success '__git_refs - do not filter refs unless told so' ' cat >expected <<-EOF && HEAD - master + main matching-branch matching/branch other/branch-in-other - other/master-in-other + other/main-in-other other/matching/branch-in-other matching-tag matching/tag EOF ( - cur=master && + cur=main && __git_refs >"$actual" ) && test_cmp expected "$actual" @@ -992,7 +1005,7 @@ test_expect_success '__git_refs - only matching refs - full refs' ' test_expect_success '__git_refs - only matching refs - remote on local file system' ' cat >expected <<-EOF && - master-in-other + main-in-other matching/branch-in-other EOF ( @@ -1004,7 +1017,7 @@ test_expect_success '__git_refs - only matching refs - remote on local file syst test_expect_success '__git_refs - only matching refs - configured remote' ' cat >expected <<-EOF && - master-in-other + main-in-other matching/branch-in-other EOF ( @@ -1016,7 +1029,7 @@ test_expect_success '__git_refs - only matching refs - configured remote' ' test_expect_success '__git_refs - only matching refs - remote - full refs' ' cat >expected <<-EOF && - refs/heads/master-in-other + refs/heads/main-in-other refs/heads/matching/branch-in-other EOF ( @@ -1038,7 +1051,7 @@ test_expect_success '__git_refs - only matching refs - checkout DWIMery' ' refs/remotes/remote/ambiguous \ refs/remotes/remote/branch-in-remote do - git update-ref $remote_ref master && + git update-ref $remote_ref main && test_when_finished "git update-ref -d $remote_ref" done && ( @@ -1057,11 +1070,11 @@ test_expect_success 'teardown after filtering matching refs' ' test_expect_success '__git_refs - for-each-ref format specifiers in prefix' ' cat >expected <<-EOF && - evil-%%-%42-%(refname)..master + evil-%%-%42-%(refname)..main EOF ( - cur="evil-%%-%42-%(refname)..mas" && - __git_refs "" "" "evil-%%-%42-%(refname).." mas >"$actual" + cur="evil-%%-%42-%(refname)..mai" && + __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual" ) && test_cmp expected "$actual" ' @@ -1069,10 +1082,10 @@ test_expect_success '__git_refs - for-each-ref format specifiers in prefix' ' test_expect_success '__git_complete_refs - simple' ' sed -e "s/Z$//" >expected <<-EOF && HEAD Z - master Z + main Z matching-branch Z other/branch-in-other Z - other/master-in-other Z + other/main-in-other Z matching-tag Z EOF ( @@ -1100,7 +1113,7 @@ test_expect_success '__git_complete_refs - remote' ' sed -e "s/Z$//" >expected <<-EOF && HEAD Z branch-in-other Z - master-in-other Z + main-in-other Z EOF ( cur= && @@ -1113,13 +1126,13 @@ test_expect_success '__git_complete_refs - remote' ' test_expect_success '__git_complete_refs - track' ' sed -e "s/Z$//" >expected <<-EOF && HEAD Z - master Z + main Z matching-branch Z other/branch-in-other Z - other/master-in-other Z + other/main-in-other Z matching-tag Z branch-in-other Z - master-in-other Z + main-in-other Z EOF ( cur= && @@ -1158,10 +1171,10 @@ test_expect_success '__git_complete_refs - prefix' ' test_expect_success '__git_complete_refs - suffix' ' cat >expected <<-EOF && HEAD. - master. + main. matching-branch. other/branch-in-other. - other/master-in-other. + other/main-in-other. matching-tag. EOF ( @@ -1176,7 +1189,7 @@ test_expect_success '__git_complete_fetch_refspecs - simple' ' sed -e "s/Z$//" >expected <<-EOF && HEAD:HEAD Z branch-in-other:branch-in-other Z - master-in-other:master-in-other Z + main-in-other:main-in-other Z EOF ( cur= && @@ -1202,7 +1215,7 @@ test_expect_success '__git_complete_fetch_refspecs - prefix' ' sed -e "s/Z$//" >expected <<-EOF && +HEAD:HEAD Z +branch-in-other:branch-in-other Z - +master-in-other:master-in-other Z + +main-in-other:main-in-other Z EOF ( cur="+" && @@ -1215,7 +1228,7 @@ test_expect_success '__git_complete_fetch_refspecs - prefix' ' test_expect_success '__git_complete_fetch_refspecs - fully qualified' ' sed -e "s/Z$//" >expected <<-EOF && refs/heads/branch-in-other:refs/heads/branch-in-other Z - refs/heads/master-in-other:refs/heads/master-in-other Z + refs/heads/main-in-other:refs/heads/main-in-other Z refs/tags/tag-in-other:refs/tags/tag-in-other Z EOF ( @@ -1229,7 +1242,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified' ' test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' sed -e "s/Z$//" >expected <<-EOF && +refs/heads/branch-in-other:refs/heads/branch-in-other Z - +refs/heads/master-in-other:refs/heads/master-in-other Z + +refs/heads/main-in-other:refs/heads/main-in-other Z +refs/tags/tag-in-other:refs/tags/tag-in-other Z EOF ( @@ -1240,6 +1253,513 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' test_cmp expected out ' +test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' ' + test_completion "git switch " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' ' + test_completion "git checkout " <<-\EOF + HEAD Z + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with --no-guess, complete only local branches' ' + test_completion "git switch --no-guess " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' ' + test_completion "git switch --no-guess --guess " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' ' + test_completion "git switch --guess --no-guess " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF + HEAD Z + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with --no-guess, only completes refs' ' + test_completion "git checkout --no-guess " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' + test_completion "git checkout --no-guess --guess " <<-\EOF + HEAD Z + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' ' + test_completion "git checkout --guess --no-guess " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with checkout.guess = false, only completes refs' ' + test_config checkout.guess false && + test_completion "git checkout " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' ' + test_config checkout.guess true && + test_completion "git checkout " <<-\EOF + HEAD Z + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' ' + test_config checkout.guess false && + test_completion "git checkout --guess " <<-\EOF + HEAD Z + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' ' + test_config checkout.guess true && + test_completion "git checkout --no-guess " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with --detach, complete all references' ' + test_completion "git switch --detach " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with --detach, complete only references' ' + test_completion "git checkout --detach " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with -d, complete all references' ' + test_completion "git switch -d " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with -d, complete only references' ' + test_completion "git checkout -d " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with --track, complete only remote branches' ' + test_completion "git switch --track " <<-\EOF + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with --track, complete only remote branches' ' + test_completion "git checkout --track " <<-\EOF + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with --no-track, complete only local branch names' ' + test_completion "git switch --no-track " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - with --no-track, complete only local references' ' + test_completion "git checkout --no-track " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with -c, complete all references' ' + test_completion "git switch -c new-branch " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with -C, complete all references' ' + test_completion "git switch -C new-branch " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with -c and --track, complete all references' ' + test_completion "git switch -c new-branch --track " <<-EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with -C and --track, complete all references' ' + test_completion "git switch -C new-branch --track " <<-EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with -c and --no-track, complete all references' ' + test_completion "git switch -c new-branch --no-track " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - with -C and --no-track, complete all references' ' + test_completion "git switch -C new-branch --no-track " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with -b, complete all references' ' + test_completion "git checkout -b new-branch " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with -B, complete all references' ' + test_completion "git checkout -B new-branch " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with -b and --track, complete all references' ' + test_completion "git checkout -b new-branch --track " <<-EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with -B and --track, complete all references' ' + test_completion "git checkout -B new-branch --track " <<-EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with -b and --no-track, complete all references' ' + test_completion "git checkout -b new-branch --no-track " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git checkout - with -B and --no-track, complete all references' ' + test_completion "git checkout -B new-branch --no-track " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + +test_expect_success 'git switch - for -c, complete local branches and unique remote branches' ' + test_completion "git switch -c " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -C, complete local branches and unique remote branches' ' + test_completion "git switch -C " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -c with --no-guess, complete local branches only' ' + test_completion "git switch --no-guess -c " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -C with --no-guess, complete local branches only' ' + test_completion "git switch --no-guess -C " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -c with --no-track, complete local branches only' ' + test_completion "git switch --no-track -c " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -C with --no-track, complete local branches only' ' + test_completion "git switch --no-track -C " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' ' + test_completion "git checkout -b " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' ' + test_completion "git checkout -B " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' ' + test_completion "git checkout --no-guess -b " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' ' + test_completion "git checkout --no-guess -B " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -b with --no-track, complete local branches only' ' + test_completion "git checkout --no-track -b " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -B with --no-track, complete local branches only' ' + test_completion "git checkout --no-track -B " <<-\EOF + main Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' ' + test_completion "git switch --orphan " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - --orphan with branch already provided completes nothing else' ' + test_completion "git switch --orphan main " <<-\EOF + + EOF +' + +test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' ' + test_completion "git checkout --orphan " <<-\EOF + branch-in-other Z + main Z + main-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' ' + test_completion "git checkout --orphan main " <<-\EOF + HEAD Z + main Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/main-in-other Z + EOF +' + test_expect_success 'teardown after ref completion' ' git branch -d matching-branch && git tag -d matching-tag && @@ -1257,7 +1777,7 @@ test_path_completion () # In the following tests calling this function we only # care about how __git_complete_index_file() deals with # unusual characters in path names. By requesting only - # untracked files we dont have to bother adding any + # untracked files we do not have to bother adding any # paths to the index in those tests. __git_complete_index_file --others && print_comp @@ -1363,6 +1883,80 @@ test_expect_success 'teardown after path completion tests' ' BS\\dir '$'separators\034in\035dir'' ' +test_expect_success '__git_find_on_cmdline - single match' ' + echo list >expect && + ( + words=(git command --opt list) && + cword=${#words[@]} && + __git_cmd_idx=1 && + __git_find_on_cmdline "add list remove" >actual + ) && + test_cmp expect actual +' + +test_expect_success '__git_find_on_cmdline - multiple matches' ' + echo remove >expect && + ( + words=(git command -o --opt remove list add) && + cword=${#words[@]} && + __git_cmd_idx=1 && + __git_find_on_cmdline "add list remove" >actual + ) && + test_cmp expect actual +' + +test_expect_success '__git_find_on_cmdline - no match' ' + ( + words=(git command --opt branch) && + cword=${#words[@]} && + __git_cmd_idx=1 && + __git_find_on_cmdline "add list remove" >actual + ) && + test_must_be_empty actual +' + +test_expect_success '__git_find_on_cmdline - single match with index' ' + echo "3 list" >expect && + ( + words=(git command --opt list) && + cword=${#words[@]} && + __git_cmd_idx=1 && + __git_find_on_cmdline --show-idx "add list remove" >actual + ) && + test_cmp expect actual +' + +test_expect_success '__git_find_on_cmdline - multiple matches with index' ' + echo "4 remove" >expect && + ( + words=(git command -o --opt remove list add) && + cword=${#words[@]} && + __git_cmd_idx=1 && + __git_find_on_cmdline --show-idx "add list remove" >actual + ) && + test_cmp expect actual +' + +test_expect_success '__git_find_on_cmdline - no match with index' ' + ( + words=(git command --opt branch) && + cword=${#words[@]} && + __git_cmd_idx=1 && + __git_find_on_cmdline --show-idx "add list remove" >actual + ) && + test_must_be_empty actual +' + +test_expect_success '__git_find_on_cmdline - ignores matches before command with index' ' + echo "6 remove" >expect && + ( + words=(git -C remove command -o --opt remove list add) && + cword=${#words[@]} && + __git_cmd_idx=3 && + __git_find_on_cmdline --show-idx "add list remove" >actual + ) && + test_cmp expect actual +' test_expect_success '__git_get_config_variables' ' cat >expect <<-EOF && @@ -1438,6 +2032,8 @@ test_expect_success 'double dash "git checkout"' ' --no-guess Z --no-... Z --overlay Z + --pathspec-file-nul Z + --pathspec-from-file=Z EOF ' @@ -1501,7 +2097,7 @@ test_expect_success 'setup for integration tests' ' test_expect_success 'checkout completes ref names' ' test_completion "git checkout m" <<-\EOF - master Z + main Z mybranch Z mytag Z EOF @@ -1515,7 +2111,7 @@ test_expect_success 'git -C <path> checkout uses the right repo' ' test_expect_success 'show completes all refs' ' test_completion "git show m" <<-\EOF - master Z + main Z mybranch Z mytag Z EOF @@ -1548,8 +2144,11 @@ test_expect_success 'complete tree filename with metacharacters' ' ' test_expect_success PERL 'send-email' ' - test_completion "git send-email --cov" "--cover-letter " && - test_completion "git send-email ma" "master " + test_completion "git send-email --cov" <<-\EOF && + --cover-from-description=Z + --cover-letter Z + EOF + test_completion "git send-email ma" "main " ' test_expect_success 'complete files' ' @@ -1576,6 +2175,11 @@ test_expect_success 'complete files' ' echo modify > modified && test_completion "git add " "modified" && + mkdir -p some/deep && + touch some/deep/path && + test_completion "git add some/" "some/deep" && + git clean -f some && + touch untracked && : TODO .gitignore should not be here && @@ -1621,10 +2225,29 @@ test_expect_success 'complete files' ' test_completion "git add mom" "momified" ' +test_expect_success "simple alias" ' + test_config alias.co checkout && + test_completion "git co m" <<-\EOF + main Z + mybranch Z + mytag Z + EOF +' + +test_expect_success "recursive alias" ' + test_config alias.co checkout && + test_config alias.cod "co --detached" && + test_completion "git cod m" <<-\EOF + main Z + mybranch Z + mytag Z + EOF +' + test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && test_completion "git co m" <<-\EOF - master Z + main Z mybranch Z mytag Z EOF @@ -1633,7 +2256,7 @@ test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cm test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' test_config alias.co "!f () { VAR=val git checkout ... ; } f" && test_completion "git co m" <<-\EOF - master Z + main Z mybranch Z mytag Z EOF @@ -1642,7 +2265,7 @@ test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' test_config alias.co "!f() { : git checkout ; if ... } f" && test_completion "git co m" <<-\EOF - master Z + main Z mybranch Z mytag Z EOF @@ -1673,11 +2296,12 @@ for flag in -d --delete do test_expect_success "__git_complete_remote_or_refspec - push $flag other" ' sed -e "s/Z$//" >expected <<-EOF && - master-in-other Z + main-in-other Z EOF ( words=(git push '$flag' other ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && @@ -1686,11 +2310,12 @@ do test_expect_failure "__git_complete_remote_or_refspec - push other $flag" ' sed -e "s/Z$//" >expected <<-EOF && - master-in-other Z + main-in-other Z EOF ( words=(git push other '$flag' ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && @@ -1709,6 +2334,7 @@ test_expect_success 'git config - variable name' ' test_completion "git config log.d" <<-\EOF log.date Z log.decorate Z + log.diffMerges Z EOF ' @@ -1730,6 +2356,7 @@ test_expect_success 'git -c - variable name' ' test_completion "git -c log.d" <<-\EOF log.date=Z log.decorate=Z + log.diffMerges=Z EOF ' @@ -1751,6 +2378,7 @@ test_expect_success 'git clone --config= - variable name' ' test_completion "git clone --config=log.d" <<-\EOF log.date=Z log.decorate=Z + log.diffMerges=Z EOF ' @@ -1761,6 +2389,12 @@ test_expect_success 'git clone --config= - value' ' EOF ' +test_expect_success 'options with value' ' + test_completion "git merge -X diff-algorithm=" <<-\EOF + + EOF +' + test_expect_success 'sourcing the completion script clears cached commands' ' __git_compute_all_commands && verbose test -n "$__git_all_commands" && @@ -1769,7 +2403,6 @@ test_expect_success 'sourcing the completion script clears cached commands' ' ' test_expect_success 'sourcing the completion script clears cached merge strategies' ' - GIT_TEST_GETTEXT_POISON=false && __git_compute_merge_strategies && verbose test -n "$__git_merge_strategies" && . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && @@ -1786,4 +2419,37 @@ test_expect_success 'sourcing the completion script clears cached --options' ' verbose test -z "$__gitcomp_builtin_notes_edit" ' +test_expect_success 'option aliases are not shown by default' ' + test_completion "git clone --recurs" "--recurse-submodules " +' + +test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' ' + . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && + GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL && + test_completion "git clone --recurs" <<-\EOF + --recurse-submodules Z + --recursive Z + EOF +' + +test_expect_success '__git_complete' ' + unset -f __git_wrap__git_main && + + __git_complete foo __git_main && + __git_have_func __git_wrap__git_main && + unset -f __git_wrap__git_main && + + __git_complete gf _git_fetch && + __git_have_func __git_wrap_git_fetch && + + __git_complete foo git && + __git_have_func __git_wrap__git_main && + unset -f __git_wrap__git_main && + + __git_complete gd git_diff && + __git_have_func __git_wrap_git_diff && + + test_must_fail __git_complete ga missing +' + test_done |