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

[PATCH 10/10] Support bash completion of refs/remote.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 27, 2006, 08:42 UTC
Message-ID
<20061127084232.GJ19745@spearce.org>
In-Reply-To
<de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>

Now that people are really likely to start using separate remotes (due to the default in git-clone changing) we should support ref completion for these refs in as many commands as possible.

While we are working on this routine we should use for-each-ref to obtain a list of local refs, as this should run faster than peek-remote as it does not need to dereference tag objects in order to produce the list of refs back to us. It should also be more friendly to users of StGIT as we won't generate a list of the StGIT metadata refs.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b456a3b..df67f8e 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -47,16 +47,26 @@ __git_refs ()
 {
 	local cmd i is_hash=y dir="${1:-$(__gitdir)}"
 	if [ -d "$dir" ]; then
-		cmd=git-peek-remote
-	else
-		cmd=git-ls-remote
+		if [ -e "$dir/HEAD" ]; then echo HEAD; fi
+		for i in $(git --git-dir="$dir" \
+			for-each-ref --format='%(refname)' \
+			refs/tags refs/heads refs/remotes); do
+			case "$i" in
+				refs/tags/*)    echo "${i#refs/tags/}" ;;
+				refs/heads/*)   echo "${i#refs/heads/}" ;;
+				refs/remotes/*) echo "${i#refs/remotes/}" ;;
+				*)              echo "$i" ;;
+			esac
+		done
+		return
 	fi
-	for i in $($cmd "$dir" 2>/dev/null); do
+	for i in $(git-ls-remote "$dir" 2>/dev/null); do
 		case "$is_hash,$i" in
 		y,*) is_hash=n ;;
 		n,*^{}) is_hash=y ;;
 		n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
 		n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
+		n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
 		n,*) is_hash=y; echo "$i" ;;
 		esac
 	done
Previous: Shawn PearceNext: Shawn Pearce
Message 15 of 19 in “Hide plumbing/transport commands from bash completion.”
  1. 2/10 Hide plumbing/transport commands from bash completion.Shawn O. Pearce, Nov 27, 2006
  2. 3/10 Teach bash how to complete options for git-name-rev.Shawn O. Pearce, Nov 27, 2006
  3. 4/10 Add current branch in PS1 support to git-completion.bash.Shawn O. Pearce, Nov 27, 2006
  4. SeanNov 27, 2006
  5. 5/10 Teach bash how to complete git-format-patch.Shawn O. Pearce, Nov 27, 2006
  6. Jakub NarebskiNov 27, 2006
  7. 6/10 Teach bash how to complete git-cherry-pick.Shawn O. Pearce, Nov 27, 2006
  8. 7/10 Teach bash how to complete git-rebase.Shawn O. Pearce, Nov 27, 2006
  9. 8/10 Teach bash about git log/show/whatchanged options.Shawn O. Pearce, Nov 27, 2006
  10. 9/10 Allow completion of --committer and --author arguments to git log.Shawn O. Pearce, Nov 27, 2006
  11. Nicolas VilzNov 27, 2006
  12. Shawn PearceNov 27, 2006
  13. Junio C HamanoNov 27, 2006
  14. Shawn PearceNov 27, 2006
  15. 10/10 Support bash completion of refs/remote.Shawn O. Pearce, Nov 27, 2006
  16. Shawn PearceNov 27, 2006
  17. SeanNov 27, 2006
  18. Shawn PearceNov 27, 2006
  19. SeanNov 27, 2006

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.