From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Jeff King <peff@peff.net>
Cc: "Thomas Rast" <tr@thomasrast.ch>,
git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH 3/3] bash prompt: indicate dirty index even on orphan branches
Date: Sat, 21 Nov 2015 12:30:09 +0100 [thread overview]
Message-ID: <1448105409-4494-3-git-send-email-szeder@ira.uka.de> (raw)
In-Reply-To: <1448105409-4494-1-git-send-email-szeder@ira.uka.de>
__git_ps1() doesn't indicate dirty index while on an orphan branch.
To check the dirtiness of the index, __git_ps1() runs 'git diff-index
--cached ... HEAD', which doesn't work on an orphan branch,
because HEAD doesn't point to a valid commit.
Run 'git diff ... --cached' instead, as it does the right thing both
on valid and invalid HEAD, i.e. compares the index to the existing
HEAD in the former case and to the empty tree in the latter. This
fixes the two failing tests added in the first commit of this series.
The dirtiness of the worktree is already checked with 'git diff' and
is displayed correctly even on an orphan branch.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
contrib/completion/git-prompt.sh | 5 ++---
t/t9903-bash-prompt.sh | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 7a95fbdcfd..64219e631a 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -477,9 +477,8 @@ __git_ps1 ()
[ "$(git config --bool bash.showDirtyState)" != "false" ]
then
git diff --no-ext-diff --quiet || w="*"
- if [ -n "$short_sha" ]; then
- git diff-index --cached --quiet HEAD -- || i="+"
- else
+ git diff --no-ext-diff --cached --quiet || i="+"
+ if [ -z "$short_sha" ] && [ -z "$i" ]; then
i="#"
fi
fi
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 2c9d1f928a..af82049f82 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -285,7 +285,7 @@ test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
test_cmp expected "$actual"
'
-test_expect_failure 'prompt - dirty status indicator - orphan branch - dirty index' '
+test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' '
printf " (orphan +)" >expected &&
test_when_finished "git checkout master" &&
git checkout --orphan orphan &&
@@ -296,7 +296,7 @@ test_expect_failure 'prompt - dirty status indicator - orphan branch - dirty ind
test_cmp expected "$actual"
'
-test_expect_failure 'prompt - dirty status indicator - orphan branch - dirty index and worktree' '
+test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' '
printf " (orphan *+)" >expected &&
test_when_finished "git checkout master" &&
git checkout --orphan orphan &&
--
2.6.3.402.geb6a0f7
prev parent reply other threads:[~2015-11-21 11:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-21 11:30 [PATCH 1/3] bash prompt: test dirty index and worktree while on an orphan branch SZEDER Gábor
2015-11-21 11:30 ` [PATCH 2/3] bash prompt: remove a redundant command line option SZEDER Gábor
2015-11-21 14:46 ` [PATCH v1.5 2/3] bash prompt: remove a redundant 'git diff' option SZEDER Gábor
2015-11-21 11:30 ` SZEDER Gábor [this message]
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=1448105409-4494-3-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=tr@thomasrast.ch \
/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;
as well as URLs for NNTP newsgroup(s).