python合并master到各开发分支
作者:互联网
- 背景
处于配置管理一职,在每次发布上线后,需要将master分支内容合并到各开发分支 - python模块
涉及到git和repo库
from git import Repo
from git import Git
conflict_branch = []
# 路径
repo = Repo("D:/gitlab-1/lis")
gitlab = Git("D:/gitlab-1/lis")
# print(repo.branches)
branches = gitlab.execute('git branch')
branches = branches.replace(' ', '')
branches = branches.replace('*', '').split('\n')
print(branches)
print(len(branches))
cnt = 0
for b in branches:
if b == 'master':
continue
gitlab.checkout(b)
cnt += 1
# 当前分支
print("================当前进行中的分支 (%d)===============" % cnt)
print(repo.active_branch)
# git pull
# repo.remote().pull() # git pull -v origin
gitlab.execute('git pull')
try:
gitlab.execute('git merge origin/master')
gitlab.execute('git push origin '+b)
# gitlab.execute('git push')
except Exception as e:
gitlab.execute('git merge --abort')
conflict_branch.append(b)
print("===============conflict================")
print(conflict_branch)
运行情况如下:
- 结语
当前只适用于目前的情况,出现冲突需要手动解决。
标签:execute,git,branches,python,gitlab,master,branch,print,分支 来源: https://blog.csdn.net/Yeva__/article/details/120448959