Re: Is "show-ref -h" a good test for an empty repository?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 07, 2008 at 10:21:16AM -0400, Eric Gerlach wrote:

>>> I'm trying to test to see if "git diff --cached" will fail because 
>>> there  are no existing commits.  I've come up with running "git 
>>> show-ref -h -q"  and testing its return value.  My hypothesis is: If 
>>
>> Maybe "git rev-parse --verify HEAD"?
>
> That seems like it would work too... any reason one would be better than  
> the other?

My thinking was:

  1. It's a plumbing command, and so less likely to change its behavior
     versus "git diff".

  2. The seems more obvious to me. rev-parse --verify is meant to ask
     "is this a valid object name?"

It is slightly different from your show-ref. Yours asks "is there
anything in refs/heads in this repository?" Mine asks "does the current
HEAD exist?" In practice, they are both reasonable tests, since once you
have a branch, it is very difficult to get HEAD to point to something
invalid short of editing manually to some bogus value. But you might
prefer one over the other depending on what you are trying to say.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux