Ronze
Ronze

Reputation: 1574

Grit commit seems to be overriding last commit in Git repo?

I'm using Grit to create a repo and committing as few times. Every time I commit, my commit is saved, but the old one disappears. Anyone have any clue what I'm doing wrong?

First I create a repo and make a commit. If I log the commit, I get the commit ID, and everything works

repo_name = 'repos/myrepo.git'
repo = Repo.init_bare(repo_name)
index = Index.new(repo)
index.add('mytext.txt', "This is my first text")
index.commit('Text commit')

Then I do another commit

index = repo.index
index.read_tree('master')
index.add('mytext.txt', "This is my second text")
index.commit('Text commit')

.. and when I do a git log, only the last commit shows up. This following line returns 1

repo.commits.count

Any idea what I'm doing wrong? I can't really find any tutorials on how to use the write methods in Grit. So any links would also be appreciated. Thanks!

Upvotes: 1

Views: 605

Answers (1)

Ronze
Ronze

Reputation: 1574

Dough. Answer was simple. Commit number 2 needs to have commit number 1 as parent. Then it forms a history of these commits, and it works:

index.commit('Text commit', [repo.commits.first])

I'm still looking for tutorials or guides explaining the write methods in the Grit library. The rubyforge documentation doesn't explain much.

Upvotes: 2

Related Questions