每个多需求并行开发的早晨执行一下,快乐生活每一天

书接上回,用一个rebase脚本就可以完成自己的一个特性分支同主分支的rebase了,但是使用过程中,多个需求特性同时开发时,切换来切换去执行脚本也有些麻烦。遂又写了一个多分支自动同步的脚本,与各位同学分享一下。

很简单,在之前rebase.sh脚本的基础上又套了一层多分支循环调用,并且比对了一下每次执行命令后的分支名符合预期,如果不一致则暂停同步脚本,保证rebase的冲突能够暴露给使用之。。

# 本脚本用于批量rebase分支,具体用法如下:
# 1. 将待rebase分支名填入'feature_branch_list.txt'中
# 2. 执行命令:python3 auto_rebase.py
# 3. 如果发生冲突,本脚本会自动停止,请解决冲突后再执行脚本

import os
import subprocess

FILE_PATH = 'feature_branch_list.txt'

branches = []
# 获取全部待rebase分支
with open(f'{FILE_PATH}', 'r') as file:
    print("将对下列分支进行rebase:")
    for line in file:
        print(line.strip())
        branches.append(line.strip())

os.system('git fetch -p')

for branch in branches:
    # 删除本地分支
    os.system(f'git branch -D {branch}')
    os.system(f'git checkout -b {branch} origin/{branch}')
    os.system('./rebase.sh')
    result = subprocess.getstatusoutput('git rev-parse --abbrev-ref HEAD')
    current_branch = result[1]
    print(f'当前分支为:{current_branch}')
    if current_branch != branch:
        print(f'分支:{branch} rebase 时发生冲突,请解决后重新运行脚本')
        break

你可能感兴趣的:(Git,git,python,并行开发,团队开发)