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

[PATCH] git-prompt.sh: make '+' work for unborn branches

From
MBMaurice Bos <m-ou.se@m-ou.se>
Date
Mar 5, 2014, 23:05 UTC
Message-ID
<20140305233219.A6FF54284F@server>

For unborn branches, it now compares the index against the empty tree. (Just like git status does.)

Signed-off-by: Maurice Bos <m-ou.se@m-ou.se>
---
 contrib/completion/git-prompt.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 7b732d2..f656838 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -407,12 +407,14 @@ __git_ps1 ()
 		if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
 		   [ "$(git config --bool bash.showDirtyState)" != "false" ]
 		then
-			git diff --no-ext-diff --quiet --exit-code || w="*"
-			if [ -n "$short_sha" ]; then
-				git diff-index --cached --quiet HEAD -- || i="+"
-			else
+			local treeish=HEAD
+			if [ -z "$short_sha" ]; then
 				i="#"
+				# the empty tree
+				treeish=4b825dc642cb6eb9a060e54bf8d69288fbee4904
 			fi
+			git diff --no-ext-diff --quiet --exit-code || w="*"
+			git diff-index --cached --quiet $treeish -- || i="$i+"
 		fi
 		if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
 		   [ -r "$g/refs/stash" ]; then
-- 
1.8.5.rc0.23.gaa27064
Next: Maurice Bos
Message 1 of 3 in “git-prompt.sh: make '+' work for unborn branches”
  1. git-prompt.sh: make '+' work for unborn branchesMaurice Bos, Mar 5, 2014
  2. Maurice BosMar 6, 2014
  3. Jeff KingMar 27, 2014

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.