Created
January 30, 2020 08:38
-
-
Save QGB/31f3b7f8cf425fba7d5d220a36fbbaae to your computer and use it in GitHub Desktop.
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
import sys;'qgb.U' in sys.modules or sys.path.append('C:/qgb/');from qgb import * | |
import dulwich | |
import dulwich.client | |
from dulwich.repo import Repo | |
from dulwich import index | |
import os | |
import shutil | |
def clone(url,path=None): | |
client, target = dulwich.client.get_transport_and_path(url) #c , 'user/repo' | |
if not path: | |
if target.endswith('.git'): | |
target=target[:-4] | |
path=target | |
path=F.mkdir(path) | |
ls=F.ls(path) | |
if len(ls)>1: #skip .git | |
return py.No('Not empty dir:'+path,ls) | |
if len(ls)==1: | |
r = Repo(path) | |
else: | |
r = Repo.init(path) | |
print(U.stime(),'fetching url...') | |
remote_refs = client.fetch(url, r) | |
r[b"HEAD"] = remote_refs[b"HEAD"] | |
print(U.stime(),'build_index_from_tree ...') | |
index.build_index_from_tree(r.path, r.index_path(), r.object_store, r[b'HEAD'].tree) | |
r.close() | |
return path,r | |
def up(url,path=None,commit_msg=None,name='QGB',email='[email protected]'): | |
if not path: | |
client, target = dulwich.client.get_transport_and_path(url) | |
if target.endswith('.git'): | |
target=target[:-4] | |
path=target | |
path=F.auto_path(path) | |
ls=F.ls(path) | |
if len(ls) < 1: | |
return py.No('Not contains .git dir:'+path,ls) | |
repo=dulwich.repo.Repo(path) | |
repo.stage(['a']) | |
if not commit_msg: | |
commit_msg='dulwich_'+U.stime() | |
if not py.isbytes(commit_msg): | |
commit_msg=commit_msg.encode('utf-8') | |
# cid=repo.do_commit(message=b"dulwic") | |
author = "{0} <{1}>".format(name, email) | |
author=author.encode('utf-8') | |
bhash=repo.do_commit(message=commit_msg | |
, author=author | |
, committer=author | |
, merge_heads=None | |
) | |
return bhash,dulwich.porcelain.push(repo.path, url , 'master',) | |
# porcelain.push(repo.repo.path, result.url, branch_name, errstream=outstream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment