From 96efd1cef04489233e00f602bad42d5dd7625ecc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 1 Mar 2026 11:36:41 -0800 Subject: [PATCH] fix: avoid no-upstream push skip when base cannot be resolved Co-authored-by: codex --- apps/server/src/git/Layers/GitCore.test.ts | 25 ++++++++++++++++++++++ apps/server/src/git/Layers/GitCore.ts | 25 ++++++++++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/apps/server/src/git/Layers/GitCore.test.ts b/apps/server/src/git/Layers/GitCore.test.ts index 53fc7bf3be4fe3db479cdd4af785dd117ca283a1..7e6a7c6c0941de915f5a4d79035e92c3acf597f5 100644 --- a/apps/server/src/git/Layers/GitCore.test.ts +++ b/apps/server/src/git/Layers/GitCore.test.ts @@ -1177,6 +1177,31 @@ it.layer(TestLayer)("git integration", (it) => { }), ); + it.effect("pushes with upstream setup when no comparable base branch exists", () => + Effect.gen(function* () { + const tmp = yield* makeTmpDir(); + const remote = yield* makeTmpDir(); + yield* git(tmp, ["init", "--initial-branch=trunk"]); + yield* git(tmp, ["config", "user.email", "test@test.com"]); + yield* git(tmp, ["config", "user.name", "Test"]); + yield* writeTextFile(path.join(tmp, "README.md"), "hello\n"); + yield* git(tmp, ["add", "README.md"]); + yield* git(tmp, ["commit", "-m", "initial"]); + yield* git(remote, ["init", "--bare"]); + yield* git(tmp, ["remote", "add", "origin", remote]); + yield* git(tmp, ["checkout", "-b", "feature/no-base"]); + + const core = yield* GitCore; + const pushed = yield* core.pushCurrentBranch(tmp, null); + expect(pushed.status).toBe("pushed"); + expect(pushed.setUpstream).toBe(true); + expect(pushed.upstreamBranch).toBe("origin/feature/no-base"); + expect(yield* git(tmp, ["rev-parse", "--abbrev-ref", "@{upstream}"])).toBe( + "origin/feature/no-base", + ); + }), + ); + it.effect("includes command context when worktree removal fails", () => Effect.gen(function* () { const tmp = yield* makeTmpDir(); diff --git a/apps/server/src/git/Layers/GitCore.ts b/apps/server/src/git/Layers/GitCore.ts index 543a721eff817ad3ceec1330bb411d3ecc5ae776..570b214fbbc2f0396c15e25d8852481efd10b1ca 100644 --- a/apps/server/src/git/Layers/GitCore.ts +++ b/apps/server/src/git/Layers/GitCore.ts @@ -630,12 +630,25 @@ const makeGitCore = Effect.gen(function* () { ); } - if (details.aheadCount === 0 && details.behindCount === 0) { - return { - status: "skipped_up_to_date" as const, - branch, - ...(details.upstreamRef ? { upstreamBranch: details.upstreamRef } : {}), - }; + const hasNoLocalDelta = details.aheadCount === 0 && details.behindCount === 0; + if (hasNoLocalDelta) { + if (details.hasUpstream) { + return { + status: "skipped_up_to_date" as const, + branch, + ...(details.upstreamRef ? { upstreamBranch: details.upstreamRef } : {}), + }; + } + + const comparableBaseBranch = yield* resolveBaseBranchForNoUpstream(cwd, branch).pipe( + Effect.catch(() => Effect.succeed(null)), + ); + if (comparableBaseBranch) { + return { + status: "skipped_up_to_date" as const, + branch, + }; + } } if (!details.hasUpstream) { -- 2.54.0