{"thread":{"id":"53317","subject":"[PATCH 00/11] refactor git switch completion","startedAt":"2020-04-25T02:20:54Z","lastAt":"2020-05-01T21:53:47Z","messageCount":26,"participants":["Jacob Keller","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":11},"messages":[{"id":"396213","messageId":"20200425022045.1089291-1-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":null,"subject":"[PATCH 00/11] refactor git switch completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:33Z","receivedAt":"2020-04-25T02:20:54Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\ncompletion support for git switch is subpar for a number of cases. Most\nnotable is difference between these two completions:\n\n  $git switch <TAB>\n  Display all 784 possibilities? (y or n)\n  <list of all references and DWIM remotes>\n\n  $git switch --track<TAB>\n  jk-refactor-git-switch-completion master`\n\nIf --track is provided, tab completion becomes almost useless, because we\nwould expect to complete remote references, but instead can only complete\nlocal branches!\n\nThis series was motivated by a desire to fix the completion for the above\ntwo cases, but I noticed several other issues on the way, including some\nissues understanding what the current logic did.\n\nThis series aims to improve the completion support, and comes with many\nadditional test cases that should help highlight the buggy behavior and\nhopefully prevent future regressions.\n\nThe first few commits just add new test cases, most of which currently fail.\n\nFollowing this is a commit to change __git_complete_refs so that it uses\n\"--dwim\" instead of \"--track\", since this made reading _git_checkout() and\n_git_switch() difficult to read. \"--track\" was both used as the \"enable DWIM\nremote branch names\" and also the option name for --track.\n\nFollowing this are some patches to extract displaying DWIM remote branch\nnames from __git_refs() and refactoring __git_complete_refs to take a mode\nargument that switches between calling __git_heads, __git_refs, and a new\n__git_remotes.\n\nBy doing this, it becomes easier to do things like complete DWIM remote\nbranches in addition to just regular branches, rather than all references.\n\nWith this series applied, completion for git switch behaves more like the\nfollowing examples:\n\n  $git switch <TAB>\n  HEAD                                master         todo\n  jk-refactor-git-switch-completion   next\n  maint                               pu\n\n  $git switch --track <TAB>\n  origin/HEAD     origin/maint    origin/master   origin/next     origin/pu\n  origin/todo\n\nJacob Keller (11):\n  completion: add some simple test cases for git switch completion\n  completion: add test showing subpar git switch completion\n  completion: add test highlighting subpar git switch --track completion\n  completion: add tests showing lack of support for  git switch -c/-C\n  completion: remove completion for git switch --orphan\n  completion: rename --track option of __git_complete_refs\n  completion: extract function __git_dwim_remote_heads\n  completion: perform DWIM logic directly in __git_complete_refs\n  completion: fix completion for git switch with no options\n  completion: recognize -c/-C when completing for git switch\n  completion: complete remote branches for git switch --track\n\n contrib/completion/git-completion.bash | 146 +++++++++++++++++++------\n t/t9902-completion.sh                  | 103 +++++++++++++++++\n 2 files changed, 215 insertions(+), 34 deletions(-)\n\n-- \n2.25.2\n\n"},{"id":"396214","messageId":"20200425022045.1089291-2-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 01/11] completion: add some simple test cases for git switch completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:34Z","receivedAt":"2020-04-25T02:20:54Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nFuture work is going to refactor the completion support for git switch,\nso add some new test cases in order to help prevent regressions.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 25 +++++++++++++++++++++++++\n 1 file changed, 25 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 5505e5aa249e..03e8188f023d 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1240,6 +1240,31 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n \ttest_cmp expected out\n '\n \n+test_expect_success 'git switch - with --no-guess, complete only local branches' '\n+\ttest_completion \"git switch --no-guess \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+test_expect_success 'git switch - with --detach, complete all references' '\n+\ttest_completion \"git switch --detach \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git switch - with --no-track, complete only local branch names' '\n+\ttest_completion \"git switch --no-track \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n-- \n2.25.2\n\n"},{"id":"396215","messageId":"20200425022045.1089291-3-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 02/11] completion: add test showing subpar git switch completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:35Z","receivedAt":"2020-04-25T02:20:57Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nWith no options, git switch only allows switching branches or DWIM to\ncreate a local branch tracking a remote branch of the same name.\nHowever, tab completion will expand \"git switch <TAB>\" to any local\nreference, including pseudorefs like HEAD, or tags.\n\nAdd a test case which highlights this failure, which will be fixed in\na future refactoring of git switch completion support.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 03e8188f023d..af4661cbcc73 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1240,6 +1240,19 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n \ttest_cmp expected out\n '\n \n+# TODO: git switch by default should only include local branches and anything which\n+# would be understood by the DWIM logic. Currently it will complete most\n+# references including pseudorefs like HEAD and FETCH_HEAD, as well as tags.\n+# These should not be completed unless certain options have been enabled.\n+test_expect_failure 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n+\ttest_completion \"git switch \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n test_expect_success 'git switch - with --no-guess, complete only local branches' '\n \ttest_completion \"git switch --no-guess \" <<-\\EOF\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"396216","messageId":"20200425022045.1089291-4-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 03/11] completion: add test highlighting subpar git switch --track completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:36Z","receivedAt":"2020-04-25T02:20:57Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nIf git switch is called with --track, it will attempts to DWIM into\ncreating a local tracking branch that tracks the provided remote branch.\nIt seems reasonable that, to support this behavior, we should only\ncomplete remote branches in the form \"<remote>/<branch>\".\n\nIndeed, current completion is not just sub-par, but could almost be\ndescribed as entirely useless.\n\n  $git switch --track <TAB>\n\nwill only report *local* branch names. Indeed a new test case highlights\nthis quite well:\n\n  --- expected    2020-04-25 00:25:34.424965326 +0000\n  +++ out_sorted  2020-04-25 00:25:34.441965370 +0000\n  @@ -1,2 +1,2 @@\n  -other/branch-in-other\n  -other/master-in-other\n  +master\n  +matching-branch\n  not ok 100 - git switch - with --track, complete only remote branches # TODO known breakage\n\nUnderstanding exactly what causes this is not that simple.\n\nFirst we enable DWIM output by default. Then, if \"--track\",\n\"--no-track\", or \"--no-guess\" is enabled on the command line, we disable\nDWIM. This makes sense, because --track should not include the default\n\"DWIM\" remote branch names.\n\nFollowing this, there is a check for \"--detach\". If \"--detach\" is *not*\npresent, then we set only_local_ref=y. this is done because we would\nlike to avoid printing remote references. This immediately seems wrong\nbecause --track should allow completing remote references.\n\nFinally, if only_local_ref is 'y', and the track_opt for DWIM logic is\ndisabled, we complete only local branches. This occurs because --track\ndisabled track_opt, and not providing --detach sets only_local_ref to\n'y'.\n\nFixing this correctly is not trivial, so it is left to a follow up\nchange.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex af4661cbcc73..002223160058 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1271,6 +1271,16 @@ test_expect_success 'git switch - with --detach, complete all references' '\n \tEOF\n '\n \n+# TODO: Since --track on its own will perform a DWIM to extract the local\n+# branch name, we should complete only the remote branches with their remote\n+# name.\n+test_expect_failure 'git switch - with --track, complete only remote branches' '\n+\ttest_completion \"git switch --track \" <<-\\EOF\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n test_expect_success 'git switch - with --no-track, complete only local branch names' '\n \ttest_completion \"git switch --no-track \" <<-\\EOF\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"396217","messageId":"20200425022045.1089291-5-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 04/11] completion: add tests showing lack of support for git switch -c/-C","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:37Z","receivedAt":"2020-04-25T02:20:57Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nAdd several tests for git switch completion which highlight the expected\nbehavior if -c or -C have been provided.\n\nShow that properly recognizing and supporting -c should override the\nbehavior for --track.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 63 +++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 63 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 002223160058..a134a8791076 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1288,6 +1288,69 @@ test_expect_success 'git switch - with --no-track, complete only local branch na\n \tEOF\n '\n \n+# TODO: git switch completion does not yet support checking for -c, but it\n+# should be able to complete all possible references. Based on a quick\n+# examination of the switch/checkout code, -c will disable DWIM logic and thus\n+# we should not complete unique remote branch names with -c or -C either.\n+test_expect_failure 'git switch - with -c, complete all references' '\n+\ttest_completion \"git switch -c new-branch \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_failure 'git switch - with -c, complete all references' '\n+\ttest_completion \"git switch -C new-branch \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+# TODO: ensure that the completion rules for -c override --track\n+test_expect_failure 'git switch - with -c and --track, complete all references' '\n+\ttest_completion \"git switch -c new-branch --track \" <<-EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+# TODO: git switch with -c and --no-track should allow creating a branch using\n+# any reference as a starting point. Because completion support does not\n+# recognize -c or -C, this doesn't work yet.\n+test_expect_failure 'git switch - with -c and --no-track, complete all references' '\n+\ttest_completion \"git switch -c new-branch --no-track \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_failure 'git switch - with -C and --no-track, complete all references' '\n+\ttest_completion \"git switch -C new-branch --no-track \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n-- \n2.25.2\n\n"},{"id":"396218","messageId":"20200425022045.1089291-11-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 09/11] completion: fix completion for git switch with no options","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:43Z","receivedAt":"2020-04-25T02:20:58Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nAdd a new --mode option to __git_complete_refs, which allows changing\nthe behavior to call __git_heads instead of __git_refs.\n\nBy passing --mode=heads, __git_complete_refs will only output local\nbranches. This enables using \"--mode=heads --dwim\" to enable listing\nlocal branches or the remote unique branch names for DWIM.\n\nRefactor completion support in _git_switch() to decide whether to use\nthis mode instead of calling __git_heads directly.\n\nWhile doing this, cleanup the function so that it is a little less\nconfusing.\n\nWe can simplify this a little by moving the check for\nGIT_COMPLETION_CHECKOUT_NO_GUESS first, so that we do not get weird\ninteractions by re-enabling --dwim after checking for other options that\nmight disable it.\n\nIf --track, --no-track, --no-guess, -d, or --detach are provided, we\nwill disable --dwim, as these DWIM branch names won't work in these\nmodes.\n\nChoose the --mode to specify to __git_complete_refs by also checking\ncommand line parameters. Default to using --mode=heads, to list only\nlocal branches.\n\nIf -d or --detach are provided, switch to --mode=refs, so that we\ndisplay all references.\n\nIn this way, the basic support for completing just \"git switch <TAB>\"\nwill result in only local branches and remote unique names for DWIM, so\nswitch this test to test_expect_success.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 59 ++++++++++++++++----------\n t/t9902-completion.sh                  |  6 +--\n 2 files changed, 38 insertions(+), 27 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c582e070711f..0384b136763a 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -782,9 +782,12 @@ __git_refs ()\n #               word to be completed.\n # --sfx=<suffix>: A suffix to be appended to each ref instead of the default\n #                 space.\n+# --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to\n+#                complete all refs, or 'heads' to complete only branches. Note\n+#                that --remote is only compatible with --mode=refs.\n __git_complete_refs ()\n {\n-\tlocal remote dwim pfx cur_=\"$cur\" sfx=\" \"\n+\tlocal remote dwim pfx cur_=\"$cur\" sfx=\" \" mode=\"refs\"\n \n \twhile test $# != 0; do\n \t\tcase \"$1\" in\n@@ -795,13 +798,23 @@ __git_complete_refs ()\n \t\t--pfx=*)\tpfx=\"${1##--pfx=}\" ;;\n \t\t--cur=*)\tcur_=\"${1##--cur=}\" ;;\n \t\t--sfx=*)\tsfx=\"${1##--sfx=}\" ;;\n+\t\t--mode=*)\tmode=\"${1##--mode=}\" ;;\n \t\t*)\t\treturn 1 ;;\n \t\tesac\n \t\tshift\n \tdone\n \n-\t__gitcomp_direct \"$(__git_refs \"$remote\" \"\" \"$pfx\" \"$cur_\" \"$sfx\")\"\n+\t# complete references based on the specified mode\n+\tcase \"$mode\" in\n+\t\trefs)\n+\t\t\t__gitcomp_direct \"$(__git_refs \"$remote\" \"\" \"$pfx\" \"$cur_\" \"$sfx\")\" ;;\n+\t\theads)\n+\t\t\t__gitcomp_direct \"$(__git_heads \"$pfx\" \"$cur_\" \"$sfx\")\" ;;\n+\t\t*)\n+\t\t\treturn 1 ;;\n+\tesac\n \n+\t# Append DWIM remote branch names if requested\n \tif [ \"$dwim\" = \"yes\" ]; then\n \t\t__gitcomp_direct_append \"$(__git_dwim_remote_heads \"$pfx\" \"$cur_\" \"$sfx\")\"\n \tfi\n@@ -2256,7 +2269,7 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\n \t*)\n-\t\tlocal dwim_opt=\"--dwim\" only_local_ref=n\n+\t\tlocal dwim_opt=\"--dwim\" mode=\"heads\"\n \n \t\t# --orphan is used to create a branch disconnected from the\n \t\t# current history, based on the empty tree. Since the only\n@@ -2266,29 +2279,31 @@ _git_switch ()\n \t\t\treturn\n \t\tfi\n \n-\t\t# check if --track, --no-track, or --no-guess was specified\n-\t\t# if so, disable DWIM mode\n-\t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n-\t\t   [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n+\t\t# By default, git switch will DWIM with remote branch names by\n+\t\t# allowing these to expand into creating a local tracking\n+\t\t# branch of the same name. Completion for this can be disabled\n+\t\t# via GIT_COMPLETION_CHECKOUT_NO_GUESS, unless the user\n+\t\t# explicitly asked this behavior with --guess\n+\t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] &&\n+\t\t   [ -z \"$(__git_find_on_cmdline \"--guess\")\" ]; then\n \t\t\tdwim_opt=''\n \t\tfi\n-\t\t# explicit --guess enables DWIM mode regardless of\n-\t\t# $GIT_COMPLETION_CHECKOUT_NO_GUESS\n-\t\tif [ -n \"$(__git_find_on_cmdline \"--guess\")\" ]; then\n-\t\t\tdwim_opt='--dwim'\n+\n+\t\t# Certain combinations of options also disable this DWIM mode,\n+\t\t# so we should not complete such names in these cases.\n+\t\tif [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess -d --detach\")\" ]; then\n+\t\t\tdwim_opt=''\n \t\tfi\n-\t\tif [ -z \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n-\t\t\tonly_local_ref=y\n-\t\telse\n-\t\t\t# --guess --detach is invalid combination, no\n-\t\t\t# dwim will be done when --detach is specified\n-\t\t\tdwim_opt=\n-\t\tfi\n-\t\tif [ $only_local_ref = y -a -z \"$dwim_opt\" ]; then\n-\t\t\t__gitcomp_direct \"$(__git_heads \"\" \"$cur\" \" \")\"\n-\t\telse\n-\t\t\t__git_complete_refs $dwim_opt\n+\n+\t\t# By default, git switch will only allow switching between\n+\t\t# local branches, or DWIM with remote branch names. However,\n+\t\t# certain options for creating branches or detaching should\n+\t\t# complete all references.\n+\t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n+\t\t\tmode=\"refs\"\n \t\tfi\n+\n+\t\t__git_complete_refs $dwim_opt --mode=$mode\n \t\t;;\n \tesac\n }\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 9d02de167219..cfd27e4857b7 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1240,11 +1240,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n \ttest_cmp expected out\n '\n \n-# TODO: git switch by default should only include local branches and anything which\n-# would be understood by the DWIM logic. Currently it will complete most\n-# references including pseudorefs like HEAD and FETCH_HEAD, as well as tags.\n-# These should not be completed unless certain options have been enabled.\n-test_expect_failure 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n+test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n \ttest_completion \"git switch \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"396219","messageId":"20200425022045.1089291-13-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 11/11] completion: complete remote branches for git switch --track","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:45Z","receivedAt":"2020-04-25T02:21:00Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\ngit switch --track <remote>/<branch> will be interpreted as a DWIM to\ncreate a local tracking branch named <branch> tracking the specified\nremote.\n\nCompletion support for this case is buggy, because it will instead\nreport only local branches.\n\nFix this by extending __git_complete_refs with a new mode,\n\"remote-heads\" which will list all reference under refs/remotes/*.\n\nBy doing this, \"git switch --track <TAB>\" changes from the rather\nuseless set of local branches to only listing remote branches.\n\nNote that if the user has specified \"-c\" or \"-C\" already on the command\nline, this will still enable completing all references, as the check to\nuse the mode \"refs\" occurs first in an if-elif chain.\n\nThis finally fixes the \"git switch --track\" test case, so it is updated\naccordingly.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 25 +++++++++++++++++++++++--\n t/t9902-completion.sh                  |  5 +----\n 2 files changed, 24 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex f9be0dabb03e..cdd141b2ba1d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -624,6 +624,19 @@ __git_heads ()\n \t\t\t\"refs/heads/$cur_*\" \"refs/heads/$cur_*/**\"\n }\n \n+# Lists branches from remote repositories.\n+# 1: A prefix to be added to each listed branch (optional).\n+# 2: List only branches matching this word (optional; list all branches if\n+#    unset or empty).\n+# 3: A suffix to be appended to each listed branch (optional).\n+__git_remote_heads ()\n+{\n+\tlocal pfx=\"${1-}\" cur_=\"${2-}\" sfx=\"${3-}\"\n+\n+\t__git for-each-ref --format=\"${pfx//\\%/%%}%(refname:strip=2)$sfx\" \\\n+\t\t\t\"refs/remotes/$cur_*\" \"refs/remotes/$cur_*/**\"\n+}\n+\n # Lists tags from the local repository.\n # Accepts the same positional parameters as __git_heads() above.\n __git_tags ()\n@@ -783,8 +796,9 @@ __git_refs ()\n # --sfx=<suffix>: A suffix to be appended to each ref instead of the default\n #                 space.\n # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to\n-#                complete all refs, or 'heads' to complete only branches. Note\n-#                that --remote is only compatible with --mode=refs.\n+#                complete all refs, 'heads' to complete only branches, or\n+#                'remote-heads' to complete only remote branches. Note that\n+#                --remote is only compatible with --mode=refs.\n __git_complete_refs ()\n {\n \tlocal remote dwim pfx cur_=\"$cur\" sfx=\" \" mode=\"refs\"\n@@ -810,6 +824,8 @@ __git_complete_refs ()\n \t\t\t__gitcomp_direct \"$(__git_refs \"$remote\" \"\" \"$pfx\" \"$cur_\" \"$sfx\")\" ;;\n \t\theads)\n \t\t\t__gitcomp_direct \"$(__git_heads \"$pfx\" \"$cur_\" \"$sfx\")\" ;;\n+\t\tremote-heads)\n+\t\t\t__gitcomp_direct \"$(__git_remote_heads \"$pfx\" \"$cur_\" \"$sfx\")\" ;;\n \t\t*)\n \t\t\treturn 1 ;;\n \tesac\n@@ -2299,8 +2315,13 @@ _git_switch ()\n \t\t# local branches, or DWIM with remote branch names. However,\n \t\t# certain options for creating branches or detaching should\n \t\t# complete all references.\n+\t\t#\n+\t\t# Additionally, if --track is provided on its own, we should\n+\t\t# complete only remote branch names.\n \t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach -c -C\")\" ]; then\n \t\t\tmode=\"refs\"\n+\t\telif [ -n \"$(__git_find_on_cmdline \"--track\")\" ]; then\n+\t\t\tmode=\"remote-heads\"\n \t\tfi\n \n \t\t__git_complete_refs $dwim_opt --mode=$mode\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 68296d79a3e9..7491d8c3b72d 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1267,10 +1267,7 @@ test_expect_success 'git switch - with --detach, complete all references' '\n \tEOF\n '\n \n-# TODO: Since --track on its own will perform a DWIM to extract the local\n-# branch name, we should complete only the remote branches with their remote\n-# name.\n-test_expect_failure 'git switch - with --track, complete only remote branches' '\n+test_expect_success 'git switch - with --track, complete only remote branches' '\n \ttest_completion \"git switch --track \" <<-\\EOF\n \tother/branch-in-other Z\n \tother/master-in-other Z\n-- \n2.25.2\n\n"},{"id":"396220","messageId":"20200425022045.1089291-10-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 08/11] completion: perform DWIM logic directly in __git_complete_refs","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:42Z","receivedAt":"2020-04-25T02:21:01Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\n__git_complete_refs is the main function used for completing references.\nIt is primarily used as a wrapper around __git_refs, and is easier to\nextend since its arguments are option-like.\n\nOne major downside of __git_complete_refs and __git_refs currently, is\nthe lack of ability to complete only a subset of refs such as branches\n(refs/heads) or tags (refs/tags).\n\nNormally, a caller might just decide to use __git_heads() or\n__git_tags(). However, in the case of git-switch, it is useful to\ncomplete both branches *and* DWIM remote branch names.\n\nDue to the complexity and implementation of __git_refs, it is not easy\nto extend it to support listing only a subset of references.\n\nInstead, we can extend __git_complete_refs to do this. For this to be\ndone, we must first ensure that \"--dwim\" support is not tied to calling\n__git_refs.\n\nInstead of passing $dwim into __git_refs, we can implement\na __gitcomp_direct_append function which can append to COMPREPLY after\na call to __gitcomp_direct.\n\nIf --dwim is passed to __git_complete_refs, use __gitcomp_direct_append\nto add the output of __git_dwim_remote_heads to the completion list.\n\nIn this way, --dwim support is now independent of calling __git_refs.\n\nA future change will add an additional option to control what set of\nreferences __git_complete_refs will output.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 19 ++++++++++++++++++-\n 1 file changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex f1ee25f05690..c582e070711f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -301,6 +301,19 @@ __gitcomp_direct ()\n \tCOMPREPLY=($1)\n }\n \n+# Similar to __gitcomp_direct, but appends to COMPREPLY instead.\n+# Callers must take care of providing only words that match the current word\n+# to be completed and adding any prefix and/or suffix (trailing space!), if\n+# necessary.\n+# 1: List of newline-separated matching completion words, complete with\n+#    prefix and suffix.\n+__gitcomp_direct_append ()\n+{\n+\tlocal IFS=$'\\n'\n+\n+\tCOMPREPLY+=($1)\n+}\n+\n __gitcompappend ()\n {\n \tlocal x i=${#COMPREPLY[@]}\n@@ -787,7 +800,11 @@ __git_complete_refs ()\n \t\tshift\n \tdone\n \n-\t__gitcomp_direct \"$(__git_refs \"$remote\" \"$dwim\" \"$pfx\" \"$cur_\" \"$sfx\")\"\n+\t__gitcomp_direct \"$(__git_refs \"$remote\" \"\" \"$pfx\" \"$cur_\" \"$sfx\")\"\n+\n+\tif [ \"$dwim\" = \"yes\" ]; then\n+\t\t__gitcomp_direct_append \"$(__git_dwim_remote_heads \"$pfx\" \"$cur_\" \"$sfx\")\"\n+\tfi\n }\n \n # __git_refs2 requires 1 argument (to pass to __git_refs)\n-- \n2.25.2\n\n"},{"id":"396221","messageId":"20200425022045.1089291-12-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 10/11] completion: recognize -c/-C when completing for git switch","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:44Z","receivedAt":"2020-04-25T02:21:03Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nIf a user wants to create a new branch using git switch, we should be\nable to complete any starting point reference. Additionally, DWIM logic\nwill not work.\n\nAdd -c and -C to the list of options for disabling --dwim and for\nchoosing the --refs mode.\n\nThis fixes several known breakages, so update these tests accordingly.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash |  4 ++--\n t/t9902-completion.sh                  | 18 +++++-------------\n 2 files changed, 7 insertions(+), 15 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0384b136763a..f9be0dabb03e 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2291,7 +2291,7 @@ _git_switch ()\n \n \t\t# Certain combinations of options also disable this DWIM mode,\n \t\t# so we should not complete such names in these cases.\n-\t\tif [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess -d --detach\")\" ]; then\n+\t\tif [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess -d --detach -c -C\")\" ]; then\n \t\t\tdwim_opt=''\n \t\tfi\n \n@@ -2299,7 +2299,7 @@ _git_switch ()\n \t\t# local branches, or DWIM with remote branch names. However,\n \t\t# certain options for creating branches or detaching should\n \t\t# complete all references.\n-\t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n+\t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach -c -C\")\" ]; then\n \t\t\tmode=\"refs\"\n \t\tfi\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex cfd27e4857b7..68296d79a3e9 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1284,11 +1284,7 @@ test_expect_success 'git switch - with --no-track, complete only local branch na\n \tEOF\n '\n \n-# TODO: git switch completion does not yet support checking for -c, but it\n-# should be able to complete all possible references. Based on a quick\n-# examination of the switch/checkout code, -c will disable DWIM logic and thus\n-# we should not complete unique remote branch names with -c or -C either.\n-test_expect_failure 'git switch - with -c, complete all references' '\n+test_expect_success 'git switch - with -c, complete all references' '\n \ttest_completion \"git switch -c new-branch \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n@@ -1299,7 +1295,7 @@ test_expect_failure 'git switch - with -c, complete all references' '\n \tEOF\n '\n \n-test_expect_failure 'git switch - with -c, complete all references' '\n+test_expect_success 'git switch - with -c, complete all references' '\n \ttest_completion \"git switch -C new-branch \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n@@ -1310,8 +1306,7 @@ test_expect_failure 'git switch - with -c, complete all references' '\n \tEOF\n '\n \n-# TODO: ensure that the completion rules for -c override --track\n-test_expect_failure 'git switch - with -c and --track, complete all references' '\n+test_expect_success 'git switch - with -c and --track, complete all references' '\n \ttest_completion \"git switch -c new-branch --track \" <<-EOF\n \tHEAD Z\n \tmaster Z\n@@ -1322,10 +1317,7 @@ test_expect_failure 'git switch - with -c and --track, complete all references'\n \tEOF\n '\n \n-# TODO: git switch with -c and --no-track should allow creating a branch using\n-# any reference as a starting point. Because completion support does not\n-# recognize -c or -C, this doesn't work yet.\n-test_expect_failure 'git switch - with -c and --no-track, complete all references' '\n+test_expect_success 'git switch - with -c and --no-track, complete all references' '\n \ttest_completion \"git switch -c new-branch --no-track \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n@@ -1336,7 +1328,7 @@ test_expect_failure 'git switch - with -c and --no-track, complete all reference\n \tEOF\n '\n \n-test_expect_failure 'git switch - with -C and --no-track, complete all references' '\n+test_expect_success 'git switch - with -C and --no-track, complete all references' '\n \ttest_completion \"git switch -C new-branch --no-track \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"396222","messageId":"20200425022045.1089291-9-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 07/11] completion: extract function __git_dwim_remote_heads","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:41Z","receivedAt":"2020-04-25T02:21:04Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\n__git_refs() has the ability to report unique remote names for\nsupporting completion of remote branch names for the DWIMery of git\ncheckout and git switch.\n\nFor git checkout, this is fine, because it always supports completing\nall local references.\n\nHowever, git switch by default only supports either switching branches\nor using this DWIMery to create a local branch tracking the remote\nbranch.\n\nFuture work to cleanup and improve completion support for git switch\nwill be aided if the remote branch names can be completed separately\nfrom __git_refs.\n\nExtract this logic to a function __git_dwim_remote_heads(), and use it\nin __git_refs.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 28 +++++++++++++++++++-------\n 1 file changed, 21 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 02dc1203559c..f1ee25f05690 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -621,6 +621,26 @@ __git_tags ()\n \t\t\t\"refs/tags/$cur_*\" \"refs/tags/$cur_*/**\"\n }\n \n+# List unique branches from refs/remotes used for 'git checkout' and 'git\n+# switch' tracking DWIMery.\n+# 1: A prefix to be added to each listed branch (optional)\n+# 2: List only branches matching this word (optional; list all branches if\n+#    unset or empty).\n+# 3: A suffix to be appended to each listed branch (optional).\n+__git_dwim_remote_heads ()\n+{\n+\tlocal pfx=\"${1-}\" cur_=\"${2-}\" sfx=\"${3-}\"\n+\tlocal fer_pfx=\"${pfx//\\%/%%}\" # \"escape\" for-each-ref format specifiers\n+\n+\t# employ the heuristic used by git checkout and git switch\n+\t# Try to find a remote branch that cur_es the completion word\n+\t# but only output if the branch name is unique\n+\t__git for-each-ref --format=\"$fer_pfx%(refname:strip=3)$sfx\" \\\n+\t\t--sort=\"refname:strip=3\" \\\n+\t\t\"refs/remotes/*/$cur_*\" \"refs/remotes/*/$cur_*/**\" | \\\n+\tuniq -u\n+}\n+\n # Lists refs from the local (by default) or from a remote repository.\n # It accepts 0, 1 or 2 arguments:\n # 1: The remote to list refs from (optional; ignored, if set but empty).\n@@ -696,13 +716,7 @@ __git_refs ()\n \t\t__git_dir=\"$dir\" __git for-each-ref --format=\"$fer_pfx%($format)$sfx\" \\\n \t\t\t\"${refs[@]}\"\n \t\tif [ -n \"$track\" ]; then\n-\t\t\t# employ the heuristic used by git checkout\n-\t\t\t# Try to find a remote branch that matches the completion word\n-\t\t\t# but only output if the branch name is unique\n-\t\t\t__git for-each-ref --format=\"$fer_pfx%(refname:strip=3)$sfx\" \\\n-\t\t\t\t--sort=\"refname:strip=3\" \\\n-\t\t\t\t\"refs/remotes/*/$match*\" \"refs/remotes/*/$match*/**\" | \\\n-\t\t\tuniq -u\n+\t\t\t__git_dwim_remote_heads \"$pfx\" \"$match\" \"$sfx\"\n \t\tfi\n \t\treturn\n \tfi\n-- \n2.25.2\n\n"},{"id":"396223","messageId":"20200425022045.1089291-8-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 06/11] completion: rename --track option of __git_complete_refs","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:40Z","receivedAt":"2020-04-25T02:21:05Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nThe __git_complete_refs uses the \"--track\" option to specify when to\nenable listing of unique remote branches which could be used by the\nDWIMery of git checkout and git switch.\n\nThis is confusing, because both git checkout and git switch have\na --track option. This makes looking at the completion code for these\ntwo functions confusing.\n\nRename this parameter to --dwim. Because it is plausible for users to\nhave developed their own completions which rely on __git_complete_ref,\nkeep --track as a synonym for --dwim, but do not use it in our own\ncompletion code.\n\nThis reduces the confusion when seeing --track in the _git_switch() and\n_git_checkout() completion functions.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 28 ++++++++++++++------------\n 1 file changed, 15 insertions(+), 13 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 08d3406cf3e4..02dc1203559c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -749,7 +749,7 @@ __git_refs ()\n # Usage: __git_complete_refs [<option>]...\n # --remote=<remote>: The remote to list refs from, can be the name of a\n #                    configured remote, a path, or a URL.\n-# --track: List unique remote branches for 'git checkout's tracking DWIMery.\n+# --dwim: List unique remote branches for 'git switch's tracking DWIMery.\n # --pfx=<prefix>: A prefix to be added to each ref.\n # --cur=<word>: The current ref to be completed.  Defaults to the current\n #               word to be completed.\n@@ -757,12 +757,14 @@ __git_refs ()\n #                 space.\n __git_complete_refs ()\n {\n-\tlocal remote track pfx cur_=\"$cur\" sfx=\" \"\n+\tlocal remote dwim pfx cur_=\"$cur\" sfx=\" \"\n \n \twhile test $# != 0; do\n \t\tcase \"$1\" in\n \t\t--remote=*)\tremote=\"${1##--remote=}\" ;;\n-\t\t--track)\ttrack=\"yes\" ;;\n+\t\t--dwim)\t\tdwim=\"yes\" ;;\n+\t\t# --track is an old spelling of --dwim\n+\t\t--track)\tdwim=\"yes\" ;;\n \t\t--pfx=*)\tpfx=\"${1##--pfx=}\" ;;\n \t\t--cur=*)\tcur_=\"${1##--cur=}\" ;;\n \t\t--sfx=*)\tsfx=\"${1##--sfx=}\" ;;\n@@ -771,7 +773,7 @@ __git_complete_refs ()\n \t\tshift\n \tdone\n \n-\t__gitcomp_direct \"$(__git_refs \"$remote\" \"$track\" \"$pfx\" \"$cur_\" \"$sfx\")\"\n+\t__gitcomp_direct \"$(__git_refs \"$remote\" \"$dwim\" \"$pfx\" \"$cur_\" \"$sfx\")\"\n }\n \n # __git_refs2 requires 1 argument (to pass to __git_refs)\n@@ -1370,12 +1372,12 @@ _git_checkout ()\n \t*)\n \t\t# check if --track, --no-track, or --no-guess was specified\n \t\t# if so, disable DWIM mode\n-\t\tlocal flags=\"--track --no-track --no-guess\" track_opt=\"--track\"\n+\t\tlocal flags=\"--track --no-track --no-guess\" dwim_opt=\"--dwim\"\n \t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n \t\t   [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n-\t\t\ttrack_opt=''\n+\t\t\tdwim_opt=''\n \t\tfi\n-\t\t__git_complete_refs $track_opt\n+\t\t__git_complete_refs $dwim_opt\n \t\t;;\n \tesac\n }\n@@ -2223,7 +2225,7 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\n \t*)\n-\t\tlocal track_opt=\"--track\" only_local_ref=n\n+\t\tlocal dwim_opt=\"--dwim\" only_local_ref=n\n \n \t\t# --orphan is used to create a branch disconnected from the\n \t\t# current history, based on the empty tree. Since the only\n@@ -2237,24 +2239,24 @@ _git_switch ()\n \t\t# if so, disable DWIM mode\n \t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n \t\t   [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n-\t\t\ttrack_opt=''\n+\t\t\tdwim_opt=''\n \t\tfi\n \t\t# explicit --guess enables DWIM mode regardless of\n \t\t# $GIT_COMPLETION_CHECKOUT_NO_GUESS\n \t\tif [ -n \"$(__git_find_on_cmdline \"--guess\")\" ]; then\n-\t\t\ttrack_opt='--track'\n+\t\t\tdwim_opt='--dwim'\n \t\tfi\n \t\tif [ -z \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n \t\t\tonly_local_ref=y\n \t\telse\n \t\t\t# --guess --detach is invalid combination, no\n \t\t\t# dwim will be done when --detach is specified\n-\t\t\ttrack_opt=\n+\t\t\tdwim_opt=\n \t\tfi\n-\t\tif [ $only_local_ref = y -a -z \"$track_opt\" ]; then\n+\t\tif [ $only_local_ref = y -a -z \"$dwim_opt\" ]; then\n \t\t\t__gitcomp_direct \"$(__git_heads \"\" \"$cur\" \" \")\"\n \t\telse\n-\t\t\t__git_complete_refs $track_opt\n+\t\t\t__git_complete_refs $dwim_opt\n \t\tfi\n \t\t;;\n \tesac\n-- \n2.25.2\n\n"},{"id":"396224","messageId":"20200425022045.1089291-7-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 05/11] completion: remove completion for git switch --orphan","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:39Z","receivedAt":"2020-04-25T02:21:07Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\ngit switch with the --orphan option is used to create a new branch that\nis not connected to any history and is instead based on the empty tree.\n\nIt does not make sense for completion to return anything in this case,\nbecause there is nothing to complete. Check for --orphan, and if it's\nfound, immediately return from _git_switch() without completing\nanything.\n\nAdd a test case which documents this expected behavior.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 11 ++++++++++-\n t/t9902-completion.sh                  |  7 +++++++\n 2 files changed, 17 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c21786f2fd00..08d3406cf3e4 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2223,9 +2223,18 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\n \t*)\n+\t\tlocal track_opt=\"--track\" only_local_ref=n\n+\n+\t\t# --orphan is used to create a branch disconnected from the\n+\t\t# current history, based on the empty tree. Since the only\n+\t\t# option required is the branch name, it doesn't make sense to\n+\t\t# complete anything here.\n+\t\tif [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n+\t\t\treturn\n+\t\tfi\n+\n \t\t# check if --track, --no-track, or --no-guess was specified\n \t\t# if so, disable DWIM mode\n-\t\tlocal track_opt=\"--track\" only_local_ref=n\n \t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n \t\t   [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n \t\t\ttrack_opt=''\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex a134a8791076..9d02de167219 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n \tEOF\n '\n \n+# TODO: completion does not yet recognize --orphan\n+test_expect_failure 'git switch - with --orphan, do not complete anything' '\n+\ttest_completion \"git switch --orphan \" <<-\\EOF\n+\n+\tEOF\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n-- \n2.25.2\n\n"},{"id":"396225","messageId":"20200425022045.1089291-6-jacob.e.keller@intel.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"[PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-04-25T02:20:38Z","receivedAt":"2020-04-25T02:21:07Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\ngit switch with the --orphan option is used to create a new branch that\nis not connected to any history and is instead based on the empty tree.\n\nIt does not make sense for completion to return anything in this case,\nbecause there is nothing to complete. Check for --orphan, and if it's\nfound, immediately return from _git_switch() without completing\nanything.\n\nAdd a test case which documents this expected behavior.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 11 ++++++++++-\n t/t9902-completion.sh                  |  7 +++++++\n 2 files changed, 17 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c21786f2fd00..08d3406cf3e4 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2223,9 +2223,18 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\n \t*)\n+\t\tlocal track_opt=\"--track\" only_local_ref=n\n+\n+\t\t# --orphan is used to create a branch disconnected from the\n+\t\t# current history, based on the empty tree. Since the only\n+\t\t# option required is the branch name, it doesn't make sense to\n+\t\t# complete anything here.\n+\t\tif [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n+\t\t\treturn\n+\t\tfi\n+\n \t\t# check if --track, --no-track, or --no-guess was specified\n \t\t# if so, disable DWIM mode\n-\t\tlocal track_opt=\"--track\" only_local_ref=n\n \t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n \t\t   [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n \t\t\ttrack_opt=''\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex a134a8791076..9d02de167219 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n \tEOF\n '\n \n+# TODO: completion does not yet recognize --orphan\n+test_expect_failure 'git switch - with --orphan, do not complete anything' '\n+\ttest_completion \"git switch --orphan \" <<-\\EOF\n+\n+\tEOF\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n-- \n2.25.2\n\n"},{"id":"396271","messageId":"CA+P7+xp8RzrpErc0bu2MxozyA0sAM-4W0C94wZWgwGOzzTYx7w@mail.gmail.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"Re: [PATCH 00/11] refactor git switch completion","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-04-25T22:14:03Z","receivedAt":"2020-04-25T22:14:16Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Fri, Apr 24, 2020 at 7:20 PM Jacob Keller <jacob.e.keller@intel.com> wrote:\n> Following this are some patches to extract displaying DWIM remote branch\n> names from __git_refs() and refactoring __git_complete_refs to take a mode\n> argument that switches between calling __git_heads, __git_refs, and a new\n> __git_remotes.\n\nThis should read __git_remote_heads, since I changed the name to be\nmore descriptive to avoid thinking it prints the remote names on their\nown.\n\nThanks,\nJake\n"},{"id":"396405","messageId":"xmqqv9lk5wqy.fsf@gitster.c.googlers.com","threadId":"53317","inReplyTo":"20200425022045.1089291-6-jacob.e.keller@intel.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-27T23:34:13Z","receivedAt":"2020-04-27T23:34:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.e.keller@intel.com> writes:\n\n> From: Jacob Keller <jacob.keller@gmail.com>\n>\n> git switch with the --orphan option is used to create a new branch that\n> is not connected to any history and is instead based on the empty tree.\n>\n> It does not make sense for completion to return anything in this case,\n> because there is nothing to complete. Check for --orphan, and if it's\n> found, immediately return from _git_switch() without completing\n> anything.\n>\n> Add a test case which documents this expected behavior.\n>\n> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 11 ++++++++++-\n>  t/t9902-completion.sh                  |  7 +++++++\n>  2 files changed, 17 insertions(+), 1 deletion(-)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index c21786f2fd00..08d3406cf3e4 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -2223,9 +2223,18 @@ _git_switch ()\n>  \t\t__gitcomp_builtin switch\n>  \t\t;;\n>  \t*)\n> +\t\tlocal track_opt=\"--track\" only_local_ref=n\n> +\n> +\t\t# --orphan is used to create a branch disconnected from the\n> +\t\t# current history, based on the empty tree. Since the only\n> +\t\t# option required is the branch name, it doesn't make sense to\n> +\t\t# complete anything here.\n> +\t\tif [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n> +\t\t\treturn\n> +\t\tfi\n> +\n>  \t\t# check if --track, --no-track, or --no-guess was specified\n>  \t\t# if so, disable DWIM mode\n> -\t\tlocal track_opt=\"--track\" only_local_ref=n\n>  \t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n>  \t\t   [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n>  \t\t\ttrack_opt=''\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index a134a8791076..9d02de167219 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n>  \tEOF\n>  '\n>  \n> +# TODO: completion does not yet recognize --orphan\n> +test_expect_failure 'git switch - with --orphan, do not complete anything' '\n> +\ttest_completion \"git switch --orphan \" <<-\\EOF\n> +\n> +\tEOF\n> +'\n> +\n\nI am getting \"TODO passed\" at 7276ffe0 (completion: add test showing\nsubpar completion for git switch --orphan, 2020-04-24), which hasn't\nhit 'next' yet.\n\nPerhaps we got some rebase gotcha here?\n\n>  test_expect_success 'teardown after ref completion' '\n>  \tgit branch -d matching-branch &&\n>  \tgit tag -d matching-tag &&\n"},{"id":"396426","messageId":"CA+P7+xqEFk5_x5hG=zbPUCvz4W5Obr7fMjdPVfKYCZ8A9e2uqA@mail.gmail.com","threadId":"53317","inReplyTo":"xmqqv9lk5wqy.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-04-28T02:12:39Z","receivedAt":"2020-04-28T02:12:52Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Mon, Apr 27, 2020 at 4:34 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jacob Keller <jacob.e.keller@intel.com> writes:\n>\n> > From: Jacob Keller <jacob.keller@gmail.com>\n> >\n> > git switch with the --orphan option is used to create a new branch that\n> > is not connected to any history and is instead based on the empty tree.\n> >\n> > It does not make sense for completion to return anything in this case,\n> > because there is nothing to complete. Check for --orphan, and if it's\n> > found, immediately return from _git_switch() without completing\n> > anything.\n> >\n> > Add a test case which documents this expected behavior.\n> >\n> > Signed-off-by: Jacob Keller <jacob.keller@gmail.com>\n> > ---\n> >  contrib/completion/git-completion.bash | 11 ++++++++++-\n> >  t/t9902-completion.sh                  |  7 +++++++\n> >  2 files changed, 17 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> > index c21786f2fd00..08d3406cf3e4 100644\n> > --- a/contrib/completion/git-completion.bash\n> > +++ b/contrib/completion/git-completion.bash\n> > @@ -2223,9 +2223,18 @@ _git_switch ()\n> >               __gitcomp_builtin switch\n> >               ;;\n> >       *)\n> > +             local track_opt=\"--track\" only_local_ref=n\n> > +\n> > +             # --orphan is used to create a branch disconnected from the\n> > +             # current history, based on the empty tree. Since the only\n> > +             # option required is the branch name, it doesn't make sense to\n> > +             # complete anything here.\n> > +             if [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n> > +                     return\n> > +             fi\n> > +\n> >               # check if --track, --no-track, or --no-guess was specified\n> >               # if so, disable DWIM mode\n> > -             local track_opt=\"--track\" only_local_ref=n\n> >               if [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n> >                  [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n> >                       track_opt=''\n> > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> > index a134a8791076..9d02de167219 100755\n> > --- a/t/t9902-completion.sh\n> > +++ b/t/t9902-completion.sh\n> > @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n> >       EOF\n> >  '\n> >\n> > +# TODO: completion does not yet recognize --orphan\n> > +test_expect_failure 'git switch - with --orphan, do not complete anything' '\n> > +     test_completion \"git switch --orphan \" <<-\\EOF\n> > +\n> > +     EOF\n> > +'\n> > +\n>\n> I am getting \"TODO passed\" at 7276ffe0 (completion: add test showing\n> subpar completion for git switch --orphan, 2020-04-24), which hasn't\n> hit 'next' yet.\n>\n> Perhaps we got some rebase gotcha here?\n>\n\n\nHmm.. Yea, I think there is a problem. Originally I had one commit\nwhich added the test case for --orphan and I fixed it later, but I\nrebased things so it was one commit. I probably just forgot to update\nthe tests.\n\nThanks,\nJake\n\n> >  test_expect_success 'teardown after ref completion' '\n> >       git branch -d matching-branch &&\n> >       git tag -d matching-tag &&\n"},{"id":"396427","messageId":"CA+P7+xpEMb-A1cOkOxdWf0pM=5o8Cyn9=5HLZPtFNMcLUaypsg@mail.gmail.com","threadId":"53317","inReplyTo":"xmqqv9lk5wqy.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-04-28T02:20:44Z","receivedAt":"2020-04-28T02:20:57Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"The proposed SQUASH you have in gitster/jk/complete-git-switch is\ncorrect. The commit message body is correct, but the title could be\nreworded to\n\n\"completion: stop completing refs for git switch --orphan\"\n\nI can send a v2 if that would be helpful, and I've got it fixed up\nlocally if other review increases the need for a new spin.\n\nThanks,\nJake\n\nOn Mon, Apr 27, 2020 at 4:34 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jacob Keller <jacob.e.keller@intel.com> writes:\n>\n> > From: Jacob Keller <jacob.keller@gmail.com>\n> >\n> > git switch with the --orphan option is used to create a new branch that\n> > is not connected to any history and is instead based on the empty tree.\n> >\n> > It does not make sense for completion to return anything in this case,\n> > because there is nothing to complete. Check for --orphan, and if it's\n> > found, immediately return from _git_switch() without completing\n> > anything.\n> >\n> > Add a test case which documents this expected behavior.\n> >\n> > Signed-off-by: Jacob Keller <jacob.keller@gmail.com>\n> > ---\n> >  contrib/completion/git-completion.bash | 11 ++++++++++-\n> >  t/t9902-completion.sh                  |  7 +++++++\n> >  2 files changed, 17 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> > index c21786f2fd00..08d3406cf3e4 100644\n> > --- a/contrib/completion/git-completion.bash\n> > +++ b/contrib/completion/git-completion.bash\n> > @@ -2223,9 +2223,18 @@ _git_switch ()\n> >               __gitcomp_builtin switch\n> >               ;;\n> >       *)\n> > +             local track_opt=\"--track\" only_local_ref=n\n> > +\n> > +             # --orphan is used to create a branch disconnected from the\n> > +             # current history, based on the empty tree. Since the only\n> > +             # option required is the branch name, it doesn't make sense to\n> > +             # complete anything here.\n> > +             if [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n> > +                     return\n> > +             fi\n> > +\n> >               # check if --track, --no-track, or --no-guess was specified\n> >               # if so, disable DWIM mode\n> > -             local track_opt=\"--track\" only_local_ref=n\n> >               if [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n> >                  [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n> >                       track_opt=''\n> > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> > index a134a8791076..9d02de167219 100755\n> > --- a/t/t9902-completion.sh\n> > +++ b/t/t9902-completion.sh\n> > @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n> >       EOF\n> >  '\n> >\n> > +# TODO: completion does not yet recognize --orphan\n> > +test_expect_failure 'git switch - with --orphan, do not complete anything' '\n> > +     test_completion \"git switch --orphan \" <<-\\EOF\n> > +\n> > +     EOF\n> > +'\n> > +\n>\n> I am getting \"TODO passed\" at 7276ffe0 (completion: add test showing\n> subpar completion for git switch --orphan, 2020-04-24), which hasn't\n> hit 'next' yet.\n>\n> Perhaps we got some rebase gotcha here?\n>\n> >  test_expect_success 'teardown after ref completion' '\n> >       git branch -d matching-branch &&\n> >       git tag -d matching-tag &&\n"},{"id":"396472","messageId":"xmqqo8rb4lyj.fsf@gitster.c.googlers.com","threadId":"53317","inReplyTo":"CA+P7+xpEMb-A1cOkOxdWf0pM=5o8Cyn9=5HLZPtFNMcLUaypsg@mail.gmail.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-28T16:24:52Z","receivedAt":"2020-04-28T16:25:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n> The proposed SQUASH you have in gitster/jk/complete-git-switch is\n> correct. The commit message body is correct, but the title could be\n> reworded to\n>\n> \"completion: stop completing refs for git switch --orphan\"\n>\n> I can send a v2 if that would be helpful, and I've got it fixed up\n> locally if other review increases the need for a new spin.\n\nThnaks.  In the meantime, what I have is attached (the test title,\nin addition to the commit title, has been updated).\n\nThe same logic would apply to \"git checkout -b <TAB>\" (or \"git\nswitch -c <TAB>\") as this change: these are meant to create a new\nbranch so you do not want to offer an existing branch name.\n\nI have a mixed feelings about that reasoning, though.  I understand\nthat not offering any existing branch name would avoid offering a\nbranch name that would cause an error message from the command,\nwhich at a first glance feels like a nice help to the user, but I am\nnot sure if it is really helping.\n\nWhen you are on jk/complete-switch branch to work on this topic, you\nmay want to keep the current state of the branch and use a \"v2\"\nbranch to play around (running \"rebase -i\" etc.), for which the way\nI would hope to work would be:\n\n\tgit checkout -b jk/comp<TAB>\n\nthat would complete to an existing branch\n\n\tgit checkout -b jk/complete-switch\n\nand then I can just type \"-v2<Enter>\" (or \"<BackSpace>-v2<Enter>\" to\nremove the inter-word space completion adds?)  after that.  After\nall, \"git checkout -b jk/complete-switch\" in that scenario would\nerror out by saying that you already use that name, which is a good\nenough protection.\n\nAnd that same \"is this really helping?\" reasoning applies equally to\nthe \"--orphan\" option.\n\nI dunno.\n\n-- >8 --\nFrom: Jacob Keller <jacob.keller@gmail.com>\nDate: Fri, 24 Apr 2020 19:20:38 -0700\nSubject: [PATCH] completion: stop completing refs for git switch --orphan\n\ngit switch with the --orphan option is used to create a new branch that\nis not connected to any history and is instead based on the empty tree.\n\nIt does not make sense for completion to return anything in this case,\nbecause there is nothing to complete. Check for --orphan, and if it's\nfound, immediately return from _git_switch() without completing\nanything.\n\nAdd a test case which documents this expected behavior.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n contrib/completion/git-completion.bash | 11 ++++++++++-\n t/t9902-completion.sh                  |  6 ++++++\n 2 files changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c21786f2fd..08d3406cf3 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2223,9 +2223,18 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\n \t*)\n+\t\tlocal track_opt=\"--track\" only_local_ref=n\n+\n+\t\t# --orphan is used to create a branch disconnected from the\n+\t\t# current history, based on the empty tree. Since the only\n+\t\t# option required is the branch name, it doesn't make sense to\n+\t\t# complete anything here.\n+\t\tif [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n+\t\t\treturn\n+\t\tfi\n+\n \t\t# check if --track, --no-track, or --no-guess was specified\n \t\t# if so, disable DWIM mode\n-\t\tlocal track_opt=\"--track\" only_local_ref=n\n \t\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n \t\t   [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n \t\t\ttrack_opt=''\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex a134a87910..7e4dd8e722 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1351,6 +1351,12 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n \tEOF\n '\n \n+test_expect_success 'git switch --orphan completes no references' '\n+\ttest_completion \"git switch --orphan \" <<-\\EOF\n+\n+\tEOF\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n-- \n2.26.2-266-ge870325ee8\n\n"},{"id":"396479","messageId":"CA+P7+xoBnS8huHiU+QM8x6LRiSDRYVVS2pduv6i_qrwb1ZS7fg@mail.gmail.com","threadId":"53317","inReplyTo":"xmqqo8rb4lyj.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-04-28T17:32:02Z","receivedAt":"2020-04-28T17:32:16Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Tue, Apr 28, 2020 at 9:24 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jacob Keller <jacob.keller@gmail.com> writes:\n>\n> > The proposed SQUASH you have in gitster/jk/complete-git-switch is\n> > correct. The commit message body is correct, but the title could be\n> > reworded to\n> >\n> > \"completion: stop completing refs for git switch --orphan\"\n> >\n> > I can send a v2 if that would be helpful, and I've got it fixed up\n> > locally if other review increases the need for a new spin.\n>\n> Thnaks.  In the meantime, what I have is attached (the test title,\n> in addition to the commit title, has been updated).\n>\n> The same logic would apply to \"git checkout -b <TAB>\" (or \"git\n> switch -c <TAB>\") as this change: these are meant to create a new\n> branch so you do not want to offer an existing branch name.\n>\n\nWhile true, you may optionally have a 2nd argument which provides a\nstart point that can be an arbitrary reference.\n\n> I have a mixed feelings about that reasoning, though.  I understand\n> that not offering any existing branch name would avoid offering a\n> branch name that would cause an error message from the command,\n> which at a first glance feels like a nice help to the user, but I am\n> not sure if it is really helping.\n>\n> When you are on jk/complete-switch branch to work on this topic, you\n> may want to keep the current state of the branch and use a \"v2\"\n> branch to play around (running \"rebase -i\" etc.), for which the way\n> I would hope to work would be:\n>\n>         git checkout -b jk/comp<TAB>\n>\n> that would complete to an existing branch\n>\n>         git checkout -b jk/complete-switch\n>\n\nHmm.. Yes this would be useful.\n\n> and then I can just type \"-v2<Enter>\" (or \"<BackSpace>-v2<Enter>\" to\n> remove the inter-word space completion adds?)  after that.  After\n> all, \"git checkout -b jk/complete-switch\" in that scenario would\n> error out by saying that you already use that name, which is a good\n> enough protection.\n>\n> And that same \"is this really helping?\" reasoning applies equally to\n> the \"--orphan\" option.\n>\n> I dunno.\n>\n\nFair enough, new branches based on previous branches makes sense.\n\nThanks,\nJake\n\n> -- >8 --\n> From: Jacob Keller <jacob.keller@gmail.com>\n> Date: Fri, 24 Apr 2020 19:20:38 -0700\n> Subject: [PATCH] completion: stop completing refs for git switch --orphan\n>\n> git switch with the --orphan option is used to create a new branch that\n> is not connected to any history and is instead based on the empty tree.\n>\n> It does not make sense for completion to return anything in this case,\n> because there is nothing to complete. Check for --orphan, and if it's\n> found, immediately return from _git_switch() without completing\n> anything.\n>\n> Add a test case which documents this expected behavior.\n>\n> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  contrib/completion/git-completion.bash | 11 ++++++++++-\n>  t/t9902-completion.sh                  |  6 ++++++\n>  2 files changed, 16 insertions(+), 1 deletion(-)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index c21786f2fd..08d3406cf3 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -2223,9 +2223,18 @@ _git_switch ()\n>                 __gitcomp_builtin switch\n>                 ;;\n>         *)\n> +               local track_opt=\"--track\" only_local_ref=n\n> +\n> +               # --orphan is used to create a branch disconnected from the\n> +               # current history, based on the empty tree. Since the only\n> +               # option required is the branch name, it doesn't make sense to\n> +               # complete anything here.\n> +               if [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n> +                       return\n> +               fi\n> +\n>                 # check if --track, --no-track, or --no-guess was specified\n>                 # if so, disable DWIM mode\n> -               local track_opt=\"--track\" only_local_ref=n\n>                 if [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ] ||\n>                    [ -n \"$(__git_find_on_cmdline \"--track --no-track --no-guess\")\" ]; then\n>                         track_opt=''\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index a134a87910..7e4dd8e722 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -1351,6 +1351,12 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n>         EOF\n>  '\n>\n> +test_expect_success 'git switch --orphan completes no references' '\n> +       test_completion \"git switch --orphan \" <<-\\EOF\n> +\n> +       EOF\n> +'\n> +\n>  test_expect_success 'teardown after ref completion' '\n>         git branch -d matching-branch &&\n>         git tag -d matching-tag &&\n> --\n> 2.26.2-266-ge870325ee8\n>\n"},{"id":"396484","messageId":"xmqqsggn32i7.fsf@gitster.c.googlers.com","threadId":"53317","inReplyTo":"CA+P7+xoBnS8huHiU+QM8x6LRiSDRYVVS2pduv6i_qrwb1ZS7fg@mail.gmail.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-28T18:10:24Z","receivedAt":"2020-04-28T18:10:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n>> And that same \"is this really helping?\" reasoning applies equally to\n>> the \"--orphan\" option.\n>>\n>> I dunno.\n>>\n>\n> Fair enough, new branches based on previous branches makes sense.\n\nI actually do not have a strong opinion either way.  I just wanted\nto say that it would be good to make it consistent across \"checkout\n-b\", \"switch -c\" and \"checkout/switch --orphan\".\n\nIt would be nice if \"checkout -B\" and \"switch -C\" pair offered\nexisting branches, as the intention of using the capital letter is\nclear---the user wants to overwrite an existing one.\n\nOn the other hand, I am OK if \"checkout -b\", \"switch -c\" and\n\"--orphan\" offered either:\n\n (1) nothing, as your patch does, or\n\n (2) all branches, except for the currently checked out one.\n\nIt would be preferrable if they did the same thing.\n\nThanks.\n\n"},{"id":"396489","messageId":"CA+P7+xoSdDjbSAKeCsPz97Rc=ykpuTb2pNKazsCNcau2SBquMA@mail.gmail.com","threadId":"53317","inReplyTo":"xmqqsggn32i7.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-04-28T18:45:58Z","receivedAt":"2020-04-28T18:46:13Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Tue, Apr 28, 2020 at 11:10 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jacob Keller <jacob.keller@gmail.com> writes:\n>\n> >> And that same \"is this really helping?\" reasoning applies equally to\n> >> the \"--orphan\" option.\n> >>\n> >> I dunno.\n> >>\n> >\n> > Fair enough, new branches based on previous branches makes sense.\n>\n> I actually do not have a strong opinion either way.  I just wanted\n> to say that it would be good to make it consistent across \"checkout\n> -b\", \"switch -c\" and \"checkout/switch --orphan\".\n>\n> It would be nice if \"checkout -B\" and \"switch -C\" pair offered\n> existing branches, as the intention of using the capital letter is\n> clear---the user wants to overwrite an existing one.\n>\n> On the other hand, I am OK if \"checkout -b\", \"switch -c\" and\n> \"--orphan\" offered either:\n>\n>  (1) nothing, as your patch does, or\n>\n>  (2) all branches, except for the currently checked out one.\n\nWhy reject the currently checked out one? If the premise is: \"use a\ncurrent branch to build a new branch name\", I don't see a reason to\nrestrict including the current branch here as well.\n\n>\n> It would be preferrable if they did the same thing.\n>\n> Thanks.\n>\n\nThe problem I see, is that regardless, I would like to see the following:\n\ngit switch -c new-branch-name <SPACE><TAB>\n\ncomplete all references for the starting point.\n\nWith this series, that's handled by just checking for \"-c/-C\" on the\ncommand line and enabling all references. There's no positional checks\ndone, so every word can complete to a reference.\n\nI don't know offhand how to add completion which depends on the\nposition of the word we're completing, so I'd have to investigate how\nto make that happen.\n\nThanks,\nJake\n"},{"id":"396491","messageId":"xmqq8sif2zfr.fsf@gitster.c.googlers.com","threadId":"53317","inReplyTo":"CA+P7+xoSdDjbSAKeCsPz97Rc=ykpuTb2pNKazsCNcau2SBquMA@mail.gmail.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-28T19:16:40Z","receivedAt":"2020-04-28T19:17:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n>> On the other hand, I am OK if \"checkout -b\", \"switch -c\" and\n>> \"--orphan\" offered either:\n>>\n>>  (1) nothing, as your patch does, or\n>>\n>>  (2) all branches, except for the currently checked out one.\n>\n> Why reject the currently checked out one? If the premise is: \"use a\n> current branch to build a new branch name\", I don't see a reason to\n> restrict including the current branch here as well.\n\nYeah, \"(3) all branches, without any exception\" makes sense too.\n\n>> It would be preferrable if they did the same thing.\n>>\n>> Thanks.\n\n> The problem I see, is that regardless, I would like to see the following:\n>\n> git switch -c new-branch-name <SPACE><TAB>\n>\n> complete all references for the starting point.\n\nMakes sense.  The starting point could be any branch or even a tag.\n\n> With this series, that's handled by just checking for \"-c/-C\" on the\n> command line and enabling all references. There's no positional checks\n> done, so every word can complete to a reference.\n>\n> I don't know offhand how to add completion which depends on the\n> position of the word we're completing, so I'd have to investigate how\n> to make that happen.\n\nI see.  Even though I say \"(3) all branches\" is a reasonable\nbehaviour, too, if the starting point has to be more (i.e. including\ntags), that would not help the issue you have here.  It may not be\ntoo bad if we offered all refs (including tags, which may not be a\ngood idea) in that case.  I dunno.\n\nThanks.\n\n\n"},{"id":"396497","messageId":"CA+P7+xpD7LaYMnoi6L-Z7e9w0j0+ppDCw6fGBzSMfxerw0HrUA@mail.gmail.com","threadId":"53317","inReplyTo":"xmqq8sif2zfr.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-04-28T20:41:44Z","receivedAt":"2020-04-28T20:41:58Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Tue, Apr 28, 2020 at 12:16 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jacob Keller <jacob.keller@gmail.com> writes:\n> > With this series, that's handled by just checking for \"-c/-C\" on the\n> > command line and enabling all references. There's no positional checks\n> > done, so every word can complete to a reference.\n> >\n> > I don't know offhand how to add completion which depends on the\n> > position of the word we're completing, so I'd have to investigate how\n> > to make that happen.\n>\n> I see.  Even though I say \"(3) all branches\" is a reasonable\n> behaviour, too, if the starting point has to be more (i.e. including\n> tags), that would not help the issue you have here.  It may not be\n> too bad if we offered all refs (including tags, which may not be a\n> good idea) in that case.  I dunno.\n>\n> Thanks.\n>\n\nBasically, when creating a branch, you often do \"git switch -c\nbranch-name start-point\"\n\nbranch-name would be the new branch name you want, and I think we\nshould complete local branches for this, but start-point can be any\nreference, i.e. a tag, a local branch, or a remote reference.\n\nI assumed completion would be most useful to complete the start-point,\nand so I opted to lean towards fixing completion for -c/-C to complete\nall references. However, I don't think the branch name should\nnecessarily complete from all references and it would make sense to\ncomplete that portion only by local branch names.\n\nI'm just not sure how best to implement that in our completion logic,\nand I would rather ensure that start-point completes properly, if we\nhave to choose.\n\nThanks,\nJake\n"},{"id":"396500","messageId":"xmqqlfmf1g7m.fsf@gitster.c.googlers.com","threadId":"53317","inReplyTo":"CA+P7+xpD7LaYMnoi6L-Z7e9w0j0+ppDCw6fGBzSMfxerw0HrUA@mail.gmail.com","subject":"Re: [PATCH 05/11] completion: add test showing subpar completion for git switch --orphan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-28T20:57:17Z","receivedAt":"2020-04-28T20:57:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n> I assumed completion would be most useful to complete the start-point,\n> and so I opted to lean towards fixing completion for -c/-C to complete\n> all references. However, I don't think the branch name should\n> necessarily complete from all references and it would make sense to\n> complete that portion only by local branch names.\n>\n> I'm just not sure how best to implement that in our completion logic,\n> and I would rather ensure that start-point completes properly, if we\n> have to choose.\n\nSure.  What I was saying that if it is easier to implement by\ncompleting both new branch name and starting point from the same\nset, you could choose to include both branches and tags, and your\n\"excuse\" for choosing that design could be that a user who wants to\nfix something in 2.26 release may want the completion and typing\nprogression go like so:\n\n\t$ git switch -c v2.2<TAB>\n\t... offers v2.20, v2.21, ..., v2.26 as candidates\n\t... complete to v2.26 and type \"-frotz-fix\"\n\t$ git switch -c v2.26-frotz-fix\n\t$ git switch -c v2.26-frotz-fix v2.2<TAB>\n\t... again offers v2.20, v2.21, ..., v2.26\n\n;-)\n"},{"id":"396704","messageId":"xmqqsggkpop0.fsf@gitster.c.googlers.com","threadId":"53317","inReplyTo":"20200425022045.1089291-1-jacob.e.keller@intel.com","subject":"Re: [PATCH 00/11] refactor git switch completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-30T22:56:59Z","receivedAt":"2020-04-30T22:57:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.e.keller@intel.com> writes:\n\n> From: Jacob Keller <jacob.keller@gmail.com>\n>\n> completion support for git switch is subpar for a number of cases. Most\n> notable is difference between these two completions:\n>\n>   $git switch <TAB>\n>   Display all 784 possibilities? (y or n)\n>   <list of all references and DWIM remotes>\n>\n>   $git switch --track<TAB>\n>   jk-refactor-git-switch-completion master`\n> ...\n\nWe've discussed that it may be a good idea to make sure that \"switch\n-c\", \"checkout -b\" and \"switch/checkout --orphan\" complete the new\nbranch name the same way, but haven't done anything else.  I'd very\nmuch appreciate to see the patches reviewed by those involved more\nin the completion script, before we decide to merge the topic to\n'next'.\n\nThanks.\n"},{"id":"396787","messageId":"CA+P7+xpdNtRPOzR09DJNRZagqwEOt3-=mxye3qQk5XQ4guaJTg@mail.gmail.com","threadId":"53317","inReplyTo":"xmqqsggkpop0.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 00/11] refactor git switch completion","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-05-01T21:53:32Z","receivedAt":"2020-05-01T21:53:47Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Apr 30, 2020 at 3:57 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jacob Keller <jacob.e.keller@intel.com> writes:\n>\n> > From: Jacob Keller <jacob.keller@gmail.com>\n> >\n> > completion support for git switch is subpar for a number of cases. Most\n> > notable is difference between these two completions:\n> >\n> >   $git switch <TAB>\n> >   Display all 784 possibilities? (y or n)\n> >   <list of all references and DWIM remotes>\n> >\n> >   $git switch --track<TAB>\n> >   jk-refactor-git-switch-completion master`\n> > ...\n>\n> We've discussed that it may be a good idea to make sure that \"switch\n> -c\", \"checkout -b\" and \"switch/checkout --orphan\" complete the new\n> branch name the same way, but haven't done anything else.  I'd very\n> much appreciate to see the patches reviewed by those involved more\n> in the completion script, before we decide to merge the topic to\n> 'next'.\n\n\nIt is my intention to extend this series with a notion of reading the\nprevious word on the command line, and using that to determine if we\nare completing an argument for an option.\n\nThanks,\nJake\n"}]}