From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Eric Gerlach <egerlach@feds.uwaterloo.ca>, git@vger.kernel.org
Subject: Re: Is "show-ref -h" a good test for an empty repository?
Date: Sun, 07 Sep 2008 10:31:52 -0700 [thread overview]
Message-ID: <7vprnfn9pz.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20080907155033.GA25031@coredump.intra.peff.net> (Jeff King's message of "Sun, 7 Sep 2008 11:50:33 -0400")
Jeff King <peff@peff.net> writes:
> 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.
next prev parent reply other threads:[~2008-09-07 17:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-06 0:45 Is "show-ref -h" a good test for an empty repository? Eric Gerlach
2008-09-06 1:29 ` Jeff King
2008-09-07 14:21 ` Eric Gerlach
2008-09-07 15:50 ` Jeff King
2008-09-07 17:31 ` Junio C Hamano [this message]
2008-09-07 17:34 ` Jeff King
2008-09-08 13:24 ` Eric Gerlach
2008-09-08 14:42 ` Jeff King
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=7vprnfn9pz.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=egerlach@feds.uwaterloo.ca \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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.
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).