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

Re: [PATCH] tab completion of filenames for 'git restore'

From
David Cantrell <david@cantrell.org.uk>
Date
Mar 14, 2022, 23:45 UTC
Message-ID
<2ae04989-156c-63a2-c191-67f97bb6c7b9@cantrell.org.uk>
In-Reply-To
<xmqqlexel59r.fsf@gitster.g>
On 13/03/2022 06:45, Junio C Hamano wrote:
Show 10 quoted lines
> "David Cantrell via GitGitGadget" <gitgitgadget@gmail.com> writes:
>>      Improved bash tab completion for 'git restore' - adds support for
>>      auto-completing filenames
>>      
>>      This adds tab-completion of filenames to the bash completions for git
>>      restore.
> Two questions
> 
>   - "restore" is a castrated half "checkout"; shouldn't the latter
>     also be getting the same feature?

`git checkout <tab>` already completes to a list of branches and tags, which is I think more useful in that case.

Show 8 quoted lines
>   - is "complete_index_file --committable" the right thing to use?
> 
>     It boils down to running "diff-index HEAD", which means path with
>     differences from the HEAD commit is listed.  By default "restore"
>     checks out the contents of the given path from the index to the
>     working tree, so after "edit F && git add F", "diff-index HEAD"
>     may show F in its output (i.e. F is "committable"), but "restore
>     F" would be a no-op.  Which feels a bit iffy.
I'd not thought of that. --modified is better.
Show 18 quoted lines
>> @@ -2883,14 +2883,21 @@ _git_restore ()
>>   	case "$cur" in
>>   	--conflict=*)
>>   		__gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
>> +		return
>>   		;;
>>   	--source=*)
>>   		__git_complete_refs --cur="${cur##--source=}"
>> +		return
>>   		;;
>> ...
> Do you need to sprinkle return's?  Instead you could just add
> another case arm, like
> 
> +	*)
> +		... whatever you want to do when
> +		... $cur is not a --dashed-option
> +		;;

Liberal sprinkling of return like that seems to be the norm for the rest of the file so I stuck with it.

-- 
David Cantrell
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 13 in “tab completion of filenames for 'git restore'”
  1. tab completion of filenames for 'git restore'David Cantrell via GitGitGadget, Mar 11, 2022
  2. Junio C HamanoMar 13, 2022
  3. David CantrellMar 14, 2022
  4. Junio C HamanoMar 15, 2022
  5. 0/2 Improved bash tab completion for 'git restore' - adds support for auto-completing filenamesDavid Cantrell via GitGitGadget, Mar 15, 2022
  6. 2/2 if a file has been staged we don't want to list itDavid Cantrell via GitGitGadget, Mar 15, 2022
  7. Bagas SanjayaMar 16, 2022
  8. 1/2 tab completion of filenames for 'git restore'David Cantrell via GitGitGadget, Mar 15, 2022
  9. Junio C HamanoMar 15, 2022
  10. Junio C HamanoMar 15, 2022
  11. tab completion of filenames for 'git restore'David Cantrell via GitGitGadget, Mar 15, 2022
  12. Junio C HamanoMar 16, 2022
  13. David CantrellMar 17, 2022

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.