Skip to content

Commit adbbc6f

Browse files
committed
Merge branch 'mw/bash-prompt-show-untracked-config'
Allows skipping the untracked check GIT_PS1_SHOWUNTRACKEDFILES asks for the git-prompt (in contrib/) per repository. * mw/bash-prompt-show-untracked-config: t9903: add extra tests for bash.showDirtyState t9903: add tests for bash.showUntrackedFiles shell prompt: add bash.showUntrackedFiles option
2 parents 00abd71 + dc7e7bc commit adbbc6f

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

contrib/completion/git-prompt.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
#
4444
# If you would like to see if there're untracked files, then you can set
4545
# GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
46-
# files, then a '%' will be shown next to the branch name.
46+
# files, then a '%' will be shown next to the branch name. You can
47+
# configure this per-repository with the bash.showUntrackedFiles
48+
# variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is
49+
# enabled.
4750
#
4851
# If you would like to see the difference between HEAD and its upstream,
4952
# set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates you are behind, ">"
@@ -332,8 +335,10 @@ __git_ps1 ()
332335
fi
333336

334337
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
335-
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
336-
u="%"
338+
if [ "$(git config --bool bash.showUntrackedFiles)" != "false" ]; then
339+
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
340+
u="%"
341+
fi
337342
fi
338343
fi
339344

t/t9903-bash-prompt.sh

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,31 @@ test_expect_success 'prompt - dirty status indicator - before root commit' '
360360
test_cmp expected "$actual"
361361
'
362362

363-
test_expect_success 'prompt - dirty status indicator - disabled by config' '
363+
test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '
364+
printf " (master)" > expected &&
365+
echo "dirty" > file &&
366+
test_when_finished "git reset --hard" &&
367+
test_config bash.showDirtyState false &&
368+
(
369+
sane_unset GIT_PS1_SHOWDIRTYSTATE &&
370+
__git_ps1 > "$actual"
371+
) &&
372+
test_cmp expected "$actual"
373+
'
374+
375+
test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '
376+
printf " (master)" > expected &&
377+
echo "dirty" > file &&
378+
test_when_finished "git reset --hard" &&
379+
test_config bash.showDirtyState true &&
380+
(
381+
sane_unset GIT_PS1_SHOWDIRTYSTATE &&
382+
__git_ps1 > "$actual"
383+
) &&
384+
test_cmp expected "$actual"
385+
'
386+
387+
test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '
364388
printf " (master)" > expected &&
365389
echo "dirty" > file &&
366390
test_when_finished "git reset --hard" &&
@@ -372,6 +396,18 @@ test_expect_success 'prompt - dirty status indicator - disabled by config' '
372396
test_cmp expected "$actual"
373397
'
374398

399+
test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '
400+
printf " (master *)" > expected &&
401+
echo "dirty" > file &&
402+
test_when_finished "git reset --hard" &&
403+
test_config bash.showDirtyState true &&
404+
(
405+
GIT_PS1_SHOWDIRTYSTATE=y &&
406+
__git_ps1 > "$actual"
407+
) &&
408+
test_cmp expected "$actual"
409+
'
410+
375411
test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '
376412
printf " (GIT_DIR!)" > expected &&
377413
echo "dirty" > file &&
@@ -437,6 +473,46 @@ test_expect_success 'prompt - untracked files status indicator - untracked files
437473
test_cmp expected "$actual"
438474
'
439475

476+
test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
477+
printf " (master)" > expected &&
478+
test_config bash.showUntrackedFiles false &&
479+
(
480+
sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
481+
__git_ps1 > "$actual"
482+
) &&
483+
test_cmp expected "$actual"
484+
'
485+
486+
test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '
487+
printf " (master)" > expected &&
488+
test_config bash.showUntrackedFiles true &&
489+
(
490+
sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
491+
__git_ps1 > "$actual"
492+
) &&
493+
test_cmp expected "$actual"
494+
'
495+
496+
test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '
497+
printf " (master)" > expected &&
498+
test_config bash.showUntrackedFiles false &&
499+
(
500+
GIT_PS1_SHOWUNTRACKEDFILES=y &&
501+
__git_ps1 > "$actual"
502+
) &&
503+
test_cmp expected "$actual"
504+
'
505+
506+
test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '
507+
printf " (master %%)" > expected &&
508+
test_config bash.showUntrackedFiles true &&
509+
(
510+
GIT_PS1_SHOWUNTRACKEDFILES=y &&
511+
__git_ps1 > "$actual"
512+
) &&
513+
test_cmp expected "$actual"
514+
'
515+
440516
test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '
441517
printf " (GIT_DIR!)" > expected &&
442518
(

0 commit comments

Comments
 (0)