git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 7, 2008, 17:31 UTC
Message-ID
<7vprnfn9pz.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080907155033.GA25031@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 25 quoted lines
> 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.

All depends on how "an empty repository" is defined. My definition of an empty repository would have been:

 - No objects in it;
 - No index;
 - No refs except symrefs.
Previous: Jeff KingNext: Jeff King
Message 5 of 8 in “Is "show-ref -h" a good test for an empty repository?”
  1. Eric GerlachSep 6, 2008
  2. Jeff KingSep 6, 2008
  3. Eric GerlachSep 7, 2008
  4. Jeff KingSep 7, 2008
  5. Junio C HamanoSep 7, 2008
  6. Jeff KingSep 7, 2008
  7. Eric GerlachSep 8, 2008
  8. Jeff KingSep 8, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.