aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hilburn <bhilburn@gmail.com>2018-11-12 18:44:23 +0300
committerGitHub <noreply@github.com>2018-11-12 18:44:23 +0300
commitc7d8ef07b76b9dc6022c656c761b6422ce919e94 (patch)
treec9ce6eba19adeeaaaa1a0f9a7d40986d71e6229e
parent78df520772135b7924d6fc84f2bdbde0f1c650b2 (diff)
parent6cfe8f8d965bfb6a1314b907e4ab970dd42d4188 (diff)
Merge pull request #1061 from dritter/speedup_vcs4_master
Backport of vcs-speedup #4 into master.
-rwxr-xr-xfunctions/vcs.zsh28
-rwxr-xr-xtest/segments/vcs-git.spec19
2 files changed, 40 insertions, 7 deletions
diff --git a/functions/vcs.zsh b/functions/vcs.zsh
index 321a1502..6c9bd055 100755
--- a/functions/vcs.zsh
+++ b/functions/vcs.zsh
@@ -8,10 +8,28 @@
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false
function +vi-git-untracked() {
+ [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return
+ # If we are in a .git folder, do not check for untracked files.
+ [[ "${PWD:A}" =~ "\.git/" ]] && return
+
+ # If we are in a repos root folder, vcs_comm[gitdir] yields ".git".
+ # Inside the .git dir itself (and not a subdir of it) the variable
+ # yields ".". In any other case (either a subdirectory of .git or
+ # the repo itself), the value of vcs_comm[gitdir] is the absolute
+ # path to the .git directory.
+ # Therefore we can step up a directory, if we are inside the .git
+ # folder. And in any other case, use the parent directory of the
+ # gitdir.
+ local repoDir="."
+ # Getting the parent dir of the current dir "." is still ".", so
+ # is is safe to do this always.
+ [[ "${vcs_comm[gitdir]}" != ".git" ]] && repoDir="${vcs_comm[gitdir]:A:h}"
+ [[ "${vcs_comm[gitdir]}" == "." ]] && repoDir="${PWD:A:h}"
+
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
VCS_WORKDIR_HALF_DIRTY=true
- elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then
+ elif [[ "$(command git ls-files --others --exclude-standard "${repoDir}")" != "" ]]; then
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
VCS_WORKDIR_HALF_DIRTY=true
else
@@ -96,11 +114,9 @@ function +vi-git-tagname() {
# Show count of stashed changes
# Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268
function +vi-git-stash() {
- local -a stashes
-
- if [[ -s "${vcs_comm[gitdir]}/refs/stash" ]] ; then
- stashes=$(command git stash list 2>/dev/null | wc -l)
- hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${stashes// /}"
+ if [[ -s "${vcs_comm[gitdir]}/logs/refs/stash" ]] ; then
+ local -a stashes=( "${(@f)"$(<${vcs_comm[gitdir]}/logs/refs/stash)"}" )
+ hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${#stashes}"
fi
}
diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec
index fed1df19..17a277fb 100755
--- a/test/segments/vcs-git.spec
+++ b/test/segments/vcs-git.spec
@@ -473,4 +473,21 @@ function testDetectingUntrackedFilesInNestedSubmodulesWork() {
assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"
}
-source shunit2/shunit2 \ No newline at end of file
+function testDetectingUntrackedFilesInCleanSubdirectoryWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true"
+ unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
+ mkdir clean-folder
+ touch clean-folder/file.txt
+ mkdir dirty-folder
+ touch dirty-folder/file.txt
+ git add . 2>/dev/null
+ git commit -m "Initial commit" >/dev/null
+ touch dirty-folder/new-file.txt
+ cd clean-folder
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2