Re: [PATCH] completion: Support the DWIM mode for git checkout
On Oct 10, 2010, at 2:16 PM, SZEDER Gábor wrote:
Show 15 quoted lines
> Hi,
>
>
> On Thu, Oct 07, 2010 at 05:08:12PM -0700, Kevin Ballard wrote:
>> Signed-off-by: Kevin Ballard <kevin@sb.org>
>> ---
>
> I think the commit message should add some details about how the patch
> changes the completion script's behavior. At least I didn't know
> offhand what "DWIM mode for git checkout" is, and once I found it
> (70c9ac2 (DWIM "git checkout frotz" to "git checkout -b frotz
> origin/frotz", 2009-10-18), right?), I didn't know how the completion
> script is supposed to support that, and once I applied the patch and
> played around a bit, I was surprised that only 'git checkout h<tab>'
> includes the 'html' branch but 'git checkout <tab>' don't.
Good point. I'll write a real commit message for the next version. And another good point about 'git checkout <tab>'. I don't remember why, but for some reason I explicitly avoided DWIM mode if the current word was empty. But you're right, there's no good reason to do that.
Show 27 quoted lines
>> contrib/completion/git-completion.bash | 35 +++++++++++++++++++++++++++++--
>> 1 files changed, 32 insertions(+), 3 deletions(-)
>>
>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>> index f83f019..be0498c 100755
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>
>
>> @@ -988,7 +1007,17 @@ _git_checkout ()
>> "
>> ;;
>> *)
>> - __gitcomp "$(__git_refs)"
>> + # check if --track, --no-track, or --no-guess was specified
>> + # if so, disable DWIM mode
>> + local i c=1 track=1
>> + while [ $c -lt $COMP_CWORD ]; do
>> + i="${COMP_WORDS[c]}"
>> + case "$i" in
>> + --track|--no-track|--no-guess) track=''; break ;;
>> + esac
>> + c=$((++c))
>> + done
>> + __gitcomp "$(__git_refs '' $track)"
>
> You could use the __git_find_on_cmdline() helper function instead.I'll look into that, thanks.
-Kevin Ballard