Skip to content

Instantly share code, notes, and snippets.

@QGB
Created January 30, 2020 08:38
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 QGB/31f3b7f8cf425fba7d5d220a36fbbaae to your computer and use it in GitHub Desktop.
Save QGB/31f3b7f8cf425fba7d5d220a36fbbaae to your computer and use it in GitHub Desktop.
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='qgbcs1@gmail.com'):
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