{"thread":{"id":"53571","subject":"[PATCH v3 10/16] completion: perform DWIM logic directly in __git_complete_refs","startedAt":"2020-05-28T18:10:56Z","lastAt":"2020-05-28T18:11:45Z","messageCount":17,"participants":["Jacob Keller"],"isPatch":true,"patchVersion":3,"patchTotal":16},"messages":[{"id":"398755","messageId":"20200528181048.3509470-11-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 10/16] completion: perform DWIM logic directly in __git_complete_refs","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:42Z","receivedAt":"2020-05-28T18:10:56Z","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 ffe3c499e1a4..5c13d2cd0fde 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":"398756","messageId":"20200528181048.3509470-9-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 08/16] completion: replace overloaded track term for __git_complete_refs","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:40Z","receivedAt":"2020-05-28T18:10: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\nThe __git_complete_refs uses the \"--track\" option to specify when to\nenable listing of unique remote branches which are used by the DWIM\nlogic of git checkout and git switch.\n\nUsing the term '--track' here is confusing because the git commands\nthemselves have '--track' as an argument. Additionally, the completion\nlogic for _git_switch also checks for --track. Keeping the meaning of\ntrack_opt and --track for __git_complete_refs straight from the --track\ngit switch and git checkout option is difficult when reading this code.\n\nUse the option '--dwim' instead, indicating this is about enabling or\ndisabling logic related to DWIM mode. Also rename the local variable\ntrack_opt to dwim_opt to further reduce the confusion when reading the\ncompletion code for _git_switch.\n\nBecause it is plausible for users to have developed their own\ncompletions which rely on __git_complete_ref, keep --track as a synonym\nfor --dwim, even though we no longer use it in any of the core git\ncompletion logic. Add a comment explaining why it remains as an\nalternative spelling for --dwim.\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 70ad04e1b2a8..2972df4cb4c9 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@@ -2226,27 +2228,27 @@ _git_switch ()\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 track_opt=\"--track\" only_local_ref=n\n+\t\tlocal dwim_opt=\"--dwim\" 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+\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":"398757","messageId":"20200528181048.3509470-10-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 09/16] completion: extract function __git_dwim_remote_heads","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:41Z","receivedAt":"2020-05-28T18:10:59Z","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 2972df4cb4c9..ffe3c499e1a4 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":"398758","messageId":"20200528181048.3509470-15-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 14/16] completion: improve handling of --track in switch/checkout","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:46Z","receivedAt":"2020-05-28T18:11: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\nCurrent completion for the --track option of git switch and git checkout\nis sub par. In addition to the DWIM logic of a bare branch name, --track\nhas DWIM logic to convert specified remote/branch names into a local\nbranch tracking that remote. For example\n\n  $git switch --track origin/master\n\nThis will create a local branch name master, that tracks the master\nbranch of the origin remote.\n\nIn fact, git switch --track on its own will not accept other forms of\nreferences. These must instead be specified manually via the -c/-C/-b/-B\noptions.\n\nIntroduce __git_remote_heads() and the \"remote-heads\" mode for\n__git_complete_refs. Use this when the --track option is provided while\ncompleting in _git_switch and _git_checkout. Just as in the --detach\ncase, we never enable DWIM mode for --track, because it doesn't make\nsense.\n\nIt should be noted that completion support is still a bit sub par when\nit comes to handling -c/-C and --orphan. This will be resolved in\na future change.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 24 ++++++++++++++++++++++--\n t/t9902-completion.sh                  |  6 ++----\n 2 files changed, 24 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 38b5a5a0d874..4cdf09987725 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, '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@@ -1492,6 +1508,8 @@ _git_checkout ()\n \n \t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"refs\"\n+\t\telif [ -n \"$(__git_find_on_cmdline \"--track\")\" ]; then\n+\t\t\t__git_complete_refs --mode=\"remote-heads\"\n \t\telse\n \t\t\t__git_complete_refs $dwim_opt --mode=\"refs\"\n \t\tfi\n@@ -2347,6 +2365,8 @@ _git_switch ()\n \n \t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"refs\"\n+\t\telif [ -n \"$(__git_find_on_cmdline \"--track\")\" ]; then\n+\t\t\t__git_complete_refs --mode=\"remote-heads\"\n \t\telse\n \t\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n \t\tfi\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 7e56a62a9bb3..f8319868080f 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1405,16 +1405,14 @@ test_expect_success 'git checkout - with -d, complete only references' '\n \tEOF\n '\n \n-#TODO: --track should only complete fully specified remote branches\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 \tEOF\n '\n \n-#TODO: --track should only complete fully specified remote branches\n-test_expect_failure 'git checkout - with --track, complete only remote branches' '\n+test_expect_success 'git checkout - with --track, complete only remote branches' '\n \ttest_completion \"git checkout --track \" <<-\\EOF\n \tother/branch-in-other Z\n \tother/master-in-other Z\n-- \n2.25.2\n\n"},{"id":"398759","messageId":"20200528181048.3509470-17-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 16/16] completion: improve handling of --orphan option of switch/checkout","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:48Z","receivedAt":"2020-05-28T18:11: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 --orphan option is used to create a local branch which is detached\nfrom the current history. In git switch, it always resets to the empty\ntree, and thus the only completion we can provide is a branch name.\nFollow the same rules for -c/-C (and -b/-B) when completing the argument\nto --orphan.\n\nIn the case of git switch, after we complete the argument, there is\nnothing more we can complete for git switch, so do not even try. Nothing\nelse would be valid.\n\nIn the case of git checkout, --orphan takes a start point which it uses\nto determine the checked out tree, even though it created orphaned\nhistory.\n\nUpdate the previously added test cases as they are now passing.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 21 ++++++++++++++-------\n t/t9902-completion.sh                  |  9 +++------\n 2 files changed, 17 insertions(+), 13 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 60666429dba4..de85b84f8116 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1508,7 +1508,7 @@ _git_checkout ()\n \t\tlocal prevword prevword=\"${words[cword-1]}\"\n \n \t\tcase \"$prevword\" in\n-\t\t\t-b|-B)\n+\t\t\t-b|-B|--orphan)\n \t\t\t\t# Complete local branches (and DWIM branch\n \t\t\t\t# remote branch names) for an option argument\n \t\t\t\t# specifying a new branch name. This is for\n@@ -1522,14 +1522,14 @@ _git_checkout ()\n \t\tesac\n \n \t\t# At this point, we've already handled special completion for\n-\t\t# the arguments to -b/-B. There are 3 main things left we can\n-\t\t# possibly complete:\n-\t\t# 1) a start-point for -b/-B or -d/--detach\n+\t\t# the arguments to -b/-B, and --orphan. There are 3 main\n+\t\t# things left we can possibly complete:\n+\t\t# 1) a start-point for -b/-B, -d/--detach, or --orphan\n \t\t# 2) a remote head, for --track\n \t\t# 3) an arbitrary reference, possibly including DWIM names\n \t\t#\n \n-\t\tif [ -n \"$(__git_find_on_cmdline \"-b -B -d --detach\")\" ]; then\n+\t\tif [ -n \"$(__git_find_on_cmdline \"-b -B -d --detach --orphan\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"refs\"\n \t\telif [ -n \"$(__git_find_on_cmdline \"--track\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"remote-heads\"\n@@ -2388,7 +2388,7 @@ _git_switch ()\n \t\tlocal prevword prevword=\"${words[cword-1]}\"\n \n \t\tcase \"$prevword\" in\n-\t\t\t-c|-C)\n+\t\t\t-c|-C|--orphan)\n \t\t\t\t# Complete local branches (and DWIM branch\n \t\t\t\t# remote branch names) for an option argument\n \t\t\t\t# specifying a new branch name. This is for\n@@ -2401,8 +2401,15 @@ _git_switch ()\n \t\t\t\t;;\n \t\tesac\n \n+\t\t# Unlike in git checkout, git switch --orphan does not take\n+\t\t# a start point. Thus we really have nothing to complete after\n+\t\t# the branch name.\n+\t\tif [ -n \"$(__git_find_on_cmdline \"--orphan\")\" ]; then\n+\t\t\treturn\n+\t\tfi\n+\n \t\t# At this point, we've already handled special completion for\n-\t\t# -c/-C. There are 3 main things left to\n+\t\t# -c/-C, and --orphan. There are 3 main things left to\n \t\t# complete:\n \t\t# 1) a start-point for -c/-C or -d/--detach\n \t\t# 2) a remote head, for --track\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 810661b10b33..d42b4191b9cb 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1670,15 +1670,13 @@ test_expect_success 'git switch - with --orphan completes local branch names and\n \tEOF\n '\n \n-#TODO: switch --orphan does not take a start-point and thus has nothing to complete\n-test_expect_failure 'git switch - --orphan with branch already provided completes nothing else' '\n+test_expect_success 'git switch - --orphan with branch already provided completes nothing else' '\n \ttest_completion \"git switch --orphan master \" <<-\\EOF\n \n \tEOF\n '\n \n-#TODO: --orphan argument completion should not include all references\n-test_expect_failure 'git checkout - with --orphan completes local branch names and unique remote branch names' '\n+test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' '\n \ttest_completion \"git checkout --orphan \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n@@ -1687,8 +1685,7 @@ test_expect_failure 'git checkout - with --orphan completes local branch names a\n \tEOF\n '\n \n-#TODO: checkout --orphan start-point completion should not included DWIM remote unique branch names\n-test_expect_failure 'git checkout - --orphan with branch already provided completes local refs for a start-point' '\n+test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' '\n \ttest_completion \"git checkout --orphan master \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"398760","messageId":"20200528181048.3509470-13-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 12/16] completion: improve completion for git switch with no options","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:44Z","receivedAt":"2020-05-28T18:11:06Z","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 and the remote unique branch names for DWIM.\n\nRefactor completion support to use the new mode option, rather than\ncalling __git_heads directly. This has the advantage that we can now\ncorrectly allow local branches along with suitable DWIM refs, rather\nthan only allowing DWIM when we complete all references.\n\nChoose what mode it uses when calling __git_complete_refs. If -d or\n--detach have been provided, then simply complete all refs, but\n*without* the DWIM option as these DWIM names won't work properly in\n--detach mode.\n\nOtherwise, call __git_complete_refs with the default dwim_opt value and\nuse the new \"heads\" mode.\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.\n\nThe basic no-options tests for git switch, as well as several of the\n-c/-C tests now pass, so remove the known breakage tags.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 33 ++++++++++++++++----------\n t/t9902-completion.sh                  | 19 ++++++---------\n 2 files changed, 27 insertions(+), 25 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 54cd676fdc9d..53afd72d0e4e 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, '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@@ -2325,18 +2338,12 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\n \t*)\n-\t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\" only_local_ref=n\n-\t\tif [ -z \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n-\t\t\tonly_local_ref=y\n+\t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n+\n+\t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n+\t\t\t__git_complete_refs --mode=\"refs\"\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+\t\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n \t\tfi\n \t\t;;\n \tesac\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 13d5a47e2912..f4f3a3ca3d55 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1240,8 +1240,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n \ttest_cmp expected out\n '\n \n-#TODO: git switch completion includes unexpected references\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@@ -1277,8 +1276,8 @@ test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, compl\n \tEOF\n '\n \n-#TODO: git switch completion includes unexpected references\n-test_expect_failure 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '\n+\n+test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '\n \tGIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion \"git switch --guess \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n@@ -1287,8 +1286,7 @@ test_expect_failure 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_G\n \tEOF\n '\n \n-#TODO: git switch completion includes unexpected references\n-test_expect_failure 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '\n+test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '\n \ttest_completion \"git switch --no-guess --guess \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n@@ -1585,8 +1583,7 @@ test_expect_success 'git checkout - with -B and --no-track, complete all referen\n \tEOF\n '\n \n-#TODO: -c/-C argument completion should not include all references\n-test_expect_failure 'git switch - for -c, complete local branches and unique remote branches' '\n+test_expect_success 'git switch - for -c, complete local branches and unique remote branches' '\n \ttest_completion \"git switch -c \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n@@ -1595,8 +1592,7 @@ test_expect_failure 'git switch - for -c, complete local branches and unique rem\n \tEOF\n '\n \n-#TODO: -c/-C argument completion should not include all references\n-test_expect_failure 'git switch - for -C, complete local branches and unique remote branches' '\n+test_expect_success 'git switch - for -C, complete local branches and unique remote branches' '\n \ttest_completion \"git switch -C \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n@@ -1685,8 +1681,7 @@ test_expect_failure 'git checkout - for -B with --no-track, complete local branc\n \tEOF\n '\n \n-#TODO: --orphan argument completion should not include all references\n-test_expect_failure 'git switch - with --orphan completes local branch names and unique remote branch names' '\n+test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' '\n \ttest_completion \"git switch --orphan \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"398761","messageId":"20200528181048.3509470-8-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 07/16] completion: add tests showing subpar switch/checkout --orphan logic","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:39Z","receivedAt":"2020-05-28T18:11:08Z","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\nSimilar to -c/-C, --orphan takes an argument which is the branch name to\nuse. We ought to complete this branch name using similar rules as to how\nwe complete new branch names for -c/-C and -b/-B. Namely, limit the\ntotal number of options provided by completing to the local branches.\n\nAdditionally, git switch --orphan does not take any start point and will\nalways create using the empty-tree. Thus, after the branch name is\ncompleted, git switch --orphan should not complete any references.\n\nAdd test cases showing the expected behavior of --orphan, for both the\nargument and starting point.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 39 +++++++++++++++++++++++++++++++++++++++\n 1 file changed, 39 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 63daf43b89ec..e4c48b20d39d 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1688,6 +1688,45 @@ test_expect_failure 'git checkout - for -B with --no-track, complete local branc\n \tEOF\n '\n \n+#TODO: --orphan argument completion should not include all references\n+test_expect_failure 'git switch - with --orphan completes local branch names and unique remote branch names' '\n+\ttest_completion \"git switch --orphan \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: switch --orphan does not take a start-point and thus has nothing to complete\n+test_expect_failure 'git switch - --orphan with branch already provided completes nothing else' '\n+\ttest_completion \"git switch --orphan master \" <<-\\EOF\n+\n+\tEOF\n+'\n+\n+#TODO: --orphan argument completion should not include all references\n+test_expect_failure 'git checkout - with --orphan completes local branch names and unique remote branch names' '\n+\ttest_completion \"git checkout --orphan \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: checkout --orphan start-point completion should not included DWIM remote unique branch names\n+test_expect_failure 'git checkout - --orphan with branch already provided completes local refs for a start-point' '\n+\ttest_completion \"git checkout --orphan master \" <<-\\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":"398762","messageId":"20200528181048.3509470-12-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 11/16] completion: improve handling of DWIM mode for switch/checkout","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:43Z","receivedAt":"2020-05-28T18:11:16Z","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\nA new helper, __git_find_last_on_cmdline is introduced, similar to the\nalready existing __git_find_on_cmdline, but which operates in reverse,\nfinding the *last* matching word of the provided wordlist.\n\nUse this in a new __git_checkout_default_dwim_mode() function that will\ndetermine when to enable listing of DWIM remote branches.\n\nThe __git_find_last_on_cmdline() function is used to determine which\n--guess or --no-guess is in effect. If either one is provided, then we\nunconditionally enable or disable the DWIM mode based on the last\nprovided option.\n\nIf neither --guess nor --no-guess is provided, then we check for\n--no-track, and finally for GIT_COMPLETION_CHECKOUT_NO_GUESS=1.\n\nThis function is then used in _git_switch and _git_checkout to improve\nthe handling for when we enable listing of these DWIM remote branches.\n\nThis new logic is more robust, as we will correctly identify superseded\noptions, and ensure that both _git_switch and _git_checkout enable DWIM\nin similar ways.\n\nWe can now update a few tests to indicate they pass. A few of the tests\npreviously added to highlight issues with the old DWIM logic still fail.\nThis is because of a separate issue related to the default completion\nbehavior of git switch, which will be addressed in a future change.\n\nAdditionally, due to this change, a few tests for the -b/-B handling of\ngit checkout now fail. This is a minor regression, and will be fixed by\na following change that improves the overall handling of -b/-B. Mark\nthese tests as known breakages for now.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 95 ++++++++++++++++++++------\n t/t9902-completion.sh                  | 17 ++---\n 2 files changed, 83 insertions(+), 29 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 5c13d2cd0fde..54cd676fdc9d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1135,6 +1135,40 @@ __git_find_on_cmdline ()\n \tdone\n }\n \n+# Similar to __git_find_on_cmdline, except that it loops backwards and thus\n+# prints the *last* word found. Useful for finding which of two options that\n+# supersede each other came last, such as \"--guess\" and \"--no-guess\".\n+#\n+# Usage: __git_find_last_on_cmdline [<option>]... \"<wordlist>\"\n+# --show-idx: Optionally show the index of the found word in the $words array.\n+__git_find_last_on_cmdline ()\n+{\n+\tlocal word c=$cword show_idx\n+\n+\twhile test $# -gt 1; do\n+\t\tcase \"$1\" in\n+\t\t--show-idx)\tshow_idx=y ;;\n+\t\t*)\t\treturn 1 ;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+\tlocal wordlist=\"$1\"\n+\n+\twhile [ $c -gt 1 ]; do\n+\t\t((c--))\n+\t\tfor word in $wordlist; do\n+\t\t\tif [ \"$word\" = \"${words[c]}\" ]; then\n+\t\t\t\tif [ -n \"$show_idx\" ]; then\n+\t\t\t\t\techo \"$c $word\"\n+\t\t\t\telse\n+\t\t\t\t\techo \"$word\"\n+\t\t\t\tfi\n+\t\t\t\treturn\n+\t\t\tfi\n+\t\tdone\n+\tdone\n+}\n+\n # Echo the value of an option set on the command line or config\n #\n # $1: short option name\n@@ -1389,6 +1423,46 @@ _git_bundle ()\n \tesac\n }\n \n+# Helper function to decide whether or not we should enable DWIM logic for\n+# git-switch and git-checkout.\n+#\n+# To decide between the following rules in priority order\n+# 1) the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n+#    disable completion of DWIM logic respectively.\n+# 2) If the --no-track option is provided, take this as a hint to disable the\n+#    DWIM completion logic\n+# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n+#    logic, as requested by the user.\n+# 4) Enable DWIM logic otherwise.\n+#\n+__git_checkout_default_dwim_mode ()\n+{\n+\tlocal last_option dwim_opt=\"--dwim\"\n+\n+\tif [ \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" = \"1\" ]; then\n+\t\tdwim_opt=\"\"\n+\tfi\n+\n+\t# --no-track disables DWIM, but with lower priority than\n+\t# --guess/--no-guess\n+\tif [ -n \"$(__git_find_on_cmdline \"--no-track\")\" ]; then\n+\t\tdwim_opt=\"\"\n+\tfi\n+\n+\t# Find the last provided --guess or --no-guess\n+\tlast_option=\"$(__git_find_last_on_cmdline \"--guess --no-guess\")\"\n+\tcase \"$last_option\" in\n+\t\t--guess)\n+\t\t\tdwim_opt=\"--dwim\"\n+\t\t\t;;\n+\t\t--no-guess)\n+\t\t\tdwim_opt=\"\"\n+\t\t\t;;\n+\tesac\n+\n+\techo \"$dwim_opt\"\n+}\n+\n _git_checkout ()\n {\n \t__git_has_doubledash && return\n@@ -1401,13 +1475,7 @@ _git_checkout ()\n \t\t__gitcomp_builtin checkout\n \t\t;;\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\" 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\tdwim_opt=''\n-\t\tfi\n+\t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n \t\t__git_complete_refs $dwim_opt\n \t\t;;\n \tesac\n@@ -2257,18 +2325,7 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\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 dwim_opt=\"--dwim\" 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\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-\t\tfi\n+\t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\" only_local_ref=n\n \t\tif [ -z \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n \t\t\tonly_local_ref=y\n \t\telse\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex e4c48b20d39d..13d5a47e2912 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1277,7 +1277,6 @@ test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, compl\n \tEOF\n '\n \n-#TODO: --guess/--no-guess ordering is not taken into account\n #TODO: git switch completion includes unexpected references\n test_expect_failure 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '\n \tGIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion \"git switch --guess \" <<-\\EOF\n@@ -1288,7 +1287,6 @@ test_expect_failure 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_G\n \tEOF\n '\n \n-#TODO: --guess/--no-guess ordering is not taken into account\n #TODO: git switch completion includes unexpected references\n test_expect_failure 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '\n \ttest_completion \"git switch --no-guess --guess \" <<-\\EOF\n@@ -1299,8 +1297,7 @@ test_expect_failure 'git switch - a later --guess overrides previous --no-guess,\n \tEOF\n '\n \n-#TODO: --guess/--no-guess ordering is not taken into account\n-test_expect_failure 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '\n+test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '\n \ttest_completion \"git switch --guess --no-guess \" <<-\\EOF\n \tmaster Z\n \tmatching-branch Z\n@@ -1318,8 +1315,7 @@ test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only complete\n \tEOF\n '\n \n-#TODO: git checkout does not override variable when --guess is provided\n-test_expect_failure 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '\n+test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '\n \tGIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion \"git checkout --guess \" <<-\\EOF\n \tHEAD Z\n \tbranch-in-other Z\n@@ -1343,8 +1339,7 @@ test_expect_success 'git checkout - with --no-guess, only completes refs' '\n \tEOF\n '\n \n-#TODO: --guess/--no-guess ordering is not taken into account\n-test_expect_failure 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '\n+test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '\n \ttest_completion \"git checkout --no-guess --guess \" <<-\\EOF\n \tHEAD Z\n \tbranch-in-other Z\n@@ -1544,7 +1539,8 @@ test_expect_failure 'git checkout - with -B, complete all references' '\n \tEOF\n '\n \n-test_expect_success 'git checkout - with -b and --track, complete all references' '\n+#TODO: completing the start point of -b/-B should not include DWIM references\n+test_expect_failure 'git checkout - with -b and --track, complete all references' '\n \ttest_completion \"git checkout -b new-branch --track \" <<-EOF\n \tHEAD Z\n \tmaster Z\n@@ -1555,7 +1551,8 @@ test_expect_success 'git checkout - with -b and --track, complete all references\n \tEOF\n '\n \n-test_expect_success 'git checkout - with -B and --track, complete all references' '\n+#TODO: completing the start point of -b/-B should not include DWIM references\n+test_expect_failure 'git checkout - with -B and --track, complete all references' '\n \ttest_completion \"git checkout -B new-branch --track \" <<-EOF\n \tHEAD Z\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"398763","messageId":"20200528181048.3509470-4-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 03/16] completion: add tests showing subar checkout --detach logic","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:35Z","receivedAt":"2020-05-28T18:11:18Z","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\nWhen completing words for git switch, the completion function correctly\ndisables the DWIM remote branch names when in the '--detach' mode. These\nDWIM remote branch names will not work when the --detach option is\nspecified, so it does not make sense to complete them.\n\ngit checkout, however, does not disable the completion of DWIM remote\nbranch names in this case.\n\nAdd test cases for both git switch and git checkout showing the expected\nbehavior.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 46 +++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 46 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex ff234dee4da9..01aba598e7fc 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1368,6 +1368,52 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues\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+#TODO: checkout --detach incorrectly includes DWIM remote branch names\n+test_expect_failure 'git checkout - with --detach, complete only references' '\n+\ttest_completion \"git checkout --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 -d, complete all references' '\n+\ttest_completion \"git switch -d \" <<-\\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: checkout -d incorrectly includes DWIM remote branch names\n+test_expect_failure 'git checkout - with -d, complete only references' '\n+\ttest_completion \"git checkout -d \" <<-\\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":"398764","messageId":"20200528181048.3509470-5-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 04/16] completion: add tests showing subpar switch/checkout --track logic","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:36Z","receivedAt":"2020-05-28T18:11:19Z","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\nWhen the --track option is provided to git switch or git checkout, and\nno branch is specified by -c or -b, git will interpret the tracking\nbranch to determine the local branch name to use. This \"Do What I Mean\"\nlogic is similar but distinct from the default DWIM logic of\ninterpreting a unique remote branch name as a request to create and\ntrack that branch.\n\nFor example, `git switch --track origin/master` is interpreted as\na request to create a local branch named master that is tracking\norigin/master.\n\nThe current completion for git checkout in this regard is only somewhat\npoor:\n\n $git checkout --track <TAB>\n HEAD\n master\n matching-branch\n matching-tag\n other/branch-in-other\n other/master-in-other\n\nAt least it still includes remote references. The clutter from including\nall references isn't too bad.\n\nHowever, git switch completion is terrible:\n\n $git switch --track <TAB>\n master\n matching-branch\n\nIt only shows local branches, not even allowing any form of completion\nof the remote references!\n\nAdd tests which highlight the expected behavior of completing --track on\nits own.\n\nNote that when -c/-C or -b/-B are provided we do expect completing more\nreferences, but this will be discussed in a future change that addresses\nthese options specifically.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 34 ++++++++++++++++++++++++++++++++++\n 1 file changed, 34 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 01aba598e7fc..8a3995f82f38 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1414,6 +1414,40 @@ test_expect_failure 'git checkout - with -d, complete only references' '\n \tEOF\n '\n \n+#TODO: --track should only complete fully specified remote branches\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+#TODO: --track should only complete fully specified remote branches\n+test_expect_failure 'git checkout - with --track, complete only remote branches' '\n+\ttest_completion \"git checkout --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+\tmatching-branch Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - with --no-track, complete only local references' '\n+\ttest_completion \"git checkout --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":"398765","messageId":"20200528181048.3509470-3-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 02/16] completion: add tests showing subpar DWIM logic for switch/checkout","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:34Z","receivedAt":"2020-05-28T18:11:22Z","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\nWhen provided with a single argument that is the name of a remote branch\nthat does not yet exist locally, both git switch and git checkout can\ninterpret this as a request to create a local branch that tracks that\nremote branch. We call this behavior \"Do What I Mean\", or DWIM for\nshort.\n\nTo aid in using this DWIM, it makes sense for completion to list these\nunique remote branch names when completing possible arguments for git\nswitch and git checkout. Indeed, both _git_checkout and _git_switch\nimplement support for completing such DWIM branch names.\n\nIn other words, in addition to the usual completions provided for git\nswitch, this \"DWIM\" logic means completion will include the names of\nbranches on remotes that are unique and thus there can be no ambiguity\nof which remote to track when creating the local branch.\n\nHowever, the DWIM logic is not always active. Many options, such as\n--no-guess, --no-track, and --track disable this DWIM logic, as they\ncause git switch and git checkout to behave in different modes.\n\nAdditionally, some completion users do not wish to have tab completion\ninclude these remote names by default, and thus introduced\nGIT_COMPLETION_CHECKOUT_NO_GUESS as an optional way to configure the\ncompletion support to disable this feature of completion support.\n\nFor this reason, _git_checkout and _git_switch have many rules about\nwhen to enable or disable completing of these remote refs. The two\ncommands follow similar but not identical rules.\n\nSet aside the question of command modes that do not accept this DWIM\nlogic (--track, -c, --orphan, --detach) for now. Thinking just about the\nmain mode of git checkout and git switch, the following guidelines will\nhelp explain the basic rules we ought to support when deciding whether\nto list the remote branches for DWIM in completion.\n\n1.  if --guess is enabled, we should list DWIM remote branch names, even\n    if something else would disable it\n2.  if --no-guess, --no-track or GIT_COMPLETION_CHECKOUT_NO_GUESS=1,\n    then we should disable listing DWIM remote branch names.\n3.  Since the '--guess' option is a boolean option, a later --guess\n    should override --no-guess, and a later --no-guess should override\n    --guess.\n\nPutting all of these together, add some tests that highlight the\nexpected behavior of this DWIM logic.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 105 ++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 105 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 8f25fd24b43e..ff234dee4da9 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1263,6 +1263,111 @@ test_expect_success 'git checkout - completes refs and unique remote branches fo\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+\tmatching-branch Z\n+\tEOF\n+'\n+\n+test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' '\n+\tGIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion \"git switch \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: --guess/--no-guess ordering is not taken into account\n+#TODO: git switch completion includes unexpected references\n+test_expect_failure 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '\n+\tGIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion \"git switch --guess \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: --guess/--no-guess ordering is not taken into account\n+#TODO: git switch completion includes unexpected references\n+test_expect_failure 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '\n+\ttest_completion \"git switch --no-guess --guess \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: --guess/--no-guess ordering is not taken into account\n+test_expect_failure 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '\n+\ttest_completion \"git switch --guess --no-guess \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' '\n+\tGIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion \"git checkout \" <<-\\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 checkout does not override variable when --guess is provided\n+test_expect_failure 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '\n+\tGIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion \"git checkout --guess \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other 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 checkout - with --no-guess, only completes refs' '\n+\ttest_completion \"git checkout --no-guess \" <<-\\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: --guess/--no-guess ordering is not taken into account\n+test_expect_failure 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '\n+\ttest_completion \"git checkout --no-guess --guess \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other 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 checkout - a later --no-guess overrides previous --guess, complete only refs' '\n+\ttest_completion \"git checkout --guess --no-guess \" <<-\\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":"398766","messageId":"20200528181048.3509470-2-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 01/16] completion: add test showing subpar git switch completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:33Z","receivedAt":"2020-05-28T18:11:23Z","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\nWhen provided with no options, git switch only allows switching between\nbranches. The one exception to this is the \"Do What I Mean\" logic that\nallows a unique remote branch name to be interpreted as a request to\ncreate a branch of the same name that is tracking that remote branch.\n\nUnfortunately, the logic for the completion of git switch results in\ncompleting not just branch names, but also pseudorefs like HEAD, tags,\nand fully specified <remote>/<branch> references.\n\nFor example, we currently complete the following:\n\n $git switch <TAB>\n HEAD\n branch-in-other\n master\n master-in-other\n matching-branch\n matching-tag\n other/branch-in-other\n other/master-in-other\n\nIndeed, if one were to attempt to use git switch with some of these\nprovided options, git will reject the request:\n\n $git switch HEAD\n fatal: a branch is expected, got 'HEAD\n\n $git switch matching-tag\n fatal: a branch is expected, got tag 'matching-tag'\n\n $git switch other/branch-in-other\n fatal: a branch is expected, got remote branch 'other/branch-in-other'\n\nIdeally, git switch without options ought to complete only words which\nwill be accepted. Without options, this means to list local branch names\nand the unique remote branch names without their remote name pre-pended.\n\n $git switch <TAB>\n branch-in-other\n master\n master-in-other\n matching-branch\n\nAdd a test case that highlights this subpar completion. Also add\na similar test for git checkout completion that shows that due to the\ncomplex nature of git checkout, it must complete all references.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 23 +++++++++++++++++++++++\n 1 file changed, 23 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 3c44af694015..8f25fd24b43e 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1240,6 +1240,29 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n \ttest_cmp expected out\n '\n \n+#TODO: git switch completion includes unexpected references\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 checkout - completes refs and unique remote branches for DWIM' '\n+\ttest_completion \"git checkout \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other 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":"398767","messageId":"20200528181048.3509470-14-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 13/16] completion: improve handling of --detach in checkout","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:45Z","receivedAt":"2020-05-28T18:11:26Z","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\nJust like git switch, we should not complete DWIM remote branch names\nif --detach has been specified. To avoid this, refactor _git_checkout in\na similar way to _git_switch.\n\nNote that we don't simply clear dwim_opt when we find -d or --detach, as\nwe will be adding other modes and checks, making this flow easier to\nfollow.\n\nUpdate the previously failing tests to show that the breakage has been\nresolved.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 7 ++++++-\n t/t9902-completion.sh                  | 6 ++----\n 2 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 53afd72d0e4e..38b5a5a0d874 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1489,7 +1489,12 @@ _git_checkout ()\n \t\t;;\n \t*)\n \t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n-\t\t__git_complete_refs $dwim_opt\n+\n+\t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n+\t\t\t__git_complete_refs --mode=\"refs\"\n+\t\telse\n+\t\t\t__git_complete_refs $dwim_opt --mode=\"refs\"\n+\t\tfi\n \t\t;;\n \tesac\n }\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex f4f3a3ca3d55..7e56a62a9bb3 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1372,8 +1372,7 @@ test_expect_success 'git switch - with --detach, complete all references' '\n \tEOF\n '\n \n-#TODO: checkout --detach incorrectly includes DWIM remote branch names\n-test_expect_failure 'git checkout - with --detach, complete only references' '\n+test_expect_success 'git checkout - with --detach, complete only references' '\n \ttest_completion \"git checkout --detach \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n@@ -1395,8 +1394,7 @@ test_expect_success 'git switch - with -d, complete all references' '\n \tEOF\n '\n \n-#TODO: checkout -d incorrectly includes DWIM remote branch names\n-test_expect_failure 'git checkout - with -d, complete only references' '\n+test_expect_success 'git checkout - with -d, complete only references' '\n \ttest_completion \"git checkout -d \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n-- \n2.25.2\n\n"},{"id":"398768","messageId":"20200528181048.3509470-6-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 05/16] completion: add tests showing subpar -c/-C startpoint completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:37Z","receivedAt":"2020-05-28T18:11:34Z","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\nWhen using the branch creation argument for git switch or git checkout,\n-c/-C or -b/-B, the commands operate in a different mode: `git switch -c\n<branch> <some-reference>` means to create a branch named <branch> at\nthe commit referred to by <some-reference>.\n\nWhen completing the start-point, we ought to always complete all valid\nreferences.\n\nAdd tests for the completion of the start-point to -c/-C and -b/-B.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 140 ++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 140 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 8a3995f82f38..609981244e9b 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1448,6 +1448,146 @@ test_expect_success 'git checkout - with --no-track, complete only local referen\n \tEOF\n '\n \n+#TODO: completing the start point of -c/-C should not include DWIM references\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: completing the start point of -c/-C should not include DWIM references\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: completing the start point of -c/-C should include all references, not just local branches\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: completing the start point of -c/-C should include all references, not just local branches\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: completing the start point of -c/-C should include all references, not just local branches\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+#TODO: completing the start point of -c/-C should include all references, not just local branches\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+#TODO: completing the start point of -b/-B should not include DWIM references\n+test_expect_failure 'git checkout - with -b, complete all references' '\n+\ttest_completion \"git checkout -b 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: completing the start point of -b/-B should not include DWIM references\n+test_expect_failure 'git checkout - with -B, complete all references' '\n+\ttest_completion \"git checkout -B 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_success 'git checkout - with -b and --track, complete all references' '\n+\ttest_completion \"git checkout -b 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+test_expect_success 'git checkout - with -B and --track, complete all references' '\n+\ttest_completion \"git checkout -B 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+test_expect_success 'git checkout - with -b and --no-track, complete all references' '\n+\ttest_completion \"git checkout -b 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 'git checkout - with -B and --no-track, complete all references' '\n+\ttest_completion \"git checkout -B 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":"398769","messageId":"20200528181048.3509470-7-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 06/16] completion: add tests showing subpar -c/C argument completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:38Z","receivedAt":"2020-05-28T18:11:37Z","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\nWhen using the branch creation argument for git switch or git checkout\n(-c/-C or -b/-B), the commands switch to a different mode: `git switch\n-c <branch> <some-referance>` means to create a branch named <branch> at\nthe commit referred to by <some-reference>.\n\nWhen completing git switch or git checkout, it makes sense to complete\nthe branch name differently from the start point.\n\nWhen completing a branch, one might consider that we do not have\nanything worth completing. After all, a new branch must have an entirely\nnew name. Consider, however, that if a user names branches using some\nsimilar scheme, they might wish to name a new branch by modifying the\nname of an existing branch.\n\nTo avoid overloading completion for the argument, it seems reasonable to\ncomplete only the local branch names and the valid \"Do What I Mean\"\nremote branch names.\n\nAdd tests for the completion of the argument to -c/-C and -b/-B,\nhighlighting this preferred completion behavior.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9902-completion.sh | 100 ++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 100 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 609981244e9b..63daf43b89ec 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1588,6 +1588,106 @@ test_expect_success 'git checkout - with -B and --no-track, complete all referen\n \tEOF\n '\n \n+#TODO: -c/-C argument completion should not include all references\n+test_expect_failure 'git switch - for -c, complete local branches and unique remote branches' '\n+\ttest_completion \"git switch -c \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: -c/-C argument completion should not include all references\n+test_expect_failure 'git switch - for -C, complete local branches and unique remote branches' '\n+\ttest_completion \"git switch -C \" <<-\\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 - for -c with --no-guess, complete local branches only' '\n+\ttest_completion \"git switch --no-guess -c \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '\n+\ttest_completion \"git switch --no-guess -C \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+test_expect_success 'git switch - for -c with --no-track, complete local branches only' '\n+\ttest_completion \"git switch --no-track -c \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+test_expect_success 'git switch - for -C with --no-track, complete local branches only' '\n+\ttest_completion \"git switch --no-track -C \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: -b/-B argument completion should not include all references\n+test_expect_failure 'git checkout - for -b, complete local branches and unique remote branches' '\n+\ttest_completion \"git checkout -b \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: -b/-B argument completion should not include all references\n+test_expect_failure 'git checkout - for -B, complete local branches and unique remote branches' '\n+\ttest_completion \"git checkout -B \" <<-\\EOF\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: -b/-B argument completion should not include all references\n+test_expect_failure 'git checkout - for -b with --no-guess, complete local branches only' '\n+\ttest_completion \"git checkout --no-guess -b \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: -b/-B argument completion should not include all references\n+test_expect_failure 'git checkout - for -B with --no-guess, complete local branches only' '\n+\ttest_completion \"git checkout --no-guess -B \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: -b/-B argument completion should not include all references\n+test_expect_failure 'git checkout - for -b with --no-track, complete local branches only' '\n+\ttest_completion \"git checkout --no-track -b \" <<-\\EOF\n+\tmaster Z\n+\tmatching-branch Z\n+\tEOF\n+'\n+\n+#TODO: -b/-B argument completion should not include all references\n+test_expect_failure 'git checkout - for -B with --no-track, complete local branches only' '\n+\ttest_completion \"git checkout --no-track -B \" <<-\\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":"398770","messageId":"20200528181048.3509470-1-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":null,"subject":"[PATCH v3 00/16] improve switch/checkout completion","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:32Z","receivedAt":"2020-05-28T18:11:44Z","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\nRecently I noticed that the completion support for git switch is subpar, and\ncan lead to frustrating moments. Specifically the difference between\ncompleting `git switch` vs `git switch --track`:\n\n  $git switch <TAB>\n  Display all 784 possibilities? (y or n)\n  <list of all references and DWIM remotes>\n\nNotice that git switch will complete basically all references, including\nthings like HEAD, and remote references like \"origin/master\". Many of these\nvalues are useless and clutter the output. It's not too bad, but could be\nsomewhat improved. At least it still completes useful words.\n\nHowever, the same cannot be said for --track:\n\n  $git switch --track<TAB>\n  jk-refactor-git-switch-completion master\n\nNotice that with --track, we suddenly start completing only local branches.\nNot only does this severely limit what we complete, it includes *only*\nuseless words. This leads to incredibly frustrating moments, as I often use\n\"git switch --track remote/<TAB>\" to create tracking branches. I found\nmyself often having to backspace --track just to complete what I wanted and\nthen re-add it.\n\nThe primary original motivation of this series was to improve the handling\nof track. Several other issues were discovered, and I attempt to improve\npretty much every mode of switch.\n\nThe first few patches simply add new test cases, most of which fail. This is\ndone in order to give time to fully explain what I believe is deficient\nabout the specific case.\n\nFollowing these patches are some cleanup improvements to remove some\nconfusing terminology and introduce new functions that will be useful to\nimprove the completion functions.\n\nFinally, several patches which improve completion follow. By the end,\ncompletion for both git switch and git checkout should be more useful and\nmore aware of the intention of the current argument being completed.\n\nA patch to initially fix just the --track behavior was posted at\nhttps://lore.kernel.org/git/20200422201541.3766173-1-jacob.e.keller@intel.com/\n\nThis original patch was reviewed by Jonathan Nieder, and he suggested\nfurther improvements, which led to v1 of this series\nhttps://lore.kernel.org/git/20200425022045.1089291-1-jacob.e.keller@intel.com/\n\nThis was further reviewed, and some issues with the handling of completing\nthe argument to -c/-C were brought up by Junio, which I then improved in v2\nhttps://lore.kernel.org/git/20200527113831.3294409-1-jacob.e.keller@intel.com/\n\nJunio mentioned that the commit messages for this v2 series were difficult\nto follow. I have split the tests from the implementation patches and\nre-written the commit messages. Hopefully this now better highlights the\nplaces where completion isn't behaving as I would expect.\n\nOnce again, given the nature of the rework I did not find a suitable\nrange-diff that expressed the evolution from v2 to v3, so I haven't included\nit here.\n\nI would really like opinions on whether the suggested -c/-C argument\ncompletion makes sense. I opted to limit it to complete local branch names,\nand optionally the unique remote branch names. I'm open to alternative\nsuggestions if anyone has a better suggestion? I had thought perhaps also\nsome users might wish to see tags, if they have branches named after tags or\nsimilar.. I don't think completing all references makes sense: branches with\nremote prefixes in their name would be confusing.\n\nJacob Keller (16):\n  completion: add test showing subpar git switch completion\n  completion: add tests showing subpar DWIM logic for switch/checkout\n  completion: add tests showing subar checkout --detach logic\n  completion: add tests showing subpar switch/checkout --track logic\n  completion: add tests showing subpar -c/-C startpoint completion\n  completion: add tests showing subpar -c/C argument completion\n  completion: add tests showing subpar switch/checkout --orphan logic\n  completion: replace overloaded track term for __git_complete_refs\n  completion: extract function __git_dwim_remote_heads\n  completion: perform DWIM logic directly in __git_complete_refs\n  completion: improve handling of DWIM mode for switch/checkout\n  completion: improve completion for git switch with no options\n  completion: improve handling of --detach in checkout\n  completion: improve handling of --track in switch/checkout\n  completion: improve handling of -c/-C and -b/-B in switch/checkout\n  completion: improve handling of --orphan option of switch/checkout\n\n contrib/completion/git-completion.bash | 252 +++++++++++---\n t/t9902-completion.sh                  | 456 +++++++++++++++++++++++++\n 2 files changed, 669 insertions(+), 39 deletions(-)\n\n-- \n2.25.2\n"},{"id":"398771","messageId":"20200528181048.3509470-16-jacob.e.keller@intel.com","threadId":"53571","inReplyTo":"20200528181048.3509470-1-jacob.e.keller@intel.com","subject":"[PATCH v3 15/16] completion: improve handling of -c/-C and -b/-B in switch/checkout","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-05-28T18:10:47Z","receivedAt":"2020-05-28T18:11:45Z","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\nA previous commit added several test cases highlighting the subpar\ncompletion logic for -c/-C and -b/-B when completing git switch and git\ncheckout.\n\nIn order to distinguish completing the argument vs the start-point for\nthis option, we now use the wordlist to determine the previous full word\non the command line.\n\nIf it's -c or -C (-b/-B for checkout), then we know that we are\ncompleting the argument for the branch name.\n\nGiven that a user who already knows the branch name they want to\ncomplete will simply not use completion, it makes sense to complete the\nsmall subset of local branches when completing the argument for -c/-C.\n\nIn all other cases, if -c/-C are on the command line but are not the\nmost recent option, then we must be completing a start-point, and should\nallow completing against all references.\n\nUpdate the -c/-C and -b/-B tests to indicate they now pass.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n contrib/completion/git-completion.bash | 49 ++++++++++++++++++++++++--\n t/t9902-completion.sh                  | 48 +++++++++----------------\n 2 files changed, 63 insertions(+), 34 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 4cdf09987725..60666429dba4 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1505,8 +1505,31 @@ _git_checkout ()\n \t\t;;\n \t*)\n \t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n+\t\tlocal prevword prevword=\"${words[cword-1]}\"\n \n-\t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n+\t\tcase \"$prevword\" in\n+\t\t\t-b|-B)\n+\t\t\t\t# Complete local branches (and DWIM branch\n+\t\t\t\t# remote branch names) for an option argument\n+\t\t\t\t# specifying a new branch name. This is for\n+\t\t\t\t# convenience, assuming new branches are\n+\t\t\t\t# possibly based on pre-existing branch names.\n+\t\t\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n+\t\t\t\treturn\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\t;;\n+\t\tesac\n+\n+\t\t# At this point, we've already handled special completion for\n+\t\t# the arguments to -b/-B. There are 3 main things left we can\n+\t\t# possibly complete:\n+\t\t# 1) a start-point for -b/-B or -d/--detach\n+\t\t# 2) a remote head, for --track\n+\t\t# 3) an arbitrary reference, possibly including DWIM names\n+\t\t#\n+\n+\t\tif [ -n \"$(__git_find_on_cmdline \"-b -B -d --detach\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"refs\"\n \t\telif [ -n \"$(__git_find_on_cmdline \"--track\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"remote-heads\"\n@@ -2362,8 +2385,30 @@ _git_switch ()\n \t\t;;\n \t*)\n \t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n+\t\tlocal prevword prevword=\"${words[cword-1]}\"\n \n-\t\tif [ -n \"$(__git_find_on_cmdline \"-d --detach\")\" ]; then\n+\t\tcase \"$prevword\" in\n+\t\t\t-c|-C)\n+\t\t\t\t# Complete local branches (and DWIM branch\n+\t\t\t\t# remote branch names) for an option argument\n+\t\t\t\t# specifying a new branch name. This is for\n+\t\t\t\t# convenience, assuming new branches are\n+\t\t\t\t# possibly based on pre-existing branch names.\n+\t\t\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n+\t\t\t\treturn\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\t;;\n+\t\tesac\n+\n+\t\t# At this point, we've already handled special completion for\n+\t\t# -c/-C. There are 3 main things left to\n+\t\t# complete:\n+\t\t# 1) a start-point for -c/-C or -d/--detach\n+\t\t# 2) a remote head, for --track\n+\t\t# 3) a branch name, possibly including DWIM remote branches\n+\n+\t\tif [ -n \"$(__git_find_on_cmdline \"-c -C -d --detach\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"refs\"\n \t\telif [ -n \"$(__git_find_on_cmdline \"--track\")\" ]; then\n \t\t\t__git_complete_refs --mode=\"remote-heads\"\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex f8319868080f..810661b10b33 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1437,8 +1437,7 @@ test_expect_success 'git checkout - with --no-track, complete only local referen\n \tEOF\n '\n \n-#TODO: completing the start point of -c/-C should not include DWIM references\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@@ -1449,8 +1448,7 @@ test_expect_failure 'git switch - with -c, complete all references' '\n \tEOF\n '\n \n-#TODO: completing the start point of -c/-C should not include DWIM references\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@@ -1461,8 +1459,7 @@ test_expect_failure 'git switch - with -C, complete all references' '\n \tEOF\n '\n \n-#TODO: completing the start point of -c/-C should include all references, not just local branches\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@@ -1473,8 +1470,7 @@ test_expect_failure 'git switch - with -c and --track, complete all references'\n \tEOF\n '\n \n-#TODO: completing the start point of -c/-C should include all references, not just local branches\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@@ -1485,8 +1481,7 @@ test_expect_failure 'git switch - with -C and --track, complete all references'\n \tEOF\n '\n \n-#TODO: completing the start point of -c/-C should include all references, not just local branches\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@@ -1497,8 +1492,7 @@ test_expect_failure 'git switch - with -c and --no-track, complete all reference\n \tEOF\n '\n \n-#TODO: completing the start point of -c/-C should include all references, not just local branches\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@@ -1509,8 +1503,7 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference\n \tEOF\n '\n \n-#TODO: completing the start point of -b/-B should not include DWIM references\n-test_expect_failure 'git checkout - with -b, complete all references' '\n+test_expect_success 'git checkout - with -b, complete all references' '\n \ttest_completion \"git checkout -b new-branch \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n@@ -1521,8 +1514,7 @@ test_expect_failure 'git checkout - with -b, complete all references' '\n \tEOF\n '\n \n-#TODO: completing the start point of -b/-B should not include DWIM references\n-test_expect_failure 'git checkout - with -B, complete all references' '\n+test_expect_success 'git checkout - with -B, complete all references' '\n \ttest_completion \"git checkout -B new-branch \" <<-\\EOF\n \tHEAD Z\n \tmaster Z\n@@ -1533,8 +1525,7 @@ test_expect_failure 'git checkout - with -B, complete all references' '\n \tEOF\n '\n \n-#TODO: completing the start point of -b/-B should not include DWIM references\n-test_expect_failure 'git checkout - with -b and --track, complete all references' '\n+test_expect_success 'git checkout - with -b and --track, complete all references' '\n \ttest_completion \"git checkout -b new-branch --track \" <<-EOF\n \tHEAD Z\n \tmaster Z\n@@ -1545,8 +1536,7 @@ test_expect_failure 'git checkout - with -b and --track, complete all references\n \tEOF\n '\n \n-#TODO: completing the start point of -b/-B should not include DWIM references\n-test_expect_failure 'git checkout - with -B and --track, complete all references' '\n+test_expect_success 'git checkout - with -B and --track, complete all references' '\n \ttest_completion \"git checkout -B new-branch --track \" <<-EOF\n \tHEAD Z\n \tmaster Z\n@@ -1625,8 +1615,7 @@ test_expect_success 'git switch - for -C with --no-track, complete local branche\n \tEOF\n '\n \n-#TODO: -b/-B argument completion should not include all references\n-test_expect_failure 'git checkout - for -b, complete local branches and unique remote branches' '\n+test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '\n \ttest_completion \"git checkout -b \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n@@ -1635,8 +1624,7 @@ test_expect_failure 'git checkout - for -b, complete local branches and unique r\n \tEOF\n '\n \n-#TODO: -b/-B argument completion should not include all references\n-test_expect_failure 'git checkout - for -B, complete local branches and unique remote branches' '\n+test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '\n \ttest_completion \"git checkout -B \" <<-\\EOF\n \tbranch-in-other Z\n \tmaster Z\n@@ -1645,32 +1633,28 @@ test_expect_failure 'git checkout - for -B, complete local branches and unique r\n \tEOF\n '\n \n-#TODO: -b/-B argument completion should not include all references\n-test_expect_failure 'git checkout - for -b with --no-guess, complete local branches only' '\n+test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' '\n \ttest_completion \"git checkout --no-guess -b \" <<-\\EOF\n \tmaster Z\n \tmatching-branch Z\n \tEOF\n '\n \n-#TODO: -b/-B argument completion should not include all references\n-test_expect_failure 'git checkout - for -B with --no-guess, complete local branches only' '\n+test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' '\n \ttest_completion \"git checkout --no-guess -B \" <<-\\EOF\n \tmaster Z\n \tmatching-branch Z\n \tEOF\n '\n \n-#TODO: -b/-B argument completion should not include all references\n-test_expect_failure 'git checkout - for -b with --no-track, complete local branches only' '\n+test_expect_success 'git checkout - for -b with --no-track, complete local branches only' '\n \ttest_completion \"git checkout --no-track -b \" <<-\\EOF\n \tmaster Z\n \tmatching-branch Z\n \tEOF\n '\n \n-#TODO: -b/-B argument completion should not include all references\n-test_expect_failure 'git checkout - for -B with --no-track, complete local branches only' '\n+test_expect_success 'git checkout - for -B with --no-track, complete local branches only' '\n \ttest_completion \"git checkout --no-track -B \" <<-\\EOF\n \tmaster Z\n \tmatching-branch Z\n-- \n2.25.2\n\n"}]}