Skip to content

Commit 49f80d4

Browse files
authored
Added push to remote for PR creator. (#16)
2 parents be0d0ae + f34fbb9 commit 49f80d4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ export function getRemoteBranches() {
9696
export function isBranchPushedToRemote(branchName) {
9797
try {
9898
// Check if the branch exists on the remote
99-
execSync(`git ls-remote --heads origin ${branchName}`, { stdio: 'ignore' });
100-
return true;
99+
const output = execSync(`git ls-remote --heads origin ${branchName}`).toString().trim();
100+
// If output is empty, branch doesn't exist on remote
101+
return output.length > 0;
101102
} catch {
102103
return false;
103104
}
@@ -300,9 +301,18 @@ export async function main() {
300301
// Check if branch is pushed to remote
301302
let needsToPush = false;
302303
if (!isBranchPushedToRemote(currentBranch)) {
303-
console.log(`\n🔄 Branch '${currentBranch}' not found on remote. Pushing now...`);
304-
needsToPush = true;
304+
const shouldPush = await confirm({
305+
message: `Branch '${currentBranch}' not found on remote. Push to origin?`,
306+
default: true
307+
});
305308

309+
if (!shouldPush) {
310+
console.log('\n❌ Cannot create PR without pushing branch to remote.');
311+
return;
312+
}
313+
314+
needsToPush = true;
315+
console.log(`\n🔄 Pushing branch '${currentBranch}' to remote...`);
306316
const pushSucceeded = pushBranchToRemote(currentBranch);
307317
if (!pushSucceeded) {
308318
console.error('\n❌ Failed to push branch to remote. Cannot create PR.');

0 commit comments

Comments
 (0)