Git fork

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

+31 -7
+3 -4
contrib/completion/git-prompt.sh
··· 476 476 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] && 477 477 [ "$(git config --bool bash.showDirtyState)" != "false" ] 478 478 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 483 482 i="#" 484 483 fi 485 484 fi
+28 -3
t/t9903-bash-prompt.sh
··· 273 273 test_cmp expected "$actual" 274 274 ' 275 275 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 && 278 304 ( 279 305 GIT_PS1_SHOWDIRTYSTATE=y && 280 - cd otherrepo && 281 306 __git_ps1 >"$actual" 282 307 ) && 283 308 test_cmp expected "$actual"