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

[PATCH 6/6] Use git-describe --exact-match in bash prompt on detached HEAD

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 24, 2008, 08:07 UTC
Message-ID
<20080224080733.GF22587@spearce.org>

Most of the time when I am on a detached HEAD and I am not doing a rebase or bisect operation the working directory is sitting on a tagged release of the repository. Showing the tag name instead of the commit SHA-1 is much more descriptive and a much better reminder of the state of this working directory.

Now that git-describe --exact-match is available as a cheap means of obtaining the exact annotated tag or nothing at all, we can favor the annotated tag name over the abbreviated commit SHA-1.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4ea727b..8722a68 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -91,7 +91,10 @@ __git_ps1 ()
 			fi
 			if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
 			then
-				b="$(cut -c1-7 $g/HEAD)..."
+				if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
+				then
+					b="$(cut -c1-7 $g/HEAD)..."
+				fi
 			fi
 		fi
 
-- 
1.5.4.3.295.g6b554
Message 1 of 1 in “Use git-describe --exact-match in bash prompt on detached HEAD”
  1. 6/6 Use git-describe --exact-match in bash prompt on detached HEADShawn O. Pearce, Feb 24, 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.