Updated git_commits_ahead function (#5247)
* Function wasn't returning correct value
* Updated underlying git command
* Kept echo command from previous function for backwards compatibility
* Kept function consistent with git_commits_behind
Diff
1diff --git a/lib/git.zsh b/lib/git.zsh
2index c79cc0d8e38c2bd485b5c6e0f85ee0c9508598fd..648a766b5b7614bb2f09db00413a5af1fc858e38 100644
3--- a/lib/git.zsh
4+++ b/lib/git.zsh
5@@ -76,9 +76,8 @@ function git_current_branch() {
6 7 # Gets the number of commits ahead from remote
8 function git_commits_ahead() {
9- if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
10- local COMMITS
11- COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
12+ if $(command git rev-parse --git-dir > /dev/null 2>&1); then
13+ local COMMITS="$(git rev-list --count @{upstream}..HEAD)"
14 echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
15 fi
16 }