Re: [PATCH] completion: Support the DWIM mode for git checkout
From: SZEDER Gábor <hidden>
Date: 2016-06-15 22:49:45
Hi, On Thu, Oct 07, 2010 at 05:08:12PM -0700, Kevin Ballard wrote:
Signed-off-by: Kevin Ballard <redacted> ---
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.
quoted hunk ↗ jump to hunk
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
quoted hunk ↗ jump to hunk
@@ -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