Commit 71201ffd authored by Marc Cornellà's avatar Marc Cornellà
Browse files

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
parent 298b6351
...@@ -76,16 +76,21 @@ function git_current_branch() { ...@@ -76,16 +76,21 @@ function git_current_branch() {
# Gets the number of commits ahead from remote # Gets the number of commits ahead from remote
function git_commits_ahead() { function git_commits_ahead() {
if $(command git rev-parse --git-dir > /dev/null 2>&1); then if command git rev-parse --git-dir &>/dev/null; then
local COMMITS="$(git rev-list --count @{upstream}..HEAD)" local commits="$(git rev-list --count @{upstream}..HEAD)"
echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" if [[ "$commits" != 0 ]]; then
echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
fi
fi fi
} }
# Gets the number of commits behind remote # Gets the number of commits behind remote
function git_commits_behind() { function git_commits_behind() {
if $(command git rev-parse --git-dir > /dev/null 2>&1); then if command git rev-parse --git-dir &>/dev/null; then
echo $(git rev-list --count HEAD..@{upstream}) 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 fi
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment