1
0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-12 19:18:28 +02:00

Merge pull request #1048 from dritter/speedup_vcs_master

Speedup vcs master
This commit is contained in:
Ben Hilburn 2018-11-05 11:54:02 -05:00 committed by GitHub
commit 23f0a1ddcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 21 deletions

View File

@ -6,18 +6,12 @@
# https://github.com/bhilburn/powerlevel9k
################################################################
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY true
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false
function +vi-git-untracked() {
# TODO: check git >= 1.7.2 - see function git_compare_version()
local FLAGS
FLAGS=('--porcelain')
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "false" ]]; then
FLAGS+='--ignore-submodules=dirty'
fi
if [[ $(command git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \
-n $(command git status ${FLAGS} | \grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive '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
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
VCS_WORKDIR_HALF_DIRTY=true
else
@ -26,30 +20,28 @@ function +vi-git-untracked() {
}
function +vi-git-aheadbehind() {
local ahead behind branch_name
local ahead behind
local -a gitstatus
branch_name=$(command git symbolic-ref --short HEAD 2>/dev/null)
# for git prior to 1.7
# ahead=$(command git rev-list origin/${branch_name}..HEAD | wc -l)
ahead=$(command git rev-list "${branch_name}"@{upstream}..HEAD 2>/dev/null | wc -l)
# ahead=$(command git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
ahead=$(command git rev-list --count "${hook_com[branch]}"@{upstream}..HEAD 2>/dev/null)
(( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" )
# for git prior to 1.7
# behind=$(command git rev-list HEAD..origin/${branch_name} | wc -l)
behind=$(command git rev-list HEAD.."${branch_name}"@{upstream} 2>/dev/null | wc -l)
# behind=$(command git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
behind=$(command git rev-list --count HEAD.."${hook_com[branch]}"@{upstream} 2>/dev/null)
(( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" )
hook_com[misc]+=${(j::)gitstatus}
}
function +vi-git-remotebranch() {
local remote branch_name
local remote
local branch_name="${hook_com[branch]}"
# Are we on a remote-tracking branch?
remote=${$(command git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/}
branch_name=$(command git symbolic-ref --short HEAD 2>/dev/null)
if [[ -n "$POWERLEVEL9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH" ]]; then
set_default POWERLEVEL9K_VCS_SHORTEN_DELIMITER $'\U2026'
@ -106,7 +98,7 @@ function +vi-git-tagname() {
function +vi-git-stash() {
local -a stashes
if [[ -s $(command git rev-parse --git-dir)/refs/stash ]] ; then
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// /}"
fi

View File

@ -375,4 +375,102 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() {
assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(build_left_prompt)"
}
function testDetectingUntrackedFilesInSubmodulesWork() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true"
unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
mkdir ../submodule
cd ../submodule
git init 1>/dev/null
touch "i-am-tracked.txt"
git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null
local submodulePath="${PWD}"
cd -
git submodule add "${submodulePath}" 2>/dev/null
git commit -m "Add submodule" 1>/dev/null
# Go into checked-out submodule path
cd submodule
# Create untracked file
touch "i-am-untracked.txt"
cd -
source ${P9K_HOME}/powerlevel9k.zsh-theme
assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"
}
function testDetectinUntrackedFilesInMainRepoWithDirtySubmodulesWork() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true"
unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
mkdir ../submodule
cd ../submodule
git init 1>/dev/null
touch "i-am-tracked.txt"
git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null
local submodulePath="${PWD}"
cd -
git submodule add "${submodulePath}" 2>/dev/null
git commit -m "Add submodule" 1>/dev/null
# Create untracked file
touch "i-am-untracked.txt"
source ${P9K_HOME}/powerlevel9k.zsh-theme
assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"
}
function testDetectingUntrackedFilesInNestedSubmodulesWork() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true"
unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
local mainRepo="${PWD}"
mkdir ../submodule
cd ../submodule
git init 1>/dev/null
touch "i-am-tracked.txt"
git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null
local submodulePath="${PWD}"
mkdir ../subsubmodule
cd ../subsubmodule
git init 1>/dev/null
touch "i-am-tracked-too.txt"
git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null
local subsubmodulePath="${PWD}"
cd "${submodulePath}"
git submodule add "${subsubmodulePath}" 2>/dev/null
git commit -m "Add subsubmodule" 1>/dev/null
cd "${mainRepo}"
git submodule add "${submodulePath}" 2>/dev/null
git commit -m "Add submodule" 1>/dev/null
git submodule update --init --recursive 2>/dev/null
cd submodule/subsubmodule
# Create untracked file
touch "i-am-untracked.txt"
cd -
source ${P9K_HOME}/powerlevel9k.zsh-theme
assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"
}
source shunit2/shunit2