Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: small nit about zsh vcs_info module

[..moved to -workers..]

Michel Lespinasse wrote:
> I wanted to report a small nit I have about it. Right after creating a
> new git repository with 'git init', vcs_info reports that there are staged
> files in it. This is because .git/HEAD points to refs/heads/master,
> which does not exist anymore, so git diff-index return code is 128.
> +    ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2>/dev/null
> +    [[ $? -eq 1 ]] && gitstaged=1
> Hope this helps. Thanks for writing the vcs_info module !

I just had a look at the source code of git's `diff-index' command. I'm
wondering: You are redirecting stderr, too. What error message did you

Other than that there, seem to be legitimate return values besides `1'
and `0' with diff-index. I'm not sure if anything other than those two
apply for what we're using diff-index for, but I'd like to be safe.

How about this?
${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2>/dev/null
(( $? && $? <= 127 )) && gitstaged=1

or maybe even (( $? && $? != 128 ))

Regards, Frank

Messages sorted by: Reverse Date, Date, Thread, Author