public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michiel W. Beijen" <mb@x14.nl>
To: git@vger.kernel.org
Cc: justinrdonnelly@gmail.com, "Michiel W. Beijen" <mb@x14.nl>
Subject: [PATCH] git-prompt: GIT_PS1_SHOWCONFLICTSTATE variable fix
Date: Tue, 19 Mar 2024 21:32:44 +0100	[thread overview]
Message-ID: <20240319203244.799796-1-mb@x14.nl> (raw)

There are a few environment variables that can influence the output for
the __git_ps1 macro in git-prompt.sh. All settings that are 'on/off'
types such as GIT_PS1_SHOWUNTRACKEDFILES and GIT_PS1_SHOWDIRTYSTATE
just take any value, and in the tests are tested with 'y', however
GIT_PS1_SHOWCONFLICTSTATE must be set to 'yes' otherwise it will not
work.

This commit changes that behaviour, and makes sure
GIT_PS1_SHOWCONFLICTSTATE is consistent with these other parameters.

Signed-off-by: Michiel W. Beijen <mb@x14.nl>
---
 contrib/completion/git-prompt.sh | 6 +++---
 t/t9903-bash-prompt.sh           | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 71f179cba3..fd6141e463 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -85,8 +85,8 @@
 # by setting GIT_PS1_OMITSPARSESTATE.
 #
 # If you would like to see a notification on the prompt when there are
-# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to "yes". The
-# prompt will include "|CONFLICT".
+# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to a nonempty
+# value. The prompt will include "|CONFLICT".
 #
 # If you would like to see more information about the identity of
 # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
@@ -528,7 +528,7 @@ __git_ps1 ()
 	fi
 
 	local conflict="" # state indicator for unresolved conflicts
-	if [[ "${GIT_PS1_SHOWCONFLICTSTATE}" == "yes" ]] &&
+	if [ -n "${GIT_PS1_SHOWCONFLICTSTATE-}" ] &&
 	   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then
 		conflict="|CONFLICT"
 	fi
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index d667dda654..6479a0d898 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -769,7 +769,7 @@ test_expect_success 'prompt - conflict indicator' '
 	test_when_finished "git reset --hard HEAD~" &&
 	test_must_fail git stash apply &&
 	(
-		GIT_PS1_SHOWCONFLICTSTATE="yes" &&
+		GIT_PS1_SHOWCONFLICTSTATE=y &&
 		__git_ps1 >"$actual"
 	) &&
 	test_cmp expected "$actual"

base-commit: 3bd955d26919e149552f34aacf8a4e6368c26cec
-- 
2.43.0


             reply	other threads:[~2024-03-19 20:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 20:32 Michiel W. Beijen [this message]
2024-03-19 22:58 ` [PATCH] git-prompt: GIT_PS1_SHOWCONFLICTSTATE variable fix Justin Donnelly
2024-03-24 17:18   ` Michiel Beijen
2024-03-24 19:01     ` Justin Donnelly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319203244.799796-1-mb@x14.nl \
    --to=mb@x14.nl \
    --cc=git@vger.kernel.org \
    --cc=justinrdonnelly@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox