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

[PATCH 2/2] completion: enhance "current branch" display

From
Junio C Hamano <gitster@pobox.com>
Date
May 10, 2009, 08:56 UTC
Message-ID
<7vvdo91glm.fsf@alter.siamese.dyndns.org>

Introduce GIT_PS1_DESCRIBE option you can set to "contains", "branch", or "describe" to tweak the way how a detached HEAD is described.

The default behaviour is to describe only exact match with some tag (otherwise use the first 7 hexdigits) as before.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * I do not think the new modes based on name-rev (aka "--contains") are
   much useful if you do your own development while on a detached HEAD,
   but they probably are useful for tourists who sightsee.
 contrib/completion/git-completion.bash |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ccc7e0d..2490d5f 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -108,10 +108,21 @@ __git_ps1 ()
 			fi
 
 			b="$(git symbolic-ref HEAD 2>/dev/null)" || {
-				b="$(git describe --exact-match HEAD 2>/dev/null)" ||
+
+				b="$(
+				case "${GIT_PS1_DESCRIBE_STYLE-}" in
+				(contains)
+					git describe --contains HEAD ;;
+				(branch)
+					git describe --contains --all HEAD ;;
+				(describe)
+					git describe HEAD ;;
+				(* | default)
+					git describe --exact-match HEAD ;;
+				esac 2>/dev/null)" ||
+
 				b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
 				b="unknown"
-
 				b="($b)"
 			}
 		fi
-- 
1.6.3.9.g6345d
Next: Johannes Sixt
Message 1 of 5 in “completion: enhance "current branch" display”
  1. 2/2 completion: enhance "current branch" displayJunio C Hamano, May 10, 2009
  2. Johannes SixtMay 10, 2009
  3. Michal NazarewiczMay 10, 2009
  4. Johannes SixtMay 10, 2009
  5. Shawn O. PearceMay 10, 2009

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.