From c26f70ceb3960603a78010c87f8ad11820ab6561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Sat, 21 Nov 2015 12:30:09 +0100 Subject: bash prompt: indicate dirty index even on orphan branches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __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 Signed-off-by: Jeff King --- contrib/completion/git-prompt.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'contrib') 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 -- cgit v1.2.3