71201ffd67da9bb8a60d998ebce4dfe7e1039c98

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

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

Diff

 1diff --git a/lib/git.zsh b/lib/git.zsh
 2index 648a766b5b7614bb2f09db00413a5af1fc858e38..b9069ff12c9c04701b82ac2cf5ff1b631178a680 100644
 3--- a/lib/git.zsh
 4+++ b/lib/git.zsh
 5@@ -76,16 +76,21 @@ function git_current_branch() {
 6 
 7 # Gets the number of commits ahead from remote
 8 function git_commits_ahead() {
 9-  if $(command git rev-parse --git-dir > /dev/null 2>&1); then
10-    local COMMITS="$(git rev-list --count @{upstream}..HEAD)"
11-    echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
12+  if command git rev-parse --git-dir &>/dev/null; then
13+    local commits="$(git rev-list --count @{upstream}..HEAD)"
14+    if [[ "$commits" != 0 ]]; then
15+      echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
16+    fi
17   fi
18 }
19 
20 # Gets the number of commits behind remote
21 function git_commits_behind() {
22-  if $(command git rev-parse --git-dir > /dev/null 2>&1); then
23-    echo $(git rev-list --count HEAD..@{upstream})
24+  if command git rev-parse --git-dir &>/dev/null; then
25+    local commits="$(git rev-list --count HEAD..@{upstream})"
26+    if [[ "$commits" != 0 ]]; then
27+      echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX"
28+    fi
29   fi
30 }
31