Merge branch 'sg/bash-prompt-untracked-optim'
authorJunio C Hamano <gitster@pobox.com>
Mon, 3 Aug 2015 18:01:26 +0000 (11:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Aug 2015 18:01:26 +0000 (11:01 -0700)
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

contrib/completion/git-prompt.sh
t/t9903-bash-prompt.sh
index 366f0bc1e9b5597f1714574700452cd241c14f8d..07b52bedf183231b5708caf1ce255a115c9a980c 100644 (file)
@@ -491,7 +491,7 @@ __git_ps1 ()
 
                if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
                   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
-                  git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
+                  git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
                then
                        u="%${ZSH_VERSION+%}"
                fi
index 49d58e6726836194e7a716365007465056744fc5..6b68777b9804a86a9d6e0bef63b5073e895efcfe 100755 (executable)
@@ -397,6 +397,31 @@ test_expect_success 'prompt - untracked files status indicator - untracked files
        test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - untracked files status indicator - empty untracked dir' '
+       printf " (master)" >expected &&
+       mkdir otherrepo/untracked-dir &&
+       test_when_finished "rm -rf otherrepo/untracked-dir" &&
+       (
+               GIT_PS1_SHOWUNTRACKEDFILES=y &&
+               cd otherrepo &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' '
+       printf " (master %%)" >expected &&
+       mkdir otherrepo/untracked-dir &&
+       test_when_finished "rm -rf otherrepo/untracked-dir" &&
+       >otherrepo/untracked-dir/untracked-file &&
+       (
+               GIT_PS1_SHOWUNTRACKEDFILES=y &&
+               cd otherrepo &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
 test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
        printf " (master %%)" >expected &&
        (