History

fix: avoid no-upstream push skip when base cannot be resolved

Julius Marminge committed 8 months ago

Commit 96efd1c1 parent c8974ed2 files · +44 −6Browse files

Unified · Split

2 files
  1. apps/server/src/git/Layers/GitCore.test.ts +25 −0
  2. apps/server/src/git/Layers/GitCore.ts +19 −6
apps/server/src/git/Layers/GitCore.test.ts+25−0
@@ -1177,6 +1177,31 @@ it.layer(TestLayer)("git integration", (it) => { · 1176 unmodified lines
11771177 }),
11781178 );
11791179
1180+ it.effect("pushes with upstream setup when no comparable base branch exists", () =>
1181+ Effect.gen(function* () {
1182+ const tmp = yield* makeTmpDir();
1183+ const remote = yield* makeTmpDir();
1184+ yield* git(tmp, ["init", "--initial-branch=trunk"]);
1185+ yield* git(tmp, ["config", "user.email", "test@test.com"]);
1186+ yield* git(tmp, ["config", "user.name", "Test"]);
1187+ yield* writeTextFile(path.join(tmp, "README.md"), "hello\n");
1188+ yield* git(tmp, ["add", "README.md"]);
1189+ yield* git(tmp, ["commit", "-m", "initial"]);
1190+ yield* git(remote, ["init", "--bare"]);
1191+ yield* git(tmp, ["remote", "add", "origin", remote]);
1192+ yield* git(tmp, ["checkout", "-b", "feature/no-base"]);
1193+
1194+ const core = yield* GitCore;
1195+ const pushed = yield* core.pushCurrentBranch(tmp, null);
1196+ expect(pushed.status).toBe("pushed");
1197+ expect(pushed.setUpstream).toBe(true);
1198+ expect(pushed.upstreamBranch).toBe("origin/feature/no-base");
1199+ expect(yield* git(tmp, ["rev-parse", "--abbrev-ref", "@{upstream}"])).toBe(
1200+ "origin/feature/no-base",
1201+ );
1202+ }),
1203+ );
1204+
11801205 it.effect("includes command context when worktree removal fails", () =>
11811206 Effect.gen(function* () {
11821207 const tmp = yield* makeTmpDir();
apps/server/src/git/Layers/GitCore.ts+19−6
@@ -630,12 +630,25 @@ const makeGitCore = Effect.gen(function* () { · 629 unmodified lines
630630 );
631631 }
632632
633− if (details.aheadCount === 0 && details.behindCount === 0) {
634− return {
635− status: "skipped_up_to_date" as const,
636− branch,
637− ...(details.upstreamRef ? { upstreamBranch: details.upstreamRef } : {}),
638− };
633+ const hasNoLocalDelta = details.aheadCount === 0 && details.behindCount === 0;
634+ if (hasNoLocalDelta) {
635+ if (details.hasUpstream) {
636+ return {
637+ status: "skipped_up_to_date" as const,
638+ branch,
639+ ...(details.upstreamRef ? { upstreamBranch: details.upstreamRef } : {}),
640+ };
641+ }
642+
643+ const comparableBaseBranch = yield* resolveBaseBranchForNoUpstream(cwd, branch).pipe(
644+ Effect.catch(() => Effect.succeed(null)),
645+ );
646+ if (comparableBaseBranch) {
647+ return {
648+ status: "skipped_up_to_date" as const,
649+ branch,
650+ };
651+ }
639652 }
640653
641654 if (!details.hasUpstream) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t