feat(cli): add branch push check before PR creation

This commit is contained in:
2026-06-11 18:24:53 +08:00
parent 1ea180387c
commit 9885096229
2 changed files with 58 additions and 0 deletions
+26
View File
@@ -23,6 +23,8 @@ import type { Config } from "./src/types";
import {
getDefaultBranch,
getBranchName,
getBranchPushStatus,
pushCurrentBranch,
getBranchCommits,
getBranchDiff,
detectPlatform,
@@ -524,6 +526,30 @@ async function handlePR(draft: boolean): Promise<void> {
` ${commits.length} commit${commits.length > 1 ? "s" : ""} on this branch`,
);
const pushStatus = await getBranchPushStatus();
if (!pushStatus.pushed) {
const target = pushStatus.upstream ?? `origin/${branchName}`;
const answer = await ask(
` Branch is not pushed to ${CYAN}${target}${RESET}. Push now? [${GREEN}Y${RESET}/n] `,
);
if (answer.toLowerCase() === "n") {
console.log(" Aborted.");
return;
}
console.log(` Pushing ${CYAN}${branchName}${RESET}...`);
try {
await pushCurrentBranch(branchName, pushStatus.upstream);
console.log(` ${GREEN}Pushed ${branchName}.${RESET}`);
} catch (err) {
console.error(
` ${RED}Push failed: ${err instanceof Error ? err.message : err}${RESET}`,
);
process.exit(1);
}
}
const diff = await getBranchDiff(baseBranch);
if (!diff) {
console.error(` ${RED}Error: No diff from base branch.${RESET}`);