Skip to content

Commit 9bdc517

Browse files
CodeMan99gitster
authored andcommitted
git prompt: use toplevel to find untracked files
The __git_ps1() prompt function would not show an untracked state when all the untracked files are outside the current working directory. Signed-off-by: Cody A Taylor <[email protected]> Helped-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 282616c commit 9bdc517

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

contrib/completion/git-prompt.sh

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

475475
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
476476
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
477-
git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
477+
git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
478478
then
479479
u="%${ZSH_VERSION+%}"
480480
fi

t/t9903-bash-prompt.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,17 @@ test_expect_success 'prompt - untracked files status indicator - untracked files
395395
test_cmp expected "$actual"
396396
'
397397

398+
test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
399+
printf " (master %%)" >expected &&
400+
(
401+
mkdir -p ignored_dir &&
402+
cd ignored_dir &&
403+
GIT_PS1_SHOWUNTRACKEDFILES=y &&
404+
__git_ps1 >"$actual"
405+
) &&
406+
test_cmp expected "$actual"
407+
'
408+
398409
test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
399410
printf " (master)" >expected &&
400411
test_config bash.showUntrackedFiles false &&

0 commit comments

Comments
 (0)