Skip to contentSkip to conversation

BUG: git prompt breaks with zsh < 5.0.6

DISCUSSION Shupak, Vitaly 2 participants 3 messages Jan 9, 2023 – Jan 10, 2023

lore
Share & tools
lore
#0 lore raw

A change to git-prompt.sh in v2.38 to show presence of unresolved conflicts contains syntax which is not valid under zsh < 5.0.6. This version of zsh is old, but is still the default on RedHat 7 machines, for example.

The offending block is:

       local conflict="" # state indicator for unresolved conflicts
       if [[ "${GIT_PS1_SHOWCONFLICTSTATE}" == "yes" ]] &&
          [[ $(git ls-files --unmerged 2>/dev/null) ]]; then
               conflict="|CONFLICT"
       fi

[[ $(command) ]] syntax doesn't work in older version of zsh and should use [[ -n "$(command)" ]] instead.

Thanks,
Vitaly

#1 lore raw
Quoted 11 lines · Vitaly

A change to git-prompt.sh in v2.38 to show presence of unresolved conflicts contains syntax which is not valid under zsh < 5.0.6. This version of zsh is old, but is still the default on RedHat 7 machines, for example.

The offending block is:

       local conflict="" # state indicator for unresolved conflicts
       if [[ "${GIT_PS1_SHOWCONFLICTSTATE}" == "yes" ]] &&
          [[ $(git ls-files --unmerged 2>/dev/null) ]]; then
               conflict="|CONFLICT"
       fi

[[ $(command) ]] syntax doesn't work in older version of zsh and should use [[ -n "$(command)" ]] instead.

Does [ "$(command)" ] work? I would assume so, because that's in POSIX. If so, that might also be a valid approach since it doesn't look like we need the special behaviour of the double-bracket operator.

Signature · 2 lines
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
#2 lore raw

Yes, that works too

-----Original Message-----
From: brian m. carlson <[email protected]>
Sent: Monday, January 9, 2023 6:37 PM
To: Shupak, Vitaly <[email protected]>
Cc: [email protected]
Subject: Re: BUG: git prompt breaks with zsh < 5.0.6

Quoted 11 lines · Vitaly

A change to git-prompt.sh in v2.38 to show presence of unresolved conflicts contains syntax which is not valid under zsh < 5.0.6. This version of zsh is old, but is still the default on RedHat 7 machines, for example.

The offending block is:

       local conflict="" # state indicator for unresolved conflicts
       if [[ "${GIT_PS1_SHOWCONFLICTSTATE}" == "yes" ]] &&
          [[ $(git ls-files --unmerged 2>/dev/null) ]]; then
               conflict="|CONFLICT"
       fi

[[ $(command) ]] syntax doesn't work in older version of zsh and should use [[ -n "$(command)" ]] instead.

Does [ "$(command)" ] work? I would assume so, because that's in POSIX.
If so, that might also be a valid approach since it doesn't look like we need the special behaviour of the double-bracket operator. --
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA