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

Re: [PATCH] completion: Support the DWIM mode for git checkout

From
Kevin Ballard <kevin@sb.org>
Date
Oct 10, 2010, 23:18 UTC
Message-ID
<DE3CFB0F-A774-4170-A74D-3BE400E33CEC@sb.org>
In-Reply-To
<20101010211634.GA4730@neumann>
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
Previous: SZEDER GáborNext: Kevin Ballard
Message 3 of 4 in “completion: Support the DWIM mode for git checkout”
  1. completion: Support the DWIM mode for git checkoutKevin Ballard, Oct 8, 2010
  2. SZEDER GáborOct 10, 2010
  3. Kevin BallardOct 10, 2010
  4. completion: Support the DWIM mode for git checkoutKevin Ballard, Oct 12, 2010

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.