git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: optionally disable checkout DWIM

From
Jeff King <peff@peff.net>
Date
Apr 21, 2017, 20:19 UTC
Message-ID
<20170421201957.ztwnyw6mut4b5u53@sigill.intra.peff.net>
In-Reply-To
<CAM0VKjm=JMuYzsS-OTx+p-vFF8PmWJGbFnndag9dWw6xCe3g6Q@mail.gmail.com>
On Fri, Apr 21, 2017 at 10:14:48PM +0200, SZEDER Gábor wrote:
Show 16 quoted lines
> >> This is flexible enough for me, but it's possible somebody would want
> >> this on a per-repo basis. I don't know that we want to read from `git
> >> config`, though, because it's relatively expensive to do so. People who
> >> want per-repo settings are probably better off with a hook that triggers
> >> when they "cd" around, and sets up their preferences.
> 
> We could discern between more than just empty vs. non-empty state of
> the environment variable, e.g.:
> 
>   - if empty/unset, then include "DWIM" suggestions.
>   - if set to 'config', then query the 'completion.checkoutNoGuess'
>     configuration variable, and omit "DWIM" suggestions if its true.
>   - if set to something else, then omit "DWIM" suggestions.
> 
> Then users can themselves decide, whether the per-repo configurability
> is worth the overhead of running 'git config'.

Yep, that would work. I wasn't going to bother with that complexity unless somebody really wanted it. The important thing is not to paint ourselves into a corner. By the rules you gave above, it would probably be fine to extend my patch later to match. But we could also be more specific (e.g., look for some positive value like "1").

Show 8 quoted lines
> >> +# You can set the following environment variables to influence the behavior of
> >> +# the completion routines:
> >> +#
> >> +#   GIT_COMPLETION_CHECKOUT_NO_GUESS
> 
> That's one long variable name :)
> Of course it has to start with the 'GIT_COMPLETION_' prefix, and you
> can't win from there...

Yeah, I had the same thought. I also considered using "DWIM", which is the name by which I know the feature. But since "--no-guess" is the matching option, I went with that.

Show 10 quoted lines
> >> @@ -1248,7 +1256,8 @@ _git_checkout ()
> >>               # check if --track, --no-track, or --no-guess was specified
> >>               # if so, disable DWIM mode
> >>               local flags="--track --no-track --no-guess" track_opt="--track"
> >> -             if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
> >> +             if [ -n "$GIT_COMPLETION_CHECKOUT_NO_GUESS" -o \
> >> +                  -n "$(__git_find_on_cmdline "$flags")" ]; then
> 
> || would be better than '-o', because the former short-circuits when
> the first condition is true, but the latter doesn't.

Ah, I didn't know that. Usually I use "||", but I thought "-o" was generally preferred in bash-specific scripts. We definitely want to short circuit here.

-Peff
Previous: SZEDER GáborNext: SZEDER Gábor
Message 6 of 10 in “completion: optionally disable checkout DWIM”
  1. completion: optionally disable checkout DWIMJeff King, Apr 20, 2017
  2. Junio C HamanoApr 21, 2017
  3. Jeff KingApr 21, 2017
  4. Junio C HamanoApr 21, 2017
  5. SZEDER GáborApr 21, 2017
  6. Jeff KingApr 21, 2017
  7. SZEDER GáborApr 22, 2017
  8. Jacob KellerApr 21, 2017
  9. completion: optionally disable checkout DWIMJeff King, Apr 21, 2017
  10. Brandon WilliamsApr 24, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.