Skip to content

Commit

Permalink
Merge branch 'sg/bash-prompt-dirty-orphan'
Browse files Browse the repository at this point in the history
Produce correct "dirty" marker for shell prompts, even when we
are on an orphan or an unborn branch.

* sg/bash-prompt-dirty-orphan:
  bash prompt: indicate dirty index even on orphan branches
  bash prompt: remove a redundant 'git diff' option
  bash prompt: test dirty index and worktree while on an orphan branch
  • Loading branch information
Junio C Hamano committed Dec 4, 2015
2 parents 3a5b6ee + c26f70c commit 80c17ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
7 changes: 3 additions & 4 deletions contrib/completion/git-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,9 @@ __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
git diff --no-ext-diff --quiet || w="*"
git diff --no-ext-diff --cached --quiet || i="+"
if [ -z "$short_sha" ] && [ -z "$i" ]; then
i="#"
fi
fi
Expand Down
31 changes: 28 additions & 3 deletions t/t9903-bash-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,36 @@ test_expect_success 'prompt - dirty status indicator - dirty index and worktree'
test_cmp expected "$actual"
'

test_expect_success 'prompt - dirty status indicator - before root commit' '
printf " (master #)" >expected &&
test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
printf " (orphan #)" >expected &&
test_when_finished "git checkout master" &&
git checkout --orphan orphan &&
git reset --hard &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'

test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' '
printf " (orphan +)" >expected &&
test_when_finished "git checkout master" &&
git checkout --orphan orphan &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'

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 &&
>file &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
cd otherrepo &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
Expand Down

0 comments on commit 80c17ca

Please sign in to comment.