1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-05-17 21:46:04 +02:00

32528: vcs_info: Add check-for-staged-changes

This commit is contained in:
Daniel Shahaf 2014-03-28 11:00:35 +00:00 committed by Frank Terbeck
parent 4dfe62640a
commit eb4c70d0b7
5 changed files with 41 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2014-04-05 Daniel Shahaf <d.s@daniel.shahaf.name>
* 32528: Completion/Zsh/Command/_zstyle, Doc/Zsh/contrib.yo,
Functions/VCS_Info/Backends/VCS_INFO_get_data_git,
Misc/vcs_info-examples: vcs_info: Add check-for-staged-changes
2014-03-28 Peter Stephenson <p.w.stephenson@ntlworld.com>
* Danek Duvall: 32505: Completion/Unix/Command/_pgrep: improved

View File

@ -182,6 +182,8 @@ styles=(
disable v:vcs
disable-patterns v:
check-for-changes v:bool
check-for-staged-changes
v:bool
stagedstr v:
unstagedstr v:
command v:_command_names

View File

@ -837,6 +837,18 @@ Note, the actions taken if this style is enabled are potentially expensive
(read: they may be slow, depending on how big the current repository is).
Therefore, it is disabled by default.
)
kindex(check-for-staged-changes)
item(tt(check-for-staged-changes))(
This style is like tt(check-for-changes), but it never checks the worktree
files, only the metadata in the tt(.${vcs}) dir. Therefore,
this style initializes only the tt(%c) escape (with tt(stagedstr)) but
not the tt(%u) escape. This style is faster than tt(check-for-changes).
In the tt(git) backend, this style checks for changes in the index.
Other backends do not currently implement this style.
This style is disabled by default.
)
kindex(stagedstr)
item(tt(stagedstr))(
This string will be used in the tt(%c) escape if there are staged changes in
@ -941,6 +953,7 @@ sitem(tt(enable))(ALL)
sitem(tt(disable))((empty list))
sitem(tt(disable-patterns))((empty list))
sitem(tt(check-for-changes))(false)
sitem(tt(check-for-staged-changes))(false)
sitem(tt(stagedstr))((string: "S"))
sitem(tt(unstagedstr))((string: "U"))
sitem(tt(command))((empty string))

View File

@ -5,6 +5,7 @@
setopt localoptions extendedglob NO_shwordsplit
local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1
local stgitpatch stgitunapplied
local -i querystaged queryunstaged
local -A hook_com
VCS_INFO_git_getaction () {
@ -120,14 +121,24 @@ if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then
return 1
fi
if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" && \
if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" ; then
querystaged=1
queryunstaged=1
elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-staged-changes" ; then
querystaged=1
fi
if (( querystaged || queryunstaged )) && \
[[ "$(${vcs_comm[cmd]} rev-parse --is-inside-git-dir 2> /dev/null)" != 'true' ]] && \
${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then
# Default: off - these are potentially expensive on big repositories
${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code ||
gitunstaged=1
${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null
(( $? && $? != 128 )) && gitstaged=1
if (( queryunstaged )) ; then
${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code ||
gitunstaged=1
fi
if (( querystaged )) ; then
${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null
(( $? && $? != 128 )) && gitstaged=1
fi
fi
VCS_INFO_adjust

View File

@ -266,6 +266,10 @@ autoload -Uz vcs_info
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' get-revision true
# Alternatively, the following would set only %c, but is faster:
#zstyle ':vcs_info:*' check-for-changes false
#zstyle ':vcs_info:*' check-for-staged-changes true
# Default to running vcs_info. If possible we prevent running it later for
# speed reasons. If set to a non empty value vcs_info is run.