zsh-workers
 help / color / mirror / code / Atom feed
From: Michel Lespinasse <walken@google.com>
To: Frank Terbeck <ft@bewatermyfriend.org>
Cc: zsh-workers@zsh.org
Subject: Re: small nit about zsh vcs_info module
Date: Sun, 18 Jul 2010 15:43:26 -0700	[thread overview]
Message-ID: <20100718224326.GA13145@google.com> (raw)
In-Reply-To: <87oce4v7t0.fsf@ft.bewatermyfriend.org>

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.


  reply	other threads:[~2010-07-18 22:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20100718121846.GA15276@google.com>
2010-07-18 20:44 ` Frank Terbeck
2010-07-18 22:43   ` Michel Lespinasse [this message]
2010-07-19 18:53     ` Frank Terbeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100718224326.GA13145@google.com \
    --to=walken@google.com \
    --cc=ft@bewatermyfriend.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).