summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2016-09-05 11:22:48 +0200
committerMarc Cornellà <marc.cornella@live.com>2016-09-05 11:22:48 +0200
commit71201ffd67da9bb8a60d998ebce4dfe7e1039c98 (patch)
treefb219d0564284cc18ef8ded1e7a8b17cbfa0d2b3
parent298b63513dbbc94f750433e79750d07d96c87d62 (diff)
downloadzsh-71201ffd67da9bb8a60d998ebce4dfe7e1039c98.tar.gz
zsh-71201ffd67da9bb8a60d998ebce4dfe7e1039c98.tar.bz2
zsh-71201ffd67da9bb8a60d998ebce4dfe7e1039c98.zip
git: output nothing when no commits ahead or behind
This fixes old git_commits_ahead behavior and changes git_commits_behind to have the same behavior. Fixes #5355
-rw-r--r--lib/git.zsh15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/git.zsh b/lib/git.zsh
index 648a766b5..b9069ff12 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -76,16 +76,21 @@ function git_current_branch() {
# Gets the number of commits ahead from remote
function git_commits_ahead() {
- if $(command git rev-parse --git-dir > /dev/null 2>&1); then
- local COMMITS="$(git rev-list --count @{upstream}..HEAD)"
- echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
+ if command git rev-parse --git-dir &>/dev/null; then
+ local commits="$(git rev-list --count @{upstream}..HEAD)"
+ if [[ "$commits" != 0 ]]; then
+ echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
+ fi
fi
}
# Gets the number of commits behind remote
function git_commits_behind() {
- if $(command git rev-parse --git-dir > /dev/null 2>&1); then
- echo $(git rev-list --count HEAD..@{upstream})
+ if command git rev-parse --git-dir &>/dev/null; then
+ local commits="$(git rev-list --count HEAD..@{upstream})"
+ if [[ "$commits" != 0 ]]; then
+ echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX"
+ fi
fi
}