Created
July 24, 2016 15:47
-
-
Save cscorley/72479aaba0edcd59dcb924036d6f753e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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