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

Re: [PATCH] bash completion: Fix the . -> .. revision range completion

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 13, 2008, 21:38 UTC
Message-ID
<7vskudpiqq.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080713111847.29801.8969.stgit@localhost>
Petr Baudis <pasky@suse.cz> writes:
Show 9 quoted lines
> When Git sees a string with trailing dot on a place where revision
> range could occur, it will unconditionally append another dot to
> it to help complete a revision range. However, filespec can usually
> occur at such a place as well. I have been hitting this all the time
> lately with
>
> 	git log git-submodule.<tab>
>
> and the like.
Modulo s/Git/bash-completion/ ;-) I think this makes sense.
Show 5 quoted lines
> This patch will make Git perform the . -> .. completion in
> __git_complete_revlist only if there is no filename starting with
> the entered prefix available.  At few places, filename could not occur
> when calling __git_complete_revlist; however, taking this into account
> did not seem worth complicating the code further.

Theoretically we could take a hint from presense of '--' like d773c63 (bash: offer only paths after '--', 2008-07-08) did. If the command line has double-dash and the token we are looking at is before it, it cannot be pathname and this check does not have to trigger. But I agree that is not worth it, because this "theoretical" solution would mean that the user needs to something awkward like:

	git log v1.5.6. --<C-b><C-b><C-b><TAB>
to take advantage of it.

By the way, the above command line is another "dot" related frustration I always have. If you try:

	git log v1.5.6.<TAB>

the completion code adds a dot unconditionally when I want to choose from the list of v1.5.6.X tags. Of course, I can work this around by dropping the last dot before asking for completion, so it is not really a very big deal, but I mention it here because this annoyance is exactly in the same league as your "git-submodule.<TAB>" example.

"git show v1.5.6.<TAB>" does complete as expected, which is understandable (the command does not take range, and completion knows about it -- which is quite nice).

Show 13 quoted lines
>  contrib/completion/git-completion.bash |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 61581fe..fe24b8c 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -325,7 +325,12 @@ __git_complete_revlist ()
>  		__gitcomp "$(__git_refs)" "$pfx" "$cur"
>  		;;
>  	*.)
> -		__gitcomp "$cur."
> +		if ls "$cur"* >/dev/null 2>&1; then

There is a slight Yuck factor for using "ls" here but I do not think of a better alternative offhand.

Will queue on top of Shawn's previous one.  Thanks.
Previous: Jakub NarebskiNext: Shawn O. Pearce
Message 3 of 22 in “bash completion: Fix the . -> .. revision range completion”
  1. bash completion: Fix the . -> .. revision range completionPetr Baudis, Jul 13, 2008
  2. Jakub NarebskiJul 13, 2008
  3. Junio C HamanoJul 13, 2008
  4. Shawn O. PearceJul 13, 2008
  5. Petr BaudisJul 13, 2008
  6. Junio C HamanoJul 13, 2008
  7. Linus TorvaldsJul 13, 2008
  8. Shawn O. PearceJul 14, 2008
  9. Linus TorvaldsJul 14, 2008
  10. Shawn O. PearceJul 14, 2008
  11. Shawn O. PearceJul 14, 2008
  12. Björn SteinbrinkJul 14, 2008
  13. Björn SteinbrinkJul 14, 2008
  14. Andreas EricssonJul 14, 2008
  15. Linus TorvaldsJul 14, 2008
  16. Linus TorvaldsJul 14, 2008
  17. Shawn O. PearceJul 15, 2008
  18. Andreas EricssonJul 15, 2008
  19. Andreas EricssonJul 15, 2008
  20. Andreas EricssonJul 15, 2008
  21. Shawn O. PearceJul 15, 2008
  22. Andreas EricssonJul 16, 2008

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.