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

[PATCH] prompt: do not double-discriminate detached HEAD

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jul 7, 2013, 12:52 UTC
Message-ID
<1373201565-14030-1-git-send-email-artagnon@gmail.com>

When GIT_PS1_SHOWCOLORHINTS is turned on, there is no need to put a detached HEAD within parenthesis: the color can be used to discriminate the detached HEAD.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 For cuteness :)
 contrib/completion/git-prompt.sh | 5 ++++-
 t/t9903-bash-prompt.sh           | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index a81ef5a..37e66a2 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -372,7 +372,10 @@ __git_ps1 ()
 				esac 2>/dev/null)" ||
 
 				b="$short_sha..."
-				b="($b)"
+				# if there is no color, use
+				# parenthesis to indicate that the
+				# HEAD is detached
+				test -n "${GIT_PS1_SHOWCOLORHINTS-}" || b="($b)"
 			fi
 		fi
 	fi
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 3c3e4e8..c44b1a6 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -450,7 +450,7 @@ test_expect_success 'prompt - bash color pc mode - branch name' '
 '
 
 test_expect_success 'prompt - bash color pc mode - detached head' '
-	printf "BEFORE: (${c_red}(%s...)${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected &&
+	printf "BEFORE: (${c_red}%s...${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected &&
 	git checkout b1^ &&
 	test_when_finished "git checkout master" &&
 	(
-- 
1.8.3.2.737.gcbc076a.dirty
Next: John Szakmeister
Message 1 of 6 in “prompt: do not double-discriminate detached HEAD”
  1. prompt: do not double-discriminate detached HEADRamkumar Ramachandra, Jul 7, 2013
  2. John SzakmeisterJul 7, 2013
  3. Junio C HamanoJul 7, 2013
  4. Kyle McKayJul 7, 2013
  5. Ramkumar RamachandraJul 8, 2013
  6. Eduardo R. D'AvilaJul 8, 2013

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.