Re: [PATCH] completion: Support the DWIM mode for git checkout
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- Oct 10, 2010, 21:16 UTC
- Message-ID
- <20101010211634.GA4730@neumann>
- In-Reply-To
- <1286496492-65221-1-git-send-email-kevin@sb.org>
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.
Show 7 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
Show 16 quoted lines
> @@ -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.
Best, Gábor