Skip to content

Commit 7d1fcd7

Browse files
committed
feat: gitCycle — full merge-to-main path (commit, push branch, ff-merge, push main, mirrors)
1 parent 895a8bf commit 7d1fcd7

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

run.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,41 @@ async function gitCycle(sync) {
197197
const commit = await run("git", ["commit", "-m",
198198
"chore: run.js launch cycle — auto-detected platform, git cycle"]);
199199
if (commit.ok) log("Committed outstanding changes");
200-
else warn("Commit failed: " + commit.err);
200+
else { warn("Commit failed: " + commit.err); return; }
201201
} else {
202202
log("Nothing to commit");
203203
}
204204

205-
if (sync.ahead > 0 || staged.out) {
206-
const push = await run("git", ["push", REGISTRY.git.remote, sync.branch]);
207-
if (push.ok) log(`Pushed to ${REGISTRY.git.remote}/${sync.branch}`);
208-
else warn("Push failed: " + push.err);
205+
// Push current branch
206+
const pushBranch = await run("git", ["push", REGISTRY.git.remote, sync.branch]);
207+
if (pushBranch.ok) log(`Pushed ${sync.branch}${REGISTRY.git.remote}`);
208+
else warn("Push failed: " + pushBranch.err);
209+
210+
// Merge to main if not already there
211+
const mainBranch = "main";
212+
if (sync.branch !== mainBranch) {
213+
log(`Merging ${sync.branch}${mainBranch}...`);
214+
const checkout = await run("git", ["checkout", mainBranch]);
215+
if (!checkout.ok) { warn("Could not switch to main: " + checkout.err); return; }
216+
217+
const merge = await run("git", ["merge", "--ff-only", sync.branch]);
218+
if (merge.ok) {
219+
log(`Fast-forward merged ${sync.branch}${mainBranch}`);
220+
} else {
221+
const mergeRegular = await run("git", ["merge", sync.branch,
222+
"-m", `chore: merge ${sync.branch} → main`]);
223+
if (!mergeRegular.ok) { warn("Merge failed: " + mergeRegular.err); return; }
224+
log(`Merged ${sync.branch}${mainBranch}`);
225+
}
226+
227+
const pushMain = await run("git", ["push", REGISTRY.git.remote, mainBranch]);
228+
if (pushMain.ok) log(`Pushed ${mainBranch}${REGISTRY.git.remote}`);
229+
else warn("Main push failed: " + pushMain.err);
209230
}
210231

232+
// Push to mirrors
211233
for (const mirror of REGISTRY.git.mirrors) {
212-
const mp = await run("git", ["push", mirror, sync.branch]);
234+
const mp = await run("git", ["push", mirror, mainBranch]);
213235
if (mp.ok) log(`Pushed to mirror: ${mirror}`);
214236
else warn(`Mirror push failed (${mirror}): ${mp.err}`);
215237
}

0 commit comments

Comments
 (0)