Skip to content

Commit 2c37797

Browse files
only21milclaudemaria-rcks
authored
fix(server): commits no longer land on a branch switched in mid-action (pingdotgg#24473)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 505d022 commit 2c37797

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3906,7 +3906,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
39063906
return { repoDir, manager, providerCalls, firstCommit, pullHead };
39073907
});
39083908

3909-
it.effect.each(["switch", "create-and-switch", "feature-branch"] as const)(
3909+
it.effect.each(["switch", "create-and-switch", "feature-branch", "commit"] as const)(
39103910
"local PR checkout excludes a concurrent %s from a nested project with an alternate root",
39113911
(operation) =>
39123912
Effect.gen(function* () {
@@ -3956,7 +3956,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
39563956
...manager,
39573957
runStackedAction: (input, options) =>
39583958
Effect.sync(() => {
3959-
events.push("feature-branch");
3959+
events.push(input.featureBranch ? "feature-branch" : "commit");
39603960
NodeFS.writeFileSync(
39613961
NodePath.join(repoDir, "second-client.txt"),
39623962
"second client\n",
@@ -3993,9 +3993,9 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
39933993
})
39943994
: workflows[1]!.runStackedAction({
39953995
cwd: nestedCwd,
3996-
actionId: "second-client-feature-branch",
3996+
actionId: `second-client-${operation}`,
39973997
action: "commit",
3998-
featureBranch: true,
3998+
featureBranch: operation === "feature-branch",
39993999
commitMessage: "Second client commit",
40004000
}),
40014001
{ startImmediately: true },
@@ -4008,15 +4008,16 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
40084008
expect(events).toEqual([operation]);
40094009
expect(prepared).toMatchObject({ branch: "feature/pr-safe", isOnPullRequestHead: true });
40104010
expect((yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim()).toBe(mainCommit);
4011-
expect((yield* runGit(repoDir, ["rev-parse", "feature/pr-safe"])).stdout.trim()).toBe(
4012-
pullHead,
4013-
);
4011+
const pullBranch = operation === "commit" ? "feature/pr-safe^" : "feature/pr-safe";
4012+
expect((yield* runGit(repoDir, ["rev-parse", pullBranch])).stdout.trim()).toBe(pullHead);
40144013
expect((yield* runGit(repoDir, ["branch", "--show-current"])).stdout.trim()).toBe(
40154014
operation === "switch"
40164015
? "main"
4017-
: "branch" in switched
4018-
? switched.branch.name
4019-
: "second-client",
4016+
: operation === "commit"
4017+
? "feature/pr-safe"
4018+
: "branch" in switched
4019+
? switched.branch.name
4020+
: "second-client",
40204021
);
40214022
if ("commit" in switched) {
40224023
expect(switched.commit.status).toBe("created");

‎apps/server/src/git/GitWorkflowService.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,10 @@ export const make = Effect.gen(function* () {
377377
runStackedAction: Effect.fn("GitWorkflowService.runStackedAction")(function (input, options) {
378378
return ensureGit("GitWorkflowService.runStackedAction", input.cwd).pipe(
379379
Effect.flatMap((handle) =>
380-
input.featureBranch
381-
? withCheckoutLease(
382-
handle.repository.rootPath,
383-
gitManager.runStackedAction(input, options),
384-
)
385-
: gitManager.runStackedAction(input, options),
380+
withCheckoutLease(
381+
handle.repository.rootPath,
382+
gitManager.runStackedAction(input, options),
383+
),
386384
),
387385
);
388386
}),

0 commit comments

Comments
 (0)