Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ export function getRemoteBranches() {
export function isBranchPushedToRemote(branchName) {
try {
// Check if the branch exists on the remote
execSync(`git ls-remote --heads origin ${branchName}`, { stdio: 'ignore' });
return true;
const output = execSync(`git ls-remote --heads origin ${branchName}`).toString().trim();
// If output is empty, branch doesn't exist on remote
return output.length > 0;
} catch {
return false;
}
Expand Down Expand Up @@ -303,9 +304,18 @@ export async function main() {
// Check if branch is pushed to remote
let needsToPush = false;
if (!isBranchPushedToRemote(currentBranch)) {
console.log(`\n🔄 Branch '${currentBranch}' not found on remote. Pushing now...`);
needsToPush = true;
const shouldPush = await confirm({
message: `Branch '${currentBranch}' not found on remote. Push to origin?`,
default: true
});

if (!shouldPush) {
console.log('\n❌ Cannot create PR without pushing branch to remote.');
return;
}

needsToPush = true;
console.log(`\n🔄 Pushing branch '${currentBranch}' to remote...`);
const pushSucceeded = pushBranchToRemote(currentBranch);
if (!pushSucceeded) {
console.error('\n❌ Failed to push branch to remote. Cannot create PR.');
Expand Down