import os
import paramiko
from git.repo import Repo as rp
# clone代码
download_path = os.path.join('code', 'fe')
rp.clone_from('https://xxx.git', to_path=download_path, branch='master')
# pull 最新代码
repo = rp(download_path)
repo.git.pull()
# 获取所有分支
branchs = repo.remote().refs
for item in branchs:
print(item.remote_head)
# 获取所有版本
for tag in repo.tags:
print(tag)
# 获取所有commit
commit_log = repo.git.log('--pretty={"commit":"%h","author":"%an","summary":"%s","date":"%cd"}', max_count=50,
date="format:%Y-%m-%d %H:%M:%S")
log_list = commit_log.split('\n')
real_log_list = [eval(item) for item in log_list]