1

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!

Phrogz
  • 296,393
  • 112
  • 651
  • 745
Ronze
  • 1,544
  • 2
  • 18
  • 33

1 Answers1

2

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.

Ronze
  • 1,544
  • 2
  • 18
  • 33
  • 1
    You might have a look at Git's own manuals (http://www.kernel.org/pub/software/scm/git/docs/), especially the "plumbing" commands. Most of them are used more or less the same in Grit's API. The equivalent for e.g. `Grit::Index#commit` is `git-commit-tree` (http://www.kernel.org/pub/software/scm/git/docs/v1.7.4/git-commit-tree.html). – Koraktor Feb 08 '11 at 22:39