Skip to content

Instantly share code, notes, and snippets.

@cscorley
Created July 24, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cscorley/72479aaba0edcd59dcb924036d6f753e to your computer and use it in GitHub Desktop.
Save cscorley/72479aaba0edcd59dcb924036d6f753e to your computer and use it in GitHub Desktop.
def clone(source, target, bare=False, fresh=False):
if os.path.exists(target) and fresh:
shutil.rmtree(target)
# so dulwich doesn't shit the bed when given a github url
if not source.endswith('.git'):
source = source + '.git'
if not os.path.exists(target):
mkdir(target)
repo = dulwich.porcelain.clone(source, target, bare)
# ugh
remote_client, remote_path = dulwich.client.get_transport_and_path(source)
remote_refs = remote_client.fetch(remote_path, repo)
for key,value in remote_refs.items():
if key.endswith('^{}'): # wtf github?
key = key[:3]
try:
repo.refs[key] = value
except:
pass
return repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment