feat(cli): add branch push check before PR creation
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user