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

Re: small nit about zsh vcs_info module



On Sun, Jul 18, 2010 at 10:44:43PM +0200, Frank Terbeck wrote:
> [..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
> get?

I was getting:
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

To reproduce, just run 'git init' in an empty directory then run
'git diff-index HEAD' or any variant of it.

> 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.

I did not realize that - the doc for git diff-index --exit-code did not
mention it. However, it's still better being safe than sorry :)

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

(( $? && $? != 128 )) looks good & works fine for me.

-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.



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