Commit ccd02866 authored by Jacopo De Simoi's avatar Jacopo De Simoi Committed by Marc Cornellà
Browse files

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.
parent 2fce6a0f
...@@ -77,8 +77,8 @@ function git_current_branch() { ...@@ -77,8 +77,8 @@ 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; 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 2>/dev/null)"
if [[ "$commits" != 0 ]]; then if [[ -n "$commits" && "$commits" != 0 ]]; then
echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
fi fi
fi fi
...@@ -87,8 +87,8 @@ function git_commits_ahead() { ...@@ -87,8 +87,8 @@ function git_commits_ahead() {
# 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; then if command git rev-parse --git-dir &>/dev/null; then
local commits="$(git rev-list --count HEAD..@{upstream})" local commits="$(git rev-list --count HEAD..@{upstream} 2>/dev/null)"
if [[ "$commits" != 0 ]]; then if [[ -n "$commits" && "$commits" != 0 ]]; then
echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX" echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX"
fi 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