{"thread":{"id":"45759","subject":"[PATCH] completion: optionally disable checkout DWIM","startedAt":"2017-04-20T20:13:58Z","lastAt":"2017-04-24T16:30:54Z","messageCount":10,"participants":["Jeff King","Junio C Hamano","Jacob Keller","SZEDER Gábor","Brandon Williams"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"317370","messageId":"20170420201229.fxiylgp2v2v4sz3w@sigill.intra.peff.net","threadId":"45759","inReplyTo":null,"subject":"[PATCH] completion: optionally disable checkout DWIM","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-04-20T20:12:30Z","receivedAt":"2017-04-20T20:13:58Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When we complete branch names for \"git checkout\", we also\ncomplete remote branch names that could trigger the DWIM\nbehavior. Depending on your workflow and project, this can\nbe either convenient or annoying.\n\nFor instance, my clone of gitster.git contains 74 local\n\"jk/*\" branches, but origin contains another 147. When I\nwant to checkout a local branch but can't quite remember the\nname, tab completion shows me 251 entries. And worse, for a\ntopic that has been picked up for pu, the upstream branch\nname is likely to be similar to mine, leading to a high\nprobability that I pick the wrong one and accidentally\ncreate a new branch.\n\nThis patch adds a way for the user to tell the completion\ncode not to include DWIM suggestions for checkout. This can\nalready be done by typing:\n\n  git checkout --no-guess jk/<TAB>\n\nbut that's rather cumbersome. The downside, of course, is\nthat you no longer get completion support when you _do_ want\nto invoke the DWIM behavior. But depending on your workflow,\nthat may not be a big loss (for instance, in git.git I am\nmuch more likely to want to detach, so I'd type \"git\ncheckout origin/jk/<TAB>\" anyway).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis is flexible enough for me, but it's possible somebody would want\nthis on a per-repo basis. I don't know that we want to read from `git\nconfig`, though, because it's relatively expensive to do so. People who\nwant per-repo settings are probably better off with a hook that triggers\nwhen they \"cd\" around, and sets up their preferences.\n\n contrib/completion/git-completion.bash | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 1150164d5..f53b18fae 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -28,6 +28,14 @@\n # completion style.  For example '!f() { : git commit ; ... }; f' will\n # tell the completion to use commit completion.  This also works with aliases\n # of form \"!sh -c '...'\".  For example, \"!sh -c ': git commit ; ... '\".\n+#\n+# You can set the following environment variables to influence the behavior of\n+# the completion routines:\n+#\n+#   GIT_COMPLETION_CHECKOUT_NO_GUESS\n+#\n+#     When non-empty, do not include \"DWIM\" suggestions in git-checkout\n+#     completion (e.g., completing \"foo\" when \"origin/foo\" exists).\n \n case \"$COMP_WORDBREAKS\" in\n *:*) : great ;;\n@@ -1248,7 +1256,8 @@ _git_checkout ()\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\tif [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n+\t\tif [ -n \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" -o \\\n+\t\t     -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n \t\t\ttrack_opt=''\n \t\tfi\n \t\t__git_complete_refs $track_opt\n-- \n2.13.0.rc0.363.g8726c260e\n"},{"id":"317456","messageId":"xmqqzifa4amr.fsf@gitster.mtv.corp.google.com","threadId":"45759","inReplyTo":"20170420201229.fxiylgp2v2v4sz3w@sigill.intra.peff.net","subject":"Re: [PATCH] completion: optionally disable checkout DWIM","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-04-21T05:01:32Z","receivedAt":"2017-04-21T05:01:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> When we complete branch names for \"git checkout\", we also\n> complete remote branch names that could trigger the DWIM\n> behavior. Depending on your workflow and project, this can\n> be either convenient or annoying.\n> ...\n> This is flexible enough for me, but it's possible somebody would want\n> this on a per-repo basis. I don't know that we want to read from `git\n> config`, though, because it's relatively expensive to do so. People who\n> want per-repo settings are probably better off with a hook that triggers\n> when they \"cd\" around, and sets up their preferences.\n\nSounds OK.  I am kind of surprised that --no-guess is the only way\nto turn off this dwimming (not in the completion side, but there\ndoes not seem to be a way to tell \"git checkout\" that you do not\nneed that create-missing-branch-out-of-remote-tracking).\n\n>  contrib/completion/git-completion.bash | 11 ++++++++++-\n>  1 file changed, 10 insertions(+), 1 deletion(-)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 1150164d5..f53b18fae 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -28,6 +28,14 @@\n>  # completion style.  For example '!f() { : git commit ; ... }; f' will\n>  # tell the completion to use commit completion.  This also works with aliases\n>  # of form \"!sh -c '...'\".  For example, \"!sh -c ': git commit ; ... '\".\n> +#\n> +# You can set the following environment variables to influence the behavior of\n> +# the completion routines:\n> +#\n> +#   GIT_COMPLETION_CHECKOUT_NO_GUESS\n> +#\n> +#     When non-empty, do not include \"DWIM\" suggestions in git-checkout\n> +#     completion (e.g., completing \"foo\" when \"origin/foo\" exists).\n>  \n>  case \"$COMP_WORDBREAKS\" in\n>  *:*) : great ;;\n> @@ -1248,7 +1256,8 @@ _git_checkout ()\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\tif [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n> +\t\tif [ -n \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" -o \\\n> +\t\t     -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n>  \t\t\ttrack_opt=''\n>  \t\tfi\n>  \t\t__git_complete_refs $track_opt\n"},{"id":"317457","messageId":"20170421050330.ntnbri6qybi5i3pe@sigill.intra.peff.net","threadId":"45759","inReplyTo":"xmqqzifa4amr.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] completion: optionally disable checkout DWIM","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-04-21T05:03:30Z","receivedAt":"2017-04-21T05:03:40Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Apr 20, 2017 at 10:01:32PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > When we complete branch names for \"git checkout\", we also\n> > complete remote branch names that could trigger the DWIM\n> > behavior. Depending on your workflow and project, this can\n> > be either convenient or annoying.\n> > ...\n> > This is flexible enough for me, but it's possible somebody would want\n> > this on a per-repo basis. I don't know that we want to read from `git\n> > config`, though, because it's relatively expensive to do so. People who\n> > want per-repo settings are probably better off with a hook that triggers\n> > when they \"cd\" around, and sets up their preferences.\n> \n> Sounds OK.  I am kind of surprised that --no-guess is the only way\n> to turn off this dwimming (not in the completion side, but there\n> does not seem to be a way to tell \"git checkout\" that you do not\n> need that create-missing-branch-out-of-remote-tracking).\n\nYeah, I didn't even know about --no-guess until reading the completion\nscript (it's intentionally undocumented). I did consider teaching\ncheckout a config option for \"do not DWIM\". But I think it's really the\ncompletion that bugs me. The DWIM is easy to avoid triggering if you\njust don't feed it the remote branch names. It's the completion that\nroutinely leads me to doing that. :)\n\n-Peff\n"},{"id":"317458","messageId":"xmqqvapy49ar.fsf@gitster.mtv.corp.google.com","threadId":"45759","inReplyTo":"20170421050330.ntnbri6qybi5i3pe@sigill.intra.peff.net","subject":"Re: [PATCH] completion: optionally disable checkout DWIM","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-04-21T05:30:20Z","receivedAt":"2017-04-21T05:30:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> ... But I think it's really the\n> completion that bugs me. The DWIM is easy to avoid triggering if you\n> just don't feed it the remote branch names. It's the completion that\n> routinely leads me to doing that. :)\n\nTrue.\n"},{"id":"317466","messageId":"CA+P7+xr83+sGiRcfbmAvOGzxoR+BMVsjED41JY5P15Dw1qVb+w@mail.gmail.com","threadId":"45759","inReplyTo":"20170420201229.fxiylgp2v2v4sz3w@sigill.intra.peff.net","subject":"Re: [PATCH] completion: optionally disable checkout DWIM","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-04-21T07:25:30Z","receivedAt":"2017-04-21T07:25:58Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Apr 20, 2017 at 1:12 PM, Jeff King <peff@peff.net> wrote:\n> When we complete branch names for \"git checkout\", we also\n> complete remote branch names that could trigger the DWIM\n> behavior. Depending on your workflow and project, this can\n> be either convenient or annoying.\n>\n> For instance, my clone of gitster.git contains 74 local\n> \"jk/*\" branches, but origin contains another 147. When I\n> want to checkout a local branch but can't quite remember the\n> name, tab completion shows me 251 entries. And worse, for a\n> topic that has been picked up for pu, the upstream branch\n> name is likely to be similar to mine, leading to a high\n> probability that I pick the wrong one and accidentally\n> create a new branch.\n>\n> This patch adds a way for the user to tell the completion\n> code not to include DWIM suggestions for checkout. This can\n> already be done by typing:\n>\n>   git checkout --no-guess jk/<TAB>\n>\n> but that's rather cumbersome. The downside, of course, is\n> that you no longer get completion support when you _do_ want\n> to invoke the DWIM behavior. But depending on your workflow,\n> that may not be a big loss (for instance, in git.git I am\n> much more likely to want to detach, so I'd type \"git\n> checkout origin/jk/<TAB>\" anyway).\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n> This is flexible enough for me, but it's possible somebody would want\n> this on a per-repo basis. I don't know that we want to read from `git\n> config`, though, because it's relatively expensive to do so. People who\n> want per-repo settings are probably better off with a hook that triggers\n> when they \"cd\" around, and sets up their preferences.\n>\n\nI would use this. Completing these can get quite cumbersome to use\nwhen I have only a few local branches but many remote ones like in\ngit.git\n\nThanks,\nJake\n"},{"id":"317515","messageId":"CAM0VKjm=JMuYzsS-OTx+p-vFF8PmWJGbFnndag9dWw6xCe3g6Q@mail.gmail.com","threadId":"45759","inReplyTo":"xmqqzifa4amr.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] completion: optionally disable checkout DWIM","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-04-21T20:14:48Z","receivedAt":"2017-04-21T20:14:56Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Apr 21, 2017 at 7:01 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jeff King <peff@peff.net> writes:\n>\n>> When we complete branch names for \"git checkout\", we also\n>> complete remote branch names that could trigger the DWIM\n>> behavior. Depending on your workflow and project, this can\n>> be either convenient or annoying.\n>> ...\n>> This is flexible enough for me, but it's possible somebody would want\n>> this on a per-repo basis. I don't know that we want to read from `git\n>> config`, though, because it's relatively expensive to do so. People who\n>> want per-repo settings are probably better off with a hook that triggers\n>> when they \"cd\" around, and sets up their preferences.\n\nWe could discern between more than just empty vs. non-empty state of\nthe environment variable, e.g.:\n\n  - if empty/unset, then include \"DWIM\" suggestions.\n  - if set to 'config', then query the 'completion.checkoutNoGuess'\n    configuration variable, and omit \"DWIM\" suggestions if its true.\n  - if set to something else, then omit \"DWIM\" suggestions.\n\nThen users can themselves decide, whether the per-repo configurability\nis worth the overhead of running 'git config'.\n\n\n> Sounds OK.  I am kind of surprised that --no-guess is the only way\n> to turn off this dwimming (not in the completion side, but there\n> does not seem to be a way to tell \"git checkout\" that you do not\n> need that create-missing-branch-out-of-remote-tracking).\n>\n>>  contrib/completion/git-completion.bash | 11 ++++++++++-\n>>  1 file changed, 10 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n>> index 1150164d5..f53b18fae 100644\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -28,6 +28,14 @@\n>>  # completion style.  For example '!f() { : git commit ; ... }; f' will\n>>  # tell the completion to use commit completion.  This also works with aliases\n>>  # of form \"!sh -c '...'\".  For example, \"!sh -c ': git commit ; ... '\".\n>> +#\n>> +# You can set the following environment variables to influence the behavior of\n>> +# the completion routines:\n>> +#\n>> +#   GIT_COMPLETION_CHECKOUT_NO_GUESS\n\nThat's one long variable name :)\nOf course it has to start with the 'GIT_COMPLETION_' prefix, and you\ncan't win from there...\n\n>> +#     When non-empty, do not include \"DWIM\" suggestions in git-checkout\n>> +#     completion (e.g., completing \"foo\" when \"origin/foo\" exists).\n>>\n>>  case \"$COMP_WORDBREAKS\" in\n>>  *:*) : great ;;\n>> @@ -1248,7 +1256,8 @@ _git_checkout ()\n>>               # check if --track, --no-track, or --no-guess was specified\n>>               # if so, disable DWIM mode\n>>               local flags=\"--track --no-track --no-guess\" track_opt=\"--track\"\n>> -             if [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n>> +             if [ -n \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" -o \\\n>> +                  -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n\n|| would be better than '-o', because the former short-circuits when\nthe first condition is true, but the latter doesn't.\n\n>>                       track_opt=''\n>>               fi\n>>               __git_complete_refs $track_opt\n\nOn Fri, Apr 21, 2017 at 7:01 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jeff King <peff@peff.net> writes:\n>\n>> When we complete branch names for \"git checkout\", we also\n>> complete remote branch names that could trigger the DWIM\n>> behavior. Depending on your workflow and project, this can\n>> be either convenient or annoying.\n>> ...\n>> This is flexible enough for me, but it's possible somebody would want\n>> this on a per-repo basis. I don't know that we want to read from `git\n>> config`, though, because it's relatively expensive to do so. People who\n>> want per-repo settings are probably better off with a hook that triggers\n>> when they \"cd\" around, and sets up their preferences.\n>\n> Sounds OK.  I am kind of surprised that --no-guess is the only way\n> to turn off this dwimming (not in the completion side, but there\n> does not seem to be a way to tell \"git checkout\" that you do not\n> need that create-missing-branch-out-of-remote-tracking).\n>\n>>  contrib/completion/git-completion.bash | 11 ++++++++++-\n>>  1 file changed, 10 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n>> index 1150164d5..f53b18fae 100644\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -28,6 +28,14 @@\n>>  # completion style.  For example '!f() { : git commit ; ... }; f' will\n>>  # tell the completion to use commit completion.  This also works with aliases\n>>  # of form \"!sh -c '...'\".  For example, \"!sh -c ': git commit ; ... '\".\n>> +#\n>> +# You can set the following environment variables to influence the behavior of\n>> +# the completion routines:\n>> +#\n>> +#   GIT_COMPLETION_CHECKOUT_NO_GUESS\n>> +#\n>> +#     When non-empty, do not include \"DWIM\" suggestions in git-checkout\n>> +#     completion (e.g., completing \"foo\" when \"origin/foo\" exists).\n>>\n>>  case \"$COMP_WORDBREAKS\" in\n>>  *:*) : great ;;\n>> @@ -1248,7 +1256,8 @@ _git_checkout ()\n>>               # check if --track, --no-track, or --no-guess was specified\n>>               # if so, disable DWIM mode\n>>               local flags=\"--track --no-track --no-guess\" track_opt=\"--track\"\n>> -             if [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n>> +             if [ -n \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" -o \\\n>> +                  -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n>>                       track_opt=''\n>>               fi\n>>               __git_complete_refs $track_opt\n"},{"id":"317517","messageId":"20170421201957.ztwnyw6mut4b5u53@sigill.intra.peff.net","threadId":"45759","inReplyTo":"CAM0VKjm=JMuYzsS-OTx+p-vFF8PmWJGbFnndag9dWw6xCe3g6Q@mail.gmail.com","subject":"Re: [PATCH] completion: optionally disable checkout DWIM","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-04-21T20:19:57Z","receivedAt":"2017-04-21T20:20:05Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Apr 21, 2017 at 10:14:48PM +0200, SZEDER Gábor wrote:\n\n> >> This is flexible enough for me, but it's possible somebody would want\n> >> this on a per-repo basis. I don't know that we want to read from `git\n> >> config`, though, because it's relatively expensive to do so. People who\n> >> want per-repo settings are probably better off with a hook that triggers\n> >> when they \"cd\" around, and sets up their preferences.\n> \n> We could discern between more than just empty vs. non-empty state of\n> the environment variable, e.g.:\n> \n>   - if empty/unset, then include \"DWIM\" suggestions.\n>   - if set to 'config', then query the 'completion.checkoutNoGuess'\n>     configuration variable, and omit \"DWIM\" suggestions if its true.\n>   - if set to something else, then omit \"DWIM\" suggestions.\n> \n> Then users can themselves decide, whether the per-repo configurability\n> is worth the overhead of running 'git config'.\n\nYep, that would work. I wasn't going to bother with that complexity\nunless somebody really wanted it. The important thing is not to paint\nourselves into a corner. By the rules you gave above, it would probably\nbe fine to extend my patch later to match. But we could also be more\nspecific (e.g., look for some positive value like \"1\").\n\n> >> +# You can set the following environment variables to influence the behavior of\n> >> +# the completion routines:\n> >> +#\n> >> +#   GIT_COMPLETION_CHECKOUT_NO_GUESS\n> \n> That's one long variable name :)\n> Of course it has to start with the 'GIT_COMPLETION_' prefix, and you\n> can't win from there...\n\nYeah, I had the same thought. I also considered using \"DWIM\", which is\nthe name by which I know the feature. But since \"--no-guess\" is the\nmatching option, I went with that.\n\n> >> @@ -1248,7 +1256,8 @@ _git_checkout ()\n> >>               # check if --track, --no-track, or --no-guess was specified\n> >>               # if so, disable DWIM mode\n> >>               local flags=\"--track --no-track --no-guess\" track_opt=\"--track\"\n> >> -             if [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n> >> +             if [ -n \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" -o \\\n> >> +                  -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n> \n> || would be better than '-o', because the former short-circuits when\n> the first condition is true, but the latter doesn't.\n\nAh, I didn't know that. Usually I use \"||\", but I thought \"-o\" was\ngenerally preferred in bash-specific scripts. We definitely want to\nshort circuit here.\n\n-Peff\n"},{"id":"317518","messageId":"20170421202705.4uhbk3okccszxvgl@sigill.intra.peff.net","threadId":"45759","inReplyTo":"20170420201229.fxiylgp2v2v4sz3w@sigill.intra.peff.net","subject":"[PATCH v2] completion: optionally disable checkout DWIM","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-04-21T20:27:06Z","receivedAt":"2017-04-21T20:27:16Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"\nWhen we complete branch names for \"git checkout\", we also\ncomplete remote branch names that could trigger the DWIM\nbehavior. Depending on your workflow and project, this can\nbe either convenient or annoying.\n\nFor instance, my clone of gitster.git contains 74 local\n\"jk/*\" branches, but origin contains another 147. When I\nwant to checkout a local branch but can't quite remember the\nname, tab completion shows me 251 entries. And worse, for a\ntopic that has been picked up for pu, the upstream branch\nname is likely to be similar to mine, leading to a high\nprobability that I pick the wrong one and accidentally\ncreate a new branch.\n\nThis patch adds a way for the user to tell the completion\ncode not to include DWIM suggestions for checkout. This can\nalready be done by typing:\n\n  git checkout --no-guess jk/<TAB>\n\nbut that's rather cumbersome. The downside, of course, is\nthat you no longer get completion support when you _do_ want\nto invoke the DWIM behavior. But depending on your workflow,\nthat may not be a big loss (for instance, in git.git I am\nmuch more likely to want to detach, so I'd type \"git\ncheckout origin/jk/<TAB>\" anyway).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nCompared to v1, this version requires the new variable be set to \"1\" (to\nleave more room for later extension), and uses short-circuiting || for\nthe logic.\n\n contrib/completion/git-completion.bash | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 1150164d5..f977b54d8 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -28,6 +28,14 @@\n # completion style.  For example '!f() { : git commit ; ... }; f' will\n # tell the completion to use commit completion.  This also works with aliases\n # of form \"!sh -c '...'\".  For example, \"!sh -c ': git commit ; ... '\".\n+#\n+# You can set the following environment variables to influence the behavior of\n+# the completion routines:\n+#\n+#   GIT_COMPLETION_CHECKOUT_NO_GUESS\n+#\n+#     When set to \"1\", do not include \"DWIM\" suggestions in git-checkout\n+#     completion (e.g., completing \"foo\" when \"origin/foo\" exists).\n \n case \"$COMP_WORDBREAKS\" in\n *:*) : great ;;\n@@ -1248,7 +1256,8 @@ _git_checkout ()\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\tif [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\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\tfi\n \t\t__git_complete_refs $track_opt\n-- \n2.13.0.rc0.364.g36b4d8031\n"},{"id":"317546","messageId":"CAM0VKj=j52hDD1TKqbube3Of1qo8zZ7e4q4yAmxbNORRRDZyFQ@mail.gmail.com","threadId":"45759","inReplyTo":"20170421201957.ztwnyw6mut4b5u53@sigill.intra.peff.net","subject":"Re: [PATCH] completion: optionally disable checkout DWIM","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-04-22T17:32:41Z","receivedAt":"2017-04-22T17:32:47Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Apr 21, 2017 at 10:19 PM, Jeff King <peff@peff.net> wrote:\n> On Fri, Apr 21, 2017 at 10:14:48PM +0200, SZEDER Gábor wrote:\n>\n>> >> This is flexible enough for me, but it's possible somebody would want\n>> >> this on a per-repo basis. I don't know that we want to read from `git\n>> >> config`, though, because it's relatively expensive to do so. People who\n>> >> want per-repo settings are probably better off with a hook that triggers\n>> >> when they \"cd\" around, and sets up their preferences.\n>>\n>> We could discern between more than just empty vs. non-empty state of\n>> the environment variable, e.g.:\n>>\n>>   - if empty/unset, then include \"DWIM\" suggestions.\n>>   - if set to 'config', then query the 'completion.checkoutNoGuess'\n>>     configuration variable, and omit \"DWIM\" suggestions if its true.\n>>   - if set to something else, then omit \"DWIM\" suggestions.\n>>\n>> Then users can themselves decide, whether the per-repo configurability\n>> is worth the overhead of running 'git config'.\n>\n> Yep, that would work. I wasn't going to bother with that complexity\n> unless somebody really wanted it. The important thing is not to paint\n> ourselves into a corner. By the rules you gave above, it would probably\n> be fine to extend my patch later to match. But we could also be more\n> specific (e.g., look for some positive value like \"1\").\n\nThat's fine with me.\n\nWe should have done this when we introduced env variables controlling\nthe prompt script, we could spare a 'git config' execution in a\nsubshell or two.\n\n>> >> @@ -1248,7 +1256,8 @@ _git_checkout ()\n>> >>               # check if --track, --no-track, or --no-guess was specified\n>> >>               # if so, disable DWIM mode\n>> >>               local flags=\"--track --no-track --no-guess\" track_opt=\"--track\"\n>> >> -             if [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n>> >> +             if [ -n \"$GIT_COMPLETION_CHECKOUT_NO_GUESS\" -o \\\n>> >> +                  -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n>>\n>> || would be better than '-o', because the former short-circuits when\n>> the first condition is true, but the latter doesn't.\n>\n> Ah, I didn't know that. Usually I use \"||\", but I thought \"-o\" was\n> generally preferred in bash-specific scripts. We definitely want to\n> short circuit here.\n\nNo, we use || and && fairly consistently in conditions in Bash\nscripts.  There is no '-o' in the completion or prompt scripts, and\nthere is only a single '-a' in the former, but it only checks two\none-letter variables, so it doesn't matter.  (Besides, it's from my\nsecond ever commit, so it has great sentimental value ;)\n\nThere are some inconsistencies using 'if [ ... ]' and 'if [[ ... ]]',\nbut oh well.\n\n\nAnyway, v2 looks good to me.\n"},{"id":"317698","messageId":"20170424163002.GB195761@google.com","threadId":"45759","inReplyTo":"20170421202705.4uhbk3okccszxvgl@sigill.intra.peff.net","subject":"Re: [PATCH v2] completion: optionally disable checkout DWIM","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-04-24T16:30:02Z","receivedAt":"2017-04-24T16:30:54Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 04/21, Jeff King wrote:\n> \n> When we complete branch names for \"git checkout\", we also\n> complete remote branch names that could trigger the DWIM\n> behavior. Depending on your workflow and project, this can\n> be either convenient or annoying.\n> \n> For instance, my clone of gitster.git contains 74 local\n> \"jk/*\" branches, but origin contains another 147. When I\n> want to checkout a local branch but can't quite remember the\n> name, tab completion shows me 251 entries. And worse, for a\n> topic that has been picked up for pu, the upstream branch\n> name is likely to be similar to mine, leading to a high\n> probability that I pick the wrong one and accidentally\n> create a new branch.\n> \n> This patch adds a way for the user to tell the completion\n> code not to include DWIM suggestions for checkout. This can\n> already be done by typing:\n> \n>   git checkout --no-guess jk/<TAB>\n> \n> but that's rather cumbersome. The downside, of course, is\n> that you no longer get completion support when you _do_ want\n> to invoke the DWIM behavior. But depending on your workflow,\n> that may not be a big loss (for instance, in git.git I am\n> much more likely to want to detach, so I'd type \"git\n> checkout origin/jk/<TAB>\" anyway).\n> \n> Signed-off-by: Jeff King <peff@peff.net>\n\nMay not be relevant to this patch per-say, but is there a way to have\nthe completion for checkout only complete up to a part of\nremotes/branches?  Say a forward-slash '/'.  For example git.git has\nlots of branches which have the form: origin/<initials>/branch-name.  It\nwould be convenient if when I type:\n\ngit checkout <TAB> \n\nInstead of getting a long list of 2k or so branch names that instead I\nwould get see the remote's name e.g. 'origin/' kind of like vanilla\ndirectory completion.  This way, unless I'm actually interested in the\nremote, I don't see the thousands of branches related to it.\n\n-- \nBrandon Williams\n"}]}