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

Re: [PATCH] bash: complete full refs

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 28, 2008, 00:51 UTC
Message-ID
<20081128005136.GE23984@spearce.org>
In-Reply-To
<20081128004638.GA6854@neumann>
SZEDER GGGbor <szeder@ira.uka.de> wrote:
> Sometimes it's handy to complete full refs, e.g. the user has some
> refs outside of refs/{heads,remotes,tags} or the user wants to
> complete some git command's special refs (like 'git show
> refs/bisect/bad').
...
Show 8 quoted lines
> On Thu, Nov 27, 2008 at 01:29:38PM -0800, Shawn O. Pearce wrote:
> > I wonder if the pattern shouldn't be:
> > 
> > 	refs|refs/*)
> > 
> > to reduce the risk of matching "refs-" and trying to do a full ref
> > match instead of a short ref match.
> Good point.  Adjusted the code and commit message accordingly.
Thanks.
Acked-by: Shawn O. Pearce <spearce@spearce.org>
 
Show 37 quoted lines
>  contrib/completion/git-completion.bash |   19 +++++++++++++++----
>  1 files changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 0ee071b..244ed41 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -188,11 +188,22 @@ __git_tags ()
>  
>  __git_refs ()
>  {
> -	local cmd i is_hash=y dir="$(__gitdir "$1")"
> +	local i is_hash=y dir="$(__gitdir "$1")"
> +	local cur="${COMP_WORDS[COMP_CWORD]}" format refs
>  	if [ -d "$dir" ]; then
> -		if [ -e "$dir/HEAD" ]; then echo HEAD; fi
> -		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
> -			refs/tags refs/heads refs/remotes
> +		case "$cur" in
> +		refs|refs/*)
> +			format="refname"
> +			refs="${cur%/*}"
> +			;;
> +		*)
> +			if [ -e "$dir/HEAD" ]; then echo HEAD; fi
> +			format="refname:short"
> +			refs="refs/tags refs/heads refs/remotes"
> +			;;
> +		esac
> +		git --git-dir="$dir" for-each-ref --format="%($format)" \
> +			$refs
>  		return
>  	fi
>  	for i in $(git ls-remote "$dir" 2>/dev/null); do
> -- 
> 1.6.0.4.814.gfe502
> 
-- 
Shawn.
Previous: SZEDER Gábor
Message 4 of 4 in “bash: complete full refs”
  1. bash: complete full refsSZEDER Gábor, Nov 27, 2008
  2. Shawn O. PearceNov 27, 2008
  3. bash: complete full refsSZEDER Gábor, Nov 28, 2008
  4. Shawn O. PearceNov 28, 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.