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
EGEric Gerlach <egerlach@feds.uwaterloo.ca>
Date
Sep 8, 2008, 13:24 UTC
Message-ID
<48C52797.3030500@feds.uwaterloo.ca>
In-Reply-To
<20080907173434.GA26182@coredump.intra.peff.net>
Jeff King wrote:
Show 14 quoted lines
> On Sun, Sep 07, 2008 at 10:31:52AM -0700, Junio C Hamano wrote:
> 
>> 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.
> 
> Agreed. In the original message, he used the phrase "no existing
> commits" which I latched onto (to mean "no existing commits on this
> branch"). But the subject does say "empty repository". :)
> 
> Eric, maybe you can tell us more about what you're trying to accomplish?

Sure, I'm writing a patch for the debcommit script for the Debian project. It's a script which parses the Debian changelog for a package, generates a commit message, and commits to an SCM system.

The case I'm looking to protect against is the following:

$ mkdir -p new-repo/debian $ cd new-repo $ git init $ vi debian/changelog (add a few lines) $ git add debian/changelog $ debcommit

(which runs $ git diff --cached debian/changelog)

If I can test before the git-diff, then I can run "diff debian/changelog /dev/null" instead of the git-diff and all is well.

I don't want to test failure of the git-diff itself, because I want debcommit to fail if there's something wrong *other* than a new repo. Also, I want to use a git command to do it, because I don't have any guarantees about how things are setup, other than "we're using git."

I'm okay with debcommit proceeding if the repo has a commit but is borked from manually editing the HEAD ref, but I'm not sure how the maintainers of the script feel about that. So if it's possible to differentiate between the two cases, bonus, but not necessary.

So that's where I'm sitting. Jeff and Junio, thanks for the help and discussion. This is great :-)

(BTW, I'm leaning to the rev-parse right now; looking at the source it seems to be more precise, i.e. has fewer ways to fail)

Cheers,
Eric
Previous: Jeff KingNext: Jeff King
Message 7 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.