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

[PATCH v2 4/5] git-prompt.sh: do not print duplicate clean color code

From
Eduardo R. D'Avila <erdavila@gmail.com>
Date
Jun 26, 2013, 03:05 UTC
Message-ID
<6dc7fc8c8033186b296616238481a86946ee36f0.1372211661.git.erdavila@gmail.com>
In-Reply-To
<cover.1372211661.git.erdavila@gmail.com>

Do not print a duplicate clean color code when there is no other indicators other than the current branch in colored prompt.

Acked-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Eduardo R. D'Avila <erdavila@gmail.com>
---
1	1	contrib/completion/git-prompt.sh
4	4	t/t9903-bash-prompt.sh
 contrib/completion/git-prompt.sh | 2 +-
 t/t9903-bash-prompt.sh           | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index fdedb45..545518a 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -253,8 +253,8 @@ __git_ps1_colorize_gitstring ()
 		branch_color="$bad_color"
 	fi
 	c="$branch_color$c"
-	b="$b$c_clear"
 
+	z="$c_clear$z"
 	if [ "$w" = "*" ]; then
 		w="$bad_color$w"
 	fi
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index f250dfc..5cd138e 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -551,7 +551,7 @@ test_expect_success 'prompt - pc mode' '
 '
 
 test_expect_success 'prompt - bash color pc mode - branch name' '
-	printf "BEFORE: (${c_green}master${c_clear}${c_clear}):AFTER" >expected &&
+	printf "BEFORE: (${c_green}master${c_clear}):AFTER" >expected &&
 	(
 		GIT_PS1_SHOWCOLORHINTS=y &&
 		__git_ps1 "BEFORE:" ":AFTER" >"$actual"
@@ -561,7 +561,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}${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" &&
 	(
@@ -627,7 +627,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - befo
 '
 
 test_expect_success 'prompt - bash color pc mode - inside .git directory' '
-	printf "BEFORE: (${c_green}GIT_DIR!${c_clear}${c_clear}):AFTER" >expected &&
+	printf "BEFORE: (${c_green}GIT_DIR!${c_clear}):AFTER" >expected &&
 	echo "dirty" >file &&
 	test_when_finished "git reset --hard" &&
 	(
@@ -666,7 +666,7 @@ test_expect_success 'prompt - bash color pc mode - untracked files status indica
 '
 
 test_expect_success 'prompt - zsh color pc mode' '
-	printf "BEFORE: (%%F{green}master%%f%%f):AFTER" >expected &&
+	printf "BEFORE: (%%F{green}master%%f):AFTER" >expected &&
 	(
 		ZSH_VERSION=5.0.0 &&
 		GIT_PS1_SHOWCOLORHINTS=y &&
-- 
1.8.3.1.590.g42a98dd
Previous: Eduardo R. D'AvilaNext: Eduardo R. D'Avila
Message 5 of 10 in “git-prompt: cleaning and improvement”
  1. 0/5 git-prompt: cleaning and improvementEduardo R. D'Avila, Jun 26, 2013
  2. 1/5 t9903: add tests for git-prompt pcmodeEduardo R. D'Avila, Jun 26, 2013
  3. 2/5 git-prompt.sh: refactor colored prompt codeEduardo R. D'Avila, Jun 26, 2013
  4. 3/5 t9903: remove redundant testsEduardo R. D'Avila, Jun 26, 2013
  5. 4/5 git-prompt.sh: do not print duplicate clean color codeEduardo R. D'Avila, Jun 26, 2013
  6. 5/5 git-prompt.sh: add missing information in commentsEduardo R. D'Avila, Jun 26, 2013
  7. Junio C HamanoJun 27, 2013
  8. Eduardo R. D'AvilaJun 28, 2013
  9. SZEDER GáborJun 28, 2013
  10. Junio C HamanoJun 28, 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.