libgit2 / rugged

ruby bindings to libgit2
MIT License
2.25k stars 277 forks source link

Add support for walking through shallow clones #409

Open eugenk opened 10 years ago

eugenk commented 10 years ago

Rugged doesn't support walking through the commits of partially cloned repositories:

In the shell do:

cd /tmp/
git clone --depth 1 git@github.com:eugenk/importing_owl.git

And then in the ruby console do:

r = Rugged::Repository.new('/tmp/importing_owl')
walker = Rugged::Walker.new(r)
walker.push(r.head.target.oid)
walker.each { |c| puts c.inspect }

which results in

Rugged::OdbError: Object not found - failed to find pack entry (c84d1be7573e2367e175b8675fcc347aaf13a27b)

where c84d1b is the parent commit oid.

Rescuing from Rugged::OdbError won't help because the walker raises this error as soon as the iterator starts walking - not when trying to find the missing parent commit.

This happens regardless of the sorting method (walker.sorting(Rugged::SORT_REVERSE) or walker.sorting(Rugged::SORT_TOPO))

If the oldest existing commit is a merge commit, then the error is not being raised. However, absolutely nothing happens, i.e. no commits are being iterated over.

The expected behaviour is at least to run through the commits which actually exist and then raise an error.

arthurschreiber commented 10 years ago

I don't think this is an issue in Rugged itself, but missing functionality in libgit2.

@carlosmn can you confirm whether libgit2 supports shallow clones or not?

carlosmn commented 10 years ago

libgit2 has not support for shallow histories.

eugenk commented 10 years ago

The git client silently ignores the "error" of references to missing parent commits. Could rugged/libgit2 do the same?

I tried to catch the Rugged::OdbError myself in the code, but then none of the (present) commits are being processed because the error is raised when the iteration begins instead of when the iteration reaches an inexistent commit.