gitpython-developers/GitPython — Issue #34: Object cache inconsistent after fetch
Author: eswierk
Created: 2011-10-21 14:49:44+00:00
State: open

If I create a new remote, call remote.fetch() and then try to obtain one of the newly-fetched commits by its sha, I get a BadObject exception deep inside gitdb:

Traceback (most recent call last):
File "/home/foobar/ggit/ggit/repo.py", line 134, in foreach
results[i] = fn(items[i], m, *args, **kargs)
File "/home/foobar/ggit/gg", line 185, in mergepull
sb = repo.commit(headRev)
File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/repo/base.py", line 378, in commit
return self.rev_parse(str(rev)+"^0")
File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/repo/fun.py", line 151, in rev_parse
obj = name_to_object(repo, rev[:start])
File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/repo/fun.py", line 89, in name_to_object
return Object.new_from_sha(repo, hex_to_bin(hexsha))
File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/objects/base.py", line 64, in new_from_sha
oinfo = repo.odb.info(sha1)
File "/usr/local/lib/python2.7/dist-packages/gitdb-0.5.4-py2.7-linux-x86_64.egg/gitdb/db/base.py", line 256, in info
return self._db_query(sha).info(sha)
File "/usr/local/lib/python2.7/dist-packages/gitdb-0.5.4-py2.7-linux-x86_64.egg/gitdb/db/base.py", line 243, in _db_query
raise BadObject(sha)
BadObject: BadObject: 4634b83087e4744ee980a17a63952412374b1b95

I can work around the problem by calling repo.odb.update_cache() after the fetch but before looking up the commit.

It would be nice if Remote.fetch() did this automatically to ensure cache consistency.