Skip to content

Commit e6ed5a4

Browse files
committed
Merge branch 'sg/bash-prompt-dirty-orphan' into maint
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
2 parents 22386ad + c26f70c commit e6ed5a4

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

contrib/completion/git-prompt.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,9 @@ __git_ps1 ()
476476
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
477477
[ "$(git config --bool bash.showDirtyState)" != "false" ]
478478
then
479-
git diff --no-ext-diff --quiet --exit-code || w="*"
480-
if [ -n "$short_sha" ]; then
481-
git diff-index --cached --quiet HEAD -- || i="+"
482-
else
479+
git diff --no-ext-diff --quiet || w="*"
480+
git diff --no-ext-diff --cached --quiet || i="+"
481+
if [ -z "$short_sha" ] && [ -z "$i" ]; then
483482
i="#"
484483
fi
485484
fi

t/t9903-bash-prompt.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,36 @@ test_expect_success 'prompt - dirty status indicator - dirty index and worktree'
273273
test_cmp expected "$actual"
274274
'
275275

276-
test_expect_success 'prompt - dirty status indicator - before root commit' '
277-
printf " (master #)" >expected &&
276+
test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
277+
printf " (orphan #)" >expected &&
278+
test_when_finished "git checkout master" &&
279+
git checkout --orphan orphan &&
280+
git reset --hard &&
281+
(
282+
GIT_PS1_SHOWDIRTYSTATE=y &&
283+
__git_ps1 >"$actual"
284+
) &&
285+
test_cmp expected "$actual"
286+
'
287+
288+
test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' '
289+
printf " (orphan +)" >expected &&
290+
test_when_finished "git checkout master" &&
291+
git checkout --orphan orphan &&
292+
(
293+
GIT_PS1_SHOWDIRTYSTATE=y &&
294+
__git_ps1 >"$actual"
295+
) &&
296+
test_cmp expected "$actual"
297+
'
298+
299+
test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' '
300+
printf " (orphan *+)" >expected &&
301+
test_when_finished "git checkout master" &&
302+
git checkout --orphan orphan &&
303+
>file &&
278304
(
279305
GIT_PS1_SHOWDIRTYSTATE=y &&
280-
cd otherrepo &&
281306
__git_ps1 >"$actual"
282307
) &&
283308
test_cmp expected "$actual"

0 commit comments

Comments
 (0)