mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-18 21:41:57 +00:00
Fix error if user cds into a .git directory
In this case is was previously not possible to get the untracked status. Now we temporarily change the directory to the repo root folder and then get the list of untracked files.
This commit is contained in:
parent
a90258a9ee
commit
645b974677
1 changed files with 21 additions and 3 deletions
|
@ -8,17 +8,35 @@
|
||||||
|
|
||||||
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false
|
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false
|
||||||
function +vi-git-untracked() {
|
function +vi-git-untracked() {
|
||||||
[[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return
|
[[ -z "${vcs_comm[gitdir]}" ]] && return
|
||||||
|
|
||||||
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then
|
# 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]:h}"
|
||||||
|
[[ "${vcs_comm[gitdir]}" == "." ]] && repoDir=".."
|
||||||
|
|
||||||
|
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(cd ${repoDir} && command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then
|
||||||
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
||||||
VCS_WORKDIR_HALF_DIRTY=true
|
VCS_WORKDIR_HALF_DIRTY=true
|
||||||
elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then
|
elif [[ "$(cd ${repoDir} && command git ls-files --others --exclude-standard)" != "" ]]; then
|
||||||
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
||||||
VCS_WORKDIR_HALF_DIRTY=true
|
VCS_WORKDIR_HALF_DIRTY=true
|
||||||
else
|
else
|
||||||
VCS_WORKDIR_HALF_DIRTY=false
|
VCS_WORKDIR_HALF_DIRTY=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If we are in any other directory than the repo root, we want
|
||||||
|
# to go back a directory.
|
||||||
|
[[ "${vcs_comm[gitdir]}" != ".git" ]] && cd - >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function +vi-git-aheadbehind() {
|
function +vi-git-aheadbehind() {
|
||||||
|
|
Loading…
Reference in a new issue