zsh-workers
 help / color / mirror / code / Atom feed
* Re: small nit about zsh vcs_info module
       [not found] <20100718121846.GA15276@google.com>
@ 2010-07-18 20:44 ` Frank Terbeck
  2010-07-18 22:43   ` Michel Lespinasse
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Terbeck @ 2010-07-18 20:44 UTC (permalink / raw)
  To: Michel Lespinasse; +Cc: zsh-workers

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

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: small nit about zsh vcs_info module
  2010-07-18 20:44 ` small nit about zsh vcs_info module Frank Terbeck
@ 2010-07-18 22:43   ` Michel Lespinasse
  2010-07-19 18:53     ` Frank Terbeck
  0 siblings, 1 reply; 3+ messages in thread
From: Michel Lespinasse @ 2010-07-18 22:43 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: zsh-workers

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: small nit about zsh vcs_info module
  2010-07-18 22:43   ` Michel Lespinasse
@ 2010-07-19 18:53     ` Frank Terbeck
  0 siblings, 0 replies; 3+ messages in thread
From: Frank Terbeck @ 2010-07-19 18:53 UTC (permalink / raw)
  To: Michel Lespinasse; +Cc: zsh-workers

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

I'll commit the following then. Thanks!

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 778d061..9765a6e 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -121,8 +121,8 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" && \
     # Default: off - these are potentially expensive on big repositories
     ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code ||
         gitunstaged=1
-    ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD ||
-        gitstaged=1
+    ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null
+    (( $? && $? != 128 )) && gitstaged=1
 fi
 
 VCS_INFO_adjust


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-19 19:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20100718121846.GA15276@google.com>
2010-07-18 20:44 ` small nit about zsh vcs_info module Frank Terbeck
2010-07-18 22:43   ` Michel Lespinasse
2010-07-19 18:53     ` Frank Terbeck

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