prezto: git-info ahead/behind check broken

I’m setting up a new Mac, so everything is up-to-date - latest OS X Mavericks, latest clone of prezto, etc. Git version is 1.8.3.4.

Symptom: After every shell command, the following is output:

git-info:165: bad math expression: operator expected at `0'
git-info:173: bad math expression: operator expected at `0'

I did some digging in that file (modules/git/functions/git-info). From line 250 (not either of the lines from the error, interestingly), we have:

ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}'
ahead_and_behind="$(${(z)ahead_and_behind_cmd} 2> /dev/null)"

if [[ -n "$ahead_format" ]]; then
  ahead="$ahead_and_behind[(w)1]"
  if (( ahead > 0 )); then

$ahead is set to (num)(some sort of whitespace)(num), which means the [(w)1] has failed to split the string, which then causes the comparison to zero to throw an error.

My shell-fu is not strong, so I don’t know how to correctly split $ahead_or_behind.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

@Po-Hsuan-Huang Check to see if other software (in my case it was a Python virtualenv postactivate script) sets the IFS environment variable and doesn’t unset it.

The culprit turned out to be a virtualenv postactivate script which modified IFS and didn’t unset it when finished.