Re: [PATCH] completion: optionally disable checkout DWIM

2017-06-29 Thread Jason Karns
> 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'.

I would _definitely_ appreciate this feature. Firstly, thank you for
the addition of the environment variable. It is indeed much better
than the --no-guess flag.

However, I'm in a situation where I very much prefer the DWIM behavior
for nearly all of my repos. However, a very few repos have LOTS of
branches. And I only wish to disable DWIM in those few repos.

I attempted to create an alias (`git config alias.co 'checkout
--no-guess'`) in those specific repos. However, that turned out to be
foolish since I believe the alias parsing doesn't occur until _after_
the shell completion script runs (thus the --no-guess is not actually
present in the command parsed by the completion script).

So I'm back to very much wanting the ability to disable DWIM
repo-specific via git-config; and am willing to pay the git-config tax
as necessary.


Re: [PATCH] completion: optionally disable checkout DWIM

2017-04-22 Thread SZEDER Gábor
On Fri, Apr 21, 2017 at 10:19 PM, Jeff King  wrote:
> On Fri, Apr 21, 2017 at 10:14:48PM +0200, SZEDER Gábor wrote:
>
>> >> 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").

That's fine with me.

We should have done this when we introduced env variables controlling
the prompt script, we could spare a 'git config' execution in a
subshell or two.

>> >> @@ -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.

No, we use || and && fairly consistently in conditions in Bash
scripts.  There is no '-o' in the completion or prompt scripts, and
there is only a single '-a' in the former, but it only checks two
one-letter variables, so it doesn't matter.  (Besides, it's from my
second ever commit, so it has great sentimental value ;)

There are some inconsistencies using 'if [ ... ]' and 'if [[ ... ]]',
but oh well.


Anyway, v2 looks good to me.


Re: [PATCH] completion: optionally disable checkout DWIM

2017-04-21 Thread Jeff King
On Fri, Apr 21, 2017 at 10:14:48PM +0200, SZEDER Gábor wrote:

> >> 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").

> >> +# 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.

> >> @@ -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


Re: [PATCH] completion: optionally disable checkout DWIM

2017-04-21 Thread SZEDER Gábor
On Fri, Apr 21, 2017 at 7:01 AM, Junio C Hamano  wrote:
> Jeff King  writes:
>
>> When we complete branch names for "git checkout", we also
>> complete remote branch names that could trigger the DWIM
>> behavior. Depending on your workflow and project, this can
>> be either convenient or annoying.
>> ...
>> 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'.


> Sounds OK.  I am kind of surprised that --no-guess is the only way
> to turn off this dwimming (not in the completion side, but there
> does not seem to be a way to tell "git checkout" that you do not
> need that create-missing-branch-out-of-remote-tracking).
>
>>  contrib/completion/git-completion.bash | 11 ++-
>>  1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/contrib/completion/git-completion.bash 
>> b/contrib/completion/git-completion.bash
>> index 1150164d5..f53b18fae 100644
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -28,6 +28,14 @@
>>  # completion style.  For example '!f() { : git commit ; ... }; f' will
>>  # tell the completion to use commit completion.  This also works with 
>> aliases
>>  # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
>> +#
>> +# 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...

>> +# When non-empty, do not include "DWIM" suggestions in git-checkout
>> +# completion (e.g., completing "foo" when "origin/foo" exists).
>>
>>  case "$COMP_WORDBREAKS" in
>>  *:*) : great ;;
>> @@ -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.

>>   track_opt=''
>>   fi
>>   __git_complete_refs $track_opt

On Fri, Apr 21, 2017 at 7:01 AM, Junio C Hamano  wrote:
> Jeff King  writes:
>
>> When we complete branch names for "git checkout", we also
>> complete remote branch names that could trigger the DWIM
>> behavior. Depending on your workflow and project, this can
>> be either convenient or annoying.
>> ...
>> 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.
>
> Sounds OK.  I am kind of surprised that --no-guess is the only way
> to turn off this dwimming (not in the completion side, but there
> does not seem to be a way to tell "git checkout" that you do not
> need that create-missing-branch-out-of-remote-tracking).
>
>>  contrib/completion/git-completion.bash | 11 ++-
>>  1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/contrib/completion/git-completion.bash 
>> b/contrib/completion/git-completion.bash
>> index 1150164d5..f53b18fae 100644
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -28,6 +28,14 @@
>>  # completion style.  For example '!f() { : git commit ; ... }; f' will
>>  # tell the completion to use commit completion.  This also works with 
>> aliases
>>  # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
>> +#
>> +# You can set the following environment variables to influence the behavior 
>> of
>> +# the completion routines:
>> +#
>> +#   GIT_COMPLETION_CHECKOUT_NO_GUESS
>> +#
>> +# When non-empty, do not include "DWIM" suggestions in git-checkout
>> +# completion (e.g., 

Re: [PATCH] completion: optionally disable checkout DWIM

2017-04-21 Thread Jacob Keller
On Thu, Apr 20, 2017 at 1:12 PM, Jeff King  wrote:
> When we complete branch names for "git checkout", we also
> complete remote branch names that could trigger the DWIM
> behavior. Depending on your workflow and project, this can
> be either convenient or annoying.
>
> For instance, my clone of gitster.git contains 74 local
> "jk/*" branches, but origin contains another 147. When I
> want to checkout a local branch but can't quite remember the
> name, tab completion shows me 251 entries. And worse, for a
> topic that has been picked up for pu, the upstream branch
> name is likely to be similar to mine, leading to a high
> probability that I pick the wrong one and accidentally
> create a new branch.
>
> This patch adds a way for the user to tell the completion
> code not to include DWIM suggestions for checkout. This can
> already be done by typing:
>
>   git checkout --no-guess jk/
>
> but that's rather cumbersome. The downside, of course, is
> that you no longer get completion support when you _do_ want
> to invoke the DWIM behavior. But depending on your workflow,
> that may not be a big loss (for instance, in git.git I am
> much more likely to want to detach, so I'd type "git
> checkout origin/jk/" anyway).
>
> Signed-off-by: Jeff King 
> ---
> 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.
>

I would use this. Completing these can get quite cumbersome to use
when I have only a few local branches but many remote ones like in
git.git

Thanks,
Jake


Re: [PATCH] completion: optionally disable checkout DWIM

2017-04-20 Thread Junio C Hamano
Jeff King  writes:

> ... But I think it's really the
> completion that bugs me. The DWIM is easy to avoid triggering if you
> just don't feed it the remote branch names. It's the completion that
> routinely leads me to doing that. :)

True.


Re: [PATCH] completion: optionally disable checkout DWIM

2017-04-20 Thread Jeff King
On Thu, Apr 20, 2017 at 10:01:32PM -0700, Junio C Hamano wrote:

> Jeff King  writes:
> 
> > When we complete branch names for "git checkout", we also
> > complete remote branch names that could trigger the DWIM
> > behavior. Depending on your workflow and project, this can
> > be either convenient or annoying.
> > ...
> > 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.
> 
> Sounds OK.  I am kind of surprised that --no-guess is the only way
> to turn off this dwimming (not in the completion side, but there
> does not seem to be a way to tell "git checkout" that you do not
> need that create-missing-branch-out-of-remote-tracking).

Yeah, I didn't even know about --no-guess until reading the completion
script (it's intentionally undocumented). I did consider teaching
checkout a config option for "do not DWIM". But I think it's really the
completion that bugs me. The DWIM is easy to avoid triggering if you
just don't feed it the remote branch names. It's the completion that
routinely leads me to doing that. :)

-Peff


Re: [PATCH] completion: optionally disable checkout DWIM

2017-04-20 Thread Junio C Hamano
Jeff King  writes:

> When we complete branch names for "git checkout", we also
> complete remote branch names that could trigger the DWIM
> behavior. Depending on your workflow and project, this can
> be either convenient or annoying.
> ...
> 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.

Sounds OK.  I am kind of surprised that --no-guess is the only way
to turn off this dwimming (not in the completion side, but there
does not seem to be a way to tell "git checkout" that you do not
need that create-missing-branch-out-of-remote-tracking).

>  contrib/completion/git-completion.bash | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-completion.bash 
> b/contrib/completion/git-completion.bash
> index 1150164d5..f53b18fae 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -28,6 +28,14 @@
>  # completion style.  For example '!f() { : git commit ; ... }; f' will
>  # tell the completion to use commit completion.  This also works with aliases
>  # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
> +#
> +# You can set the following environment variables to influence the behavior 
> of
> +# the completion routines:
> +#
> +#   GIT_COMPLETION_CHECKOUT_NO_GUESS
> +#
> +# When non-empty, do not include "DWIM" suggestions in git-checkout
> +# completion (e.g., completing "foo" when "origin/foo" exists).
>  
>  case "$COMP_WORDBREAKS" in
>  *:*) : great ;;
> @@ -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
>   track_opt=''
>   fi
>   __git_complete_refs $track_opt