Skip to content

Commit

Permalink
git: output nothing when no commits ahead or behind
Browse files Browse the repository at this point in the history
This fixes old git_commits_ahead behavior and changes git_commits_behind
to have the same behavior.

Fixes ohmyzsh#5355
  • Loading branch information
mcornella committed Sep 5, 2016
1 parent 298b635 commit 71201ff
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/git.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 71201ff

Please sign in to comment.