python - dulwich's NotCommitError when trying to resolve tags -


i'm working dulwich on project need clone repositories commit id, tag, branch name. i'm having trouble tag case seems work repositories, not others.

here's "clone" helper function wrote:

from dulwich import index dulwich.client import get_transport_and_path dulwich.repo import repo   def clone(repo_url, ref, folder):     is_commit = false     if not ref.startswith('refs/'):         is_commit = true     rep = repo.init(folder)     client, relative_path = get_transport_and_path(repo_url)      remote_refs = client.fetch(relative_path, rep)     k, v in remote_refs.iteritems():         try:             rep.refs.add_if_new(k, v)         except:             pass      if ref.startswith('refs/tags'):         ref = rep.ref(ref)         is_commit = true      if is_commit:         rep['head'] = rep.commit(ref)     else:         rep['head'] = remote_refs[ref]     indexfile = rep.index_path()     tree = rep["head"].tree     index.build_index_from_tree(rep.path, indexfile, rep.object_store, tree)     return rep, folder 

oddly, able do

 clone('git://github.com/dotcloud/docker-py', 'refs/tags/0.2.0', '/tmp/a') 

but

clone('git://github.com/dotcloud/docker-registry', 'refs/tags/0.6.0', '/tmp/b') 

fails with

notcommiterror: object debd567e95df51f8ac91d0bb69ca35037d957ee6 type commit [...]  not commit 

both refs tags, i'm not sure i'm doing wrong, or why code behaves differently on both repositories. appreciate sort out!

refs/tags/0.6.0 annotated tag. means ref points tag object (which has reference commit object), rather directly commit object.

in line:

if is_commit:      rep['head'] = rep.commit(ref)  else:      rep['head'] = remote_refs[ref] 

you want like:

if isinstance(rep[ref], tag):      rep['head'] = rep[ref].object[1] else:      rep['head'] = rep[ref] 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -