Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.head.commit is 'HEAD' in empty repo #16

Closed
candlerb opened this issue Mar 22, 2010 · 1 comment
Closed

r.head.commit is 'HEAD' in empty repo #16

candlerb opened this issue Mar 22, 2010 · 1 comment

Comments

@candlerb
Copy link

With a non-empty repo:

r.head.commit
=> "f36d24ea4d820a9c109e35b22c8a77fed2060dcb"

But with an empty repo (no commits yet):

r = Grit::Repo.new(".")
=> #<Grit::Repo "/home/candlerb/tmp/tst2.git">
r.head.commit
=> "HEAD"

The upshot is if you use the following code for a commit, you end up with a corrupted repo:

i = r.index
=> #<Grit::Index:0xb70ae288 @current_tree=nil, @repo=#<Grit::Repo "/home/candlerb/tmp/tst2.git">, @tree={}>
i.add("foo","aaa")
=> "aaa"
i.commit("Message", [r.head.commit])
=> "115431315faec0c3427d02dc8694f7de1a38bdc6"

$ git log
error: bad parents in commit 115431315faec0c3427d02dc8694f7de1a38bdc6
fatal: bad object HEAD

Workaround:

parents = [r.head.commit]
parents = nil if parents == ['HEAD']
i.commit("Message", parents)

Perhaps r.head.commit would be better as nil if it doesn't exist? And perhaps commit should validate the parent commit IDs given to it?

@bkeepers
Copy link
Collaborator

bkeepers commented Feb 3, 2014

Grit is no longer maintained. See #183 and check out libgit2/rugged.

@bkeepers bkeepers closed this as completed Feb 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants