Skip to content

Commit 461c119

Browse files
committed
Merge branch 'sg/bash-prompt-untracked-optim'
Optimize computation of untracked status indicator by bash prompt script (in contrib/). * sg/bash-prompt-untracked-optim: bash prompt: faster untracked status indicator with untracked directories bash prompt: test untracked files status indicator with untracked dirs
2 parents 8e699cd + dd160d7 commit 461c119

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

contrib/completion/git-prompt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ __git_ps1 ()
491491

492492
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
493493
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
494-
git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
494+
git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
495495
then
496496
u="%${ZSH_VERSION+%}"
497497
fi

t/t9903-bash-prompt.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,31 @@ test_expect_success 'prompt - untracked files status indicator - untracked files
397397
test_cmp expected "$actual"
398398
'
399399

400+
test_expect_success 'prompt - untracked files status indicator - empty untracked dir' '
401+
printf " (master)" >expected &&
402+
mkdir otherrepo/untracked-dir &&
403+
test_when_finished "rm -rf otherrepo/untracked-dir" &&
404+
(
405+
GIT_PS1_SHOWUNTRACKEDFILES=y &&
406+
cd otherrepo &&
407+
__git_ps1 >"$actual"
408+
) &&
409+
test_cmp expected "$actual"
410+
'
411+
412+
test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' '
413+
printf " (master %%)" >expected &&
414+
mkdir otherrepo/untracked-dir &&
415+
test_when_finished "rm -rf otherrepo/untracked-dir" &&
416+
>otherrepo/untracked-dir/untracked-file &&
417+
(
418+
GIT_PS1_SHOWUNTRACKEDFILES=y &&
419+
cd otherrepo &&
420+
__git_ps1 >"$actual"
421+
) &&
422+
test_cmp expected "$actual"
423+
'
424+
400425
test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
401426
printf " (master %%)" >expected &&
402427
(

0 commit comments

Comments
 (0)