Thread (4 messages) flat view 4 messages, 3 authors, 2016-06-15

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

From: Eric Gerlach <hidden>
Date: 2016-06-15 22:45:19

Possibly related (same subject, not in this thread)

Jeff King wrote:
On Sun, Sep 07, 2008 at 10:31:52AM -0700, Junio C Hamano wrote:
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help