Created
December 21, 2016 03:50
-
-
Save mixja/7dd908292e69b08f4c8fcad96d6fb041 to your computer and use it in GitHub Desktop.
Clone a revision of a Git Repo and create a ZIP file
This file contains 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
from dulwich.client import get_transport_and_path | |
from dulwich.repo import Repo | |
import shutil | |
git_url = "https://github.com/dpaws/microtrader.git" | |
git_revision = "54dcd9f5b557af87ec1132f62b9c6bbdfc01a2f5" | |
local = Repo.init(b"local", mkdir=True) | |
client, path = get_transport_and_path(git_url) | |
remote_refs = client.fetch(path, local, determine_wants=local.object_store.determine_wants_all) | |
remote_refs[b"refs/heads/master"] = remote_refs[b"HEAD"] = git_revision | |
local.refs.import_refs(b'refs/remotes/origin',{n[len(b'refs/heads/'):]: v for (n, v) in remote_refs.items() if n.startswith(b'refs/heads/')}) | |
local.refs.import_refs(b'refs/tags',{n[len(b'refs/tags/'):]: v for (n, v) in remote_refs.items() if n.startswith(b'refs/tags/')}) | |
local[b"HEAD"] = remote_refs[b"HEAD"] | |
local.reset_index() | |
shutil.make_archive('local','zip','local') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment