Add diverged context to git-info
that, when defined, will be set if branch is both ahead and behind of remote. If not defined, the `ahead` and `behind` contexts will still be set, as how they worked previously.
This commit is contained in:
parent
f97e43a39f
commit
53aef5a05c
2 changed files with 32 additions and 18 deletions
|
@ -48,16 +48,22 @@ a style is:
|
||||||
| action | %s | Special action name (see Special Action Contexts below)
|
| action | %s | Special action name (see Special Action Contexts below)
|
||||||
| ahead | %A | Commits ahead of remote count
|
| ahead | %A | Commits ahead of remote count
|
||||||
| behind | %B | Commits behind of remote count
|
| behind | %B | Commits behind of remote count
|
||||||
|
| diverged | %V | Diverged commits (both ahead and behind are yield when it's not defined)
|
||||||
| branch | %b | Branch name
|
| branch | %b | Branch name
|
||||||
| commit | %c | Commit short hash (when in 'detached HEAD' state)
|
| commit | %c | Commit short hash (when in 'detached HEAD' state)
|
||||||
| clean | %C | Clean state
|
| clean | %C | Clean state
|
||||||
| dirty | %D | Dirty state (count with untracked files if verbose enabled)
|
| dirty | %D | Dirty state (count with untracked files when verbose mode enabled)
|
||||||
| indexed | %i | Indexed files (count if verbose enabled)
|
| indexed | %i | Indexed files (count when verbose mode enabled)
|
||||||
| unindexed | %I | Unindexed files (count if verbose enabled)
|
| unindexed | %I | Unindexed files (count when verbose mode enabled)
|
||||||
| position | %p | Commits from nearest tag count (when in 'detached HEAD' state)
|
| position | %p | Commits from nearest tag count (when in 'detached HEAD' state)
|
||||||
| remote | %R | Remote name
|
| remote | %R | Remote name
|
||||||
| stashed | %S | Stashed states count
|
| stashed | %S | Stashed states count
|
||||||
| untracked | %u | Untracked files count (only if verbose enabled)
|
| untracked | %u | Untracked files count (only when verbose mode enabled)
|
||||||
|
|
||||||
|
While `commit` and `position` are only available when in ['detached HEAD'
|
||||||
|
state](http://gitfaq.org/articles/what-is-a-detached-head.html), on the other
|
||||||
|
hand, `ahead`, `behind`, `diverged`, `branch` and `remote` are only available
|
||||||
|
when an actual branch is checked out (so when **not** in 'detached HEAD' state).
|
||||||
|
|
||||||
### Special Action Contexts
|
### Special Action Contexts
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
# Gets the Git special action (am, bisect, cherry, merge, rebase).
|
# Gets the Git special action (am, bisect, cherry, merge, rebase).
|
||||||
# Borrowed from vcs_info and edited.
|
# Borrowed from vcs_info and edited.
|
||||||
function _git-action {
|
_git-action() {
|
||||||
local git_dir=$(git-dir)
|
local git_dir=$(git-dir)
|
||||||
local action_dir
|
local action_dir
|
||||||
for action_dir in \
|
for action_dir in \
|
||||||
|
@ -87,7 +87,7 @@ function _git-action {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Gets the Git status information.
|
# Gets the Git status information.
|
||||||
function git-info {
|
git-info() {
|
||||||
# Extended globbing is needed to parse repository status.
|
# Extended globbing is needed to parse repository status.
|
||||||
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||||||
|
|
||||||
|
@ -148,6 +148,7 @@ function git-info {
|
||||||
local behind_formatted
|
local behind_formatted
|
||||||
local branch_formatted
|
local branch_formatted
|
||||||
local commit_formatted
|
local commit_formatted
|
||||||
|
local diverged_formatted
|
||||||
local position_formatted
|
local position_formatted
|
||||||
local remote_formatted
|
local remote_formatted
|
||||||
if [[ -n ${branch} ]]; then
|
if [[ -n ${branch} ]]; then
|
||||||
|
@ -172,25 +173,31 @@ function git-info {
|
||||||
|
|
||||||
local ahead_format
|
local ahead_format
|
||||||
local behind_format
|
local behind_format
|
||||||
|
local diverged_format
|
||||||
zstyle -s ':zim:git-info:ahead' format 'ahead_format'
|
zstyle -s ':zim:git-info:ahead' format 'ahead_format'
|
||||||
zstyle -s ':zim:git-info:behind' format 'behind_format'
|
zstyle -s ':zim:git-info:behind' format 'behind_format'
|
||||||
if [[ -n ${ahead_format} || -n ${behind_format} ]]; then
|
zstyle -s ':zim:git-info:diverged' format 'diverged_format'
|
||||||
|
if [[ -n ${ahead_format} || -n ${behind_format} || -n ${diverged_format} ]]; then
|
||||||
# Gets the commit difference counts between local and remote.
|
# Gets the commit difference counts between local and remote.
|
||||||
local ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}'
|
local ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}'
|
||||||
|
|
||||||
# Get ahead and behind counts.
|
# Get ahead and behind counts.
|
||||||
local ahead_and_behind=$(${(z)ahead_and_behind_cmd} 2>/dev/null)
|
local ahead_and_behind=$(${(z)ahead_and_behind_cmd} 2>/dev/null)
|
||||||
|
|
||||||
# Format ahead.
|
|
||||||
if [[ -n ${ahead_format} ]]; then
|
|
||||||
local ahead=${ahead_and_behind[(w)1]}
|
local ahead=${ahead_and_behind[(w)1]}
|
||||||
(( ahead )) && zformat -f ahead_formatted ${ahead_format} "A:${ahead}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Format behind.
|
|
||||||
if [[ -n ${behind_format} ]]; then
|
|
||||||
local behind=${ahead_and_behind[(w)2]}
|
local behind=${ahead_and_behind[(w)2]}
|
||||||
(( behind )) && zformat -f behind_formatted ${behind_format} "B:${behind}"
|
|
||||||
|
if [[ -n ${diverged_format} && ${ahead} -gt 0 && ${behind} -gt 0 ]]; then
|
||||||
|
# Format diverged.
|
||||||
|
diverged_formatted=${diverged_format}
|
||||||
|
else
|
||||||
|
# Format ahead.
|
||||||
|
if [[ -n ${ahead_format} && ${ahead} -gt 0 ]]; then
|
||||||
|
zformat -f ahead_formatted ${ahead_format} "A:${ahead}"
|
||||||
|
fi
|
||||||
|
# Format behind.
|
||||||
|
if [[ -n ${behind_format} && ${behind} -gt 0 ]]; then
|
||||||
|
zformat -f behind_formatted ${behind_format} "B:${behind}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -328,7 +335,8 @@ function git-info {
|
||||||
"R:${remote_formatted}" \
|
"R:${remote_formatted}" \
|
||||||
"s:${action_formatted}" \
|
"s:${action_formatted}" \
|
||||||
"S:${stashed_formatted}" \
|
"S:${stashed_formatted}" \
|
||||||
"u:${untracked_formatted}"
|
"u:${untracked_formatted}" \
|
||||||
|
"V:${diverged_formatted}"
|
||||||
git_info[${info_format}]=${reply}
|
git_info[${info_format}]=${reply}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue