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

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

From
Andreas Ericsson <ae@op5.se>
Date
Jul 15, 2008, 08:05 UTC
Message-ID
<487C5A2D.3000707@op5.se>
In-Reply-To
<20080715042553.GD2432@spearce.org>
Shawn O. Pearce wrote:
Show 33 quoted lines
> Linus Torvalds <torvalds@linux-foundation.org> wrote:
>> On Mon, 14 Jul 2008, Shawn O. Pearce wrote:
>>> What is $COMP_WORDBREAKS set to in your shell?  In mine it
>>> appears to be:
>>>
>>> 	" \"'@><=;|&(:"
>> Ahhah. Indeed. I don't have the ':'.
> ...
>> Umm, if so, git should just set it in the completion script, no?
> 
> OK, so it turns out not having : in COMP_WORDBREAKS is a very common
> case that we should somehow deal with, to aid our users.
> 
> I'm concerned about just setting COMP_WORDBREAKS back to the default
> in the git completion script because then we get into an ordering
> game with the profile scripts, don't we?  If git completion sources
> before the gvfs script we don't get our COMP_WORDBREAKS setting.
> 
> I think we may need to do two things.
> 
> If COMP_WORDBREAKS doesn't contain a :, try to reset it to include
> one when the script is sourced.  This may "fix" git completion but
> make gvfs completion act differently, resulting in a thread on the
> gvfs lists.  ;-)
> 
> If COMP_WORDBREAKS doesn't contain : during a completion event than
> we need to do what your original patch asked, which is to include
> "$ref:" in the prefix, so the ref isn't lost.
> 
> At least we understand the problem now, finally.  I'll try to write
> up a patch for it tomorrow.  Unfortunately packing to move has been
> really sucking up my time lately.
>  

I beat you to it ;-) This works just fine for me regardless of whether or not I have a colon in COMP_WORDBREAKS.

--%<--%<--%<--
From: Andreas Ericsson <ae@op5.se>
Subject: git-completion.bash: Handle "rev:path" completion properly

The gvfs package on at least Fedora9 installs its own bash completion script which removes the colon from COMP_WORDBREAKS, which acts as a list of characters where bash should consider as word boundaries. Doing so breaks the git bash completion script when handling any rev:path style argument.

This patch fixes it by prepending the "rev" part and the colon (which otherwise gets lost) before adding the "path" part if COMP_WORDBREAKS doesn't contain the colon we would otherwise need.

Also fixes a nearby indented-with-spaces issue.
Spotted-by: Linus Torvalds <torvalds@linux-foundation.org>
Investigated-by: Björn Steinbrink <b.steinbrink@gmx.de>
Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 contrib/completion/git-completion.bash |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index d268e6f..e138022 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -293,7 +293,11 @@ __git_complete_file ()
 		*)
 			ls="$ref"
 			;;
-	    esac
+		esac
+		# When completing something like 'rev:path', bash behaves
+		# differently whether or not COMP_WORDBREAKS contains a
+		# colon or not. This lets it handle both cases
+		test "${COMP_WORDBREAKS//:}" = "$COMP_WORDBREAKS" && pfx="$ref:$pfx"
 		COMPREPLY=($(compgen -P "$pfx" \
 			-W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
 				| sed '/^100... blob /s,^.*	,,
-- 
1.5.6.3.315.g10ce0

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: Shawn O. PearceNext: Andreas Ericsson
Message 18 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.