mirror of
https://github.com/stablyai/orca.git
synced 2026-10-12 08:02:37 +00:00
fix: avoid --delete-branch to prevent worktree branch deletion error
gh pr merge --delete-branch fails when the current worktree is on the branch being merged, because git refuses to delete a checked-out branch. Instead, merge without --delete-branch and delete only the remote branch afterward. Local branch cleanup is left to the worktree manager.
This commit is contained in:
@@ -249,11 +249,34 @@ export async function mergePR(
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
await acquire()
|
||||
try {
|
||||
await execFileAsync('gh', ['pr', 'merge', String(prNumber), `--${method}`, '--delete-branch'], {
|
||||
await execFileAsync('gh', ['pr', 'merge', String(prNumber), `--${method}`], {
|
||||
cwd: repoPath,
|
||||
encoding: 'utf-8',
|
||||
env: { ...process.env, GH_PROMPT_DISABLED: '1' }
|
||||
})
|
||||
// Delete remote branch separately — local branch deletion fails when
|
||||
// the user's worktree is checked out on that branch, so we only clean
|
||||
// up the remote side. Local cleanup is left to the caller / worktree manager.
|
||||
const headBranch = (
|
||||
await execFileAsync(
|
||||
'gh',
|
||||
['pr', 'view', String(prNumber), '--json', 'headRefName', '-q', '.headRefName'],
|
||||
{
|
||||
cwd: repoPath,
|
||||
encoding: 'utf-8'
|
||||
}
|
||||
)
|
||||
).stdout.trim()
|
||||
if (headBranch) {
|
||||
try {
|
||||
await execFileAsync('git', ['push', 'origin', '--delete', headBranch], {
|
||||
cwd: repoPath,
|
||||
encoding: 'utf-8'
|
||||
})
|
||||
} catch {
|
||||
// Remote branch may already be deleted by GitHub — ignore
|
||||
}
|
||||
}
|
||||
return { ok: true }
|
||||
} catch (err) {
|
||||
const message =
|
||||
|
||||
Reference in New Issue
Block a user