summaryrefslogtreecommitdiff
path: root/lib/git.zsh
diff options
context:
space:
mode:
authorJacopo De Simoi <wilderjds@users.noreply.github.com>2018-04-15 12:44:48 -0400
committerMarc Cornellà <marc.cornella@live.com>2018-04-15 18:44:48 +0200
commitccd02866f67e704cd4844029c0f5787c0714e21c (patch)
tree9e6969fd26a5ceff772a3e38e271792e6a030148 /lib/git.zsh
parent2fce6a0faf4e9c2c44521cd51ff8c88f11346e02 (diff)
downloadzsh-ccd02866f67e704cd4844029c0f5787c0714e21c.tar.gz
zsh-ccd02866f67e704cd4844029c0f5787c0714e21c.tar.bz2
zsh-ccd02866f67e704cd4844029c0f5787c0714e21c.zip
Fix git_commits_{ahead,before} when no upstream branch is defined (#6658)
If @{u} is not defined, git rev-list will give an error; redirect to stderr the error and deal with this case in what follows.
Diffstat (limited to 'lib/git.zsh')
-rw-r--r--lib/git.zsh8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/git.zsh b/lib/git.zsh
index 9b0f6e36f..b55b762d7 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -77,8 +77,8 @@ 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; then
- local commits="$(git rev-list --count @{upstream}..HEAD)"
- if [[ "$commits" != 0 ]]; then
+ local commits="$(git rev-list --count @{upstream}..HEAD 2>/dev/null)"
+ if [[ -n "$commits" && "$commits" != 0 ]]; then
echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
fi
fi
@@ -87,8 +87,8 @@ function git_commits_ahead() {
# Gets the number of commits behind remote
function git_commits_behind() {
if command git rev-parse --git-dir &>/dev/null; then
- local commits="$(git rev-list --count HEAD..@{upstream})"
- if [[ "$commits" != 0 ]]; then
+ local commits="$(git rev-list --count HEAD..@{upstream} 2>/dev/null)"
+ if [[ -n "$commits" && "$commits" != 0 ]]; then
echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX"
fi
fi