chore: remove temp merge scripts
This commit is contained in:
parent
1922f505d6
commit
d3bcbae82a
165
batch_merge.py
165
batch_merge.py
|
|
@ -1,165 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
本地批量解冲突合入:对每个 PR 执行 git merge --no-ff,遇到冲突时 accept theirs。
|
||||
支持 add/add 冲突(两个分支都创建同名文件)。
|
||||
"""
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
REPO_DIR = "/tmp/gitlink-cli-rebase"
|
||||
os.chdir(REPO_DIR)
|
||||
|
||||
def run(cmd, check=True):
|
||||
r = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
if check and r.returncode != 0:
|
||||
return None
|
||||
return r
|
||||
|
||||
def git(cmd, check=False):
|
||||
return run(f"git {cmd}", check=check)
|
||||
|
||||
def get_conflicted_files():
|
||||
"""获取所有冲突文件(包括 add/add)"""
|
||||
r = git("status --porcelain")
|
||||
if not r:
|
||||
return []
|
||||
files = []
|
||||
for line in r.stdout.strip().split('\n'):
|
||||
if not line:
|
||||
continue
|
||||
status = line[:2]
|
||||
path = line[3:]
|
||||
# UU=both modified, AA=both added, DU/UD=delete conflicts
|
||||
if status in ('UU', 'AA', 'DU', 'UD', 'AU', 'UA'):
|
||||
files.append(path)
|
||||
return files
|
||||
|
||||
def resolve_conflicts():
|
||||
"""Accept theirs for all conflicted files"""
|
||||
files = get_conflicted_files()
|
||||
if not files:
|
||||
return False
|
||||
|
||||
for f in files:
|
||||
# For add/add conflicts, checkout --theirs may fail, use a different approach
|
||||
r = git(f'checkout --theirs "{f}"')
|
||||
if r is None or r.returncode != 0:
|
||||
# Fallback: just use what's in the index from theirs
|
||||
git(f'show :3:"{f}" > "{f}"', check=False)
|
||||
git(f'add "{f}"')
|
||||
return True
|
||||
|
||||
def merge_pr(remote, branch, number, title):
|
||||
"""Merge one PR branch into current HEAD"""
|
||||
msg = f"Merge PR #{number}: {title[:60]}"
|
||||
|
||||
# Try clean merge first
|
||||
r = git(f'merge --no-ff {remote}/{branch} -m "{msg}"')
|
||||
if r and r.returncode == 0:
|
||||
return "clean"
|
||||
|
||||
# Check if we have conflicts
|
||||
files = get_conflicted_files()
|
||||
if not files:
|
||||
# Not a conflict, some other error (e.g., branch not found)
|
||||
git("merge --abort")
|
||||
return "error"
|
||||
|
||||
# Resolve conflicts
|
||||
resolve_conflicts()
|
||||
|
||||
# Commit the merge
|
||||
r = git(f'commit --no-edit')
|
||||
if r and r.returncode == 0:
|
||||
return "resolved"
|
||||
|
||||
# If commit fails, abort
|
||||
git("merge --abort")
|
||||
return "failed"
|
||||
|
||||
def main():
|
||||
# Load PR list
|
||||
with open("/Users/baai/codebase/gitlink-cli/scripts/pr-triage/conflict_prs.json") as f:
|
||||
data = json.load(f)
|
||||
|
||||
high_risk_files = ['internal/auth/', 'token_store', 'internal/client/client.go', 'cmd/auth/']
|
||||
safe = []
|
||||
for pr in data['conflict']:
|
||||
cfs = pr['conflict_files']
|
||||
is_risky = any(any(h in cf for h in high_risk_files) for cf in cfs)
|
||||
if not is_risky:
|
||||
safe.append(pr)
|
||||
|
||||
safe.sort(key=lambda p: len(p['conflict_files']))
|
||||
|
||||
# Collect unique fork remotes
|
||||
forks = set()
|
||||
for pr in safe:
|
||||
if pr['fork_login']:
|
||||
forks.add(pr['fork_login'])
|
||||
|
||||
print(f"添加 {len(forks)} 个 fork remote 并 fetch...")
|
||||
for f in sorted(forks):
|
||||
git(f'remote add {f.lower()} https://www.gitlink.org.cn/{f}/gitlink-cli.git')
|
||||
r = git(f'fetch {f.lower()}')
|
||||
if r is None or r.returncode != 0:
|
||||
print(f" ⚠️ fetch {f} 失败")
|
||||
|
||||
print(f"\n开始合并 {len(safe)} 个 PR...")
|
||||
print("=" * 60)
|
||||
|
||||
merged = 0
|
||||
failed = 0
|
||||
failed_prs = []
|
||||
|
||||
for i, pr in enumerate(safe):
|
||||
num = pr['number']
|
||||
remote = pr['fork_login'].lower() if pr['fork_login'] else 'origin'
|
||||
branch = pr['head']
|
||||
title = pr['title']
|
||||
|
||||
# Check branch exists
|
||||
r = git(f'rev-parse --verify {remote}/{branch}')
|
||||
if r is None or r.returncode != 0:
|
||||
print(f" [{i+1}/{len(safe)}] #{num}: ❌ branch {remote}/{branch} not found")
|
||||
failed += 1
|
||||
failed_prs.append((num, "branch not found"))
|
||||
continue
|
||||
|
||||
result = merge_pr(remote, branch, num, title)
|
||||
|
||||
if result in ("clean", "resolved"):
|
||||
merged += 1
|
||||
tag = "✅" if result == "clean" else "✅ (conflict resolved)"
|
||||
print(f" [{i+1}/{len(safe)}] #{num}: {tag}")
|
||||
else:
|
||||
failed += 1
|
||||
failed_prs.append((num, result))
|
||||
print(f" [{i+1}/{len(safe)}] #{num}: ❌ {result}")
|
||||
|
||||
# Progress summary every 20
|
||||
if (i + 1) % 20 == 0:
|
||||
print(f" --- 进度: {merged} merged, {failed} failed ---")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print(f"完成: 合并 {merged}, 失败 {failed}")
|
||||
|
||||
if failed_prs:
|
||||
print(f"\n失败的 PR:")
|
||||
for num, reason in failed_prs:
|
||||
print(f" #{num}: {reason}")
|
||||
|
||||
# Verify build
|
||||
print("\n验证编译...")
|
||||
r = run("go build ./...")
|
||||
if r and r.returncode == 0:
|
||||
print(" ✅ go build 通过")
|
||||
else:
|
||||
print(" ❌ go build 失败!")
|
||||
if r:
|
||||
print(r.stderr[:500])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
3801
merge_all.sh
3801
merge_all.sh
File diff suppressed because it is too large
Load Diff
|
|
@ -1,92 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# PR 处理顺序和对应的 fork branch
|
||||
declare -A PR_BRANCHES
|
||||
PR_BRANCHES[421]="taoyouce/feat/skill-fork-sync"
|
||||
PR_BRANCHES[413]="taoyouce/feat/semantic-audit-skill"
|
||||
PR_BRANCHES[412]="taoyouce/feat/issue-delete"
|
||||
PR_BRANCHES[406]="chroe/fix/msys2-path-pollution"
|
||||
PR_BRANCHES[304]="muel/fix/i18n-locale-eol"
|
||||
PR_BRANCHES[379]="taoyouce/feat/repo-topics"
|
||||
PR_BRANCHES[378]="taoyouce/feat/repo-blame"
|
||||
PR_BRANCHES[382]="taoyouce/feat/repo-activity"
|
||||
PR_BRANCHES[381]="taoyouce/feat/repo-forks-topcounts"
|
||||
PR_BRANCHES[355]="taoyouce/feat/repo-clone"
|
||||
PR_BRANCHES[386]="taoyouce/feat/branch-default-all"
|
||||
PR_BRANCHES[284]="mengz/mengz/pr-list-search-number"
|
||||
PR_BRANCHES[283]="mengz/mengz/pr-list-show-number"
|
||||
PR_BRANCHES[213]="wangyue111/feat/repo-mirror-sync-shortcut"
|
||||
|
||||
ORDER=(421 413 412 406 304 379 378 382 381 355 386 284 283 213)
|
||||
|
||||
echo "开始按顺序处理 ${#ORDER[@]} 个冲突 PR..."
|
||||
echo ""
|
||||
|
||||
for PR_NUM in "${ORDER[@]}"; do
|
||||
BRANCH="${PR_BRANCHES[$PR_NUM]}"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "处理 PR #${PR_NUM}: branch=${BRANCH}"
|
||||
|
||||
# 创建临时分支来做 rebase
|
||||
TEMP_BRANCH="rebase-pr-${PR_NUM}"
|
||||
git checkout -B "$TEMP_BRANCH" "$BRANCH" 2>/dev/null
|
||||
|
||||
# Rebase onto master
|
||||
if git rebase origin/master 2>/dev/null; then
|
||||
echo " ✅ rebase 成功 (无需手动解冲突)"
|
||||
else
|
||||
echo " ⚠️ rebase 有冲突,尝试自动解决..."
|
||||
# 对于 JSON 文件、README、test 文件的追加冲突,accept theirs for new content
|
||||
CONFLICTED=$(git diff --name-only --diff-filter=U 2>/dev/null)
|
||||
echo " 冲突文件: $CONFLICTED"
|
||||
|
||||
ALL_RESOLVED=true
|
||||
for F in $CONFLICTED; do
|
||||
case "$F" in
|
||||
*.json)
|
||||
# JSON 文件: accept both (theirs adds new keys)
|
||||
git checkout --theirs "$F" 2>/dev/null && git add "$F"
|
||||
echo " $F → accept theirs (新增 key)"
|
||||
;;
|
||||
*README*)
|
||||
# README: accept theirs (新增行)
|
||||
git checkout --theirs "$F" 2>/dev/null && git add "$F"
|
||||
echo " $F → accept theirs (新增行)"
|
||||
;;
|
||||
*_test.go)
|
||||
# Test 文件: accept theirs (新增测试)
|
||||
git checkout --theirs "$F" 2>/dev/null && git add "$F"
|
||||
echo " $F → accept theirs (新增测试)"
|
||||
;;
|
||||
*.go)
|
||||
# Go 源文件: accept theirs (新增函数/注册)
|
||||
git checkout --theirs "$F" 2>/dev/null && git add "$F"
|
||||
echo " $F → accept theirs (新增代码)"
|
||||
;;
|
||||
*)
|
||||
git checkout --theirs "$F" 2>/dev/null && git add "$F"
|
||||
echo " $F → accept theirs"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
git rebase --continue --no-edit 2>/dev/null || {
|
||||
# 可能还有后续冲突
|
||||
CONFLICTED2=$(git diff --name-only --diff-filter=U 2>/dev/null)
|
||||
if [ -n "$CONFLICTED2" ]; then
|
||||
for F in $CONFLICTED2; do
|
||||
git checkout --theirs "$F" 2>/dev/null && git add "$F"
|
||||
done
|
||||
git rebase --continue --no-edit 2>/dev/null || git rebase --abort
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# 回到 master
|
||||
git checkout master 2>/dev/null
|
||||
echo ""
|
||||
done
|
||||
|
||||
echo "所有 PR 已 rebase 到各自临时分支"
|
||||
echo "现在逐个 merge 到 master..."
|
||||
Loading…
Reference in New Issue