Skip to content

Instantly share code, notes, and snippets.

@aaroncox
Created May 9, 2013 15:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaroncox/5548105 to your computer and use it in GitHub Desktop.
Save aaroncox/5548105 to your computer and use it in GitHub Desktop.
Cloning a Repo from Github using Dulwich/Python
#!/usr/bin/env python
import dulwich.client
from dulwich.repo import Repo
from dulwich import index
import os
import shutil
client, path = dulwich.client.get_transport_and_path("https://github.com/aaroncox/d3.git")
src = "https://github.com/aaroncox/d3.git"
target = "local"
shutil.rmtree(target)
os.mkdir(target)
r = Repo.init(target)
remote_refs = client.fetch(src, r)
r["HEAD"] = remote_refs["HEAD"]
index.build_index_from_tree(r.path, r.index_path(), r.object_store, r['head'].tree)
@QGB
Copy link

QGB commented Jan 28, 2020

import dulwich.client
from dulwich.repo import Repo
from dulwich import index

import os
import shutil

client, path = dulwich.client.get_transport_and_path("https://github.com/aaroncox/d3.git")

src = "https://github.com/qgb/qpsu"
target = "qgb"
try:
    shutil.rmtree(target)
    os.mkdir(target)
except Exception as e:print(e)
r = Repo.init(target)

remote_refs = client.fetch(src, r)
r[b"HEAD"] = remote_refs[b"HEAD"]

index.build_index_from_tree(r.path, r.index_path(), r.object_store, r[b'HEAD'].tree)

@QGB
Copy link

QGB commented Jan 28, 2020

index.build_index_from_tree('C:\qgb\test','C:\qgb\test\.git\index',<DiskObjectStore('C:\qgb\test\.git\objects')>,b'8b65f1fe548bc15681ad6109b7824cb1c2c0444e',)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment