Skip to content

Commit e0b50fa

Browse files
committed
fix(server): a failing final status read no longer fails a completed git action
The completion toast read git status after the commit and push had landed. If that read failed, for example on a locked index, the whole action failed. The read is now best-effort like the PR lookup next to it, and the Create PR button is left out when the branch state is unknown. Generated with Claude Opus 5.5 in T3 Code Nightly
1 parent 25bf84a commit e0b50fa

2 files changed

Lines changed: 62 additions & 10 deletions

File tree

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,56 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
34133413
}),
34143414
);
34153415

3416+
it.effect("finishes a pushed commit when the final status read fails", () =>
3417+
Effect.gen(function* () {
3418+
const repoDir = yield* makeTempDir("t3code-git-manager-");
3419+
yield* initRepo(repoDir);
3420+
yield* runGit(repoDir, ["checkout", "-b", "feature/status-after-push"]);
3421+
const remoteDir = yield* createBareRemote();
3422+
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
3423+
NodeFS.writeFileSync(NodePath.join(repoDir, "change.txt"), "change\n");
3424+
const gate = {
3425+
matches: (args: ReadonlyArray<string>) => args[0] === "push",
3426+
reached: yield* Deferred.make<void>(),
3427+
release: yield* Deferred.make<void>(),
3428+
};
3429+
const events: GitActionProgressEvent[] = [];
3430+
const { manager } = yield* makeManager({ gitSpawnGate: gate });
3431+
3432+
const action = yield* Effect.forkChild(
3433+
runStackedAction(
3434+
manager,
3435+
{ cwd: repoDir, action: "commit_push", commitMessage: "Status after push" },
3436+
{
3437+
progressReporter: {
3438+
publish: (event) =>
3439+
Effect.sync(() => {
3440+
events.push(event);
3441+
}),
3442+
},
3443+
},
3444+
),
3445+
);
3446+
yield* Deferred.await(gate.reached);
3447+
NodeFS.writeFileSync(NodePath.join(repoDir, ".git", "index.lock"), "");
3448+
yield* Deferred.succeed(gate.release, undefined);
3449+
const result = yield* Fiber.join(action);
3450+
3451+
expect(result.push.status).toBe("pushed");
3452+
expect(result.toast.cta).toEqual({ kind: "none" });
3453+
expect(events.at(-1)?.kind).toBe("action_finished");
3454+
expect(
3455+
(yield* runGit(remoteDir, [
3456+
"--git-dir=.",
3457+
"log",
3458+
"-1",
3459+
"--pretty=%s",
3460+
"feature/status-after-push",
3461+
])).stdout.trim(),
3462+
).toBe("Status after push");
3463+
}),
3464+
);
3465+
34163466
it.effect("hands the branch base to the host when a failed first push is retried", () =>
34173467
Effect.gen(function* () {
34183468
const repoDir = yield* makeTempDir("t3code-git-manager-");

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,16 +1945,17 @@ export const make = Effect.gen(function* () {
19451945
hasUpstream: boolean;
19461946
} | null = null;
19471947

1948-
if (result.action !== "commit") {
1949-
const finalStatus = yield* gitCore.statusDetails(cwd);
1950-
if (finalStatus.branch) {
1951-
finalBranchContext = {
1952-
branch: finalStatus.branch,
1953-
upstreamRef: finalStatus.upstreamRef,
1954-
hasUpstream: finalStatus.hasUpstream,
1955-
};
1956-
currentBranchIsDefault = finalStatus.isDefaultBranch;
1957-
}
1948+
const finalStatus =
1949+
result.action === "commit"
1950+
? null
1951+
: yield* gitCore.statusDetails(cwd).pipe(Effect.orElseSucceed(() => null));
1952+
if (finalStatus?.branch) {
1953+
finalBranchContext = {
1954+
branch: finalStatus.branch,
1955+
upstreamRef: finalStatus.upstreamRef,
1956+
hasUpstream: finalStatus.hasUpstream,
1957+
};
1958+
currentBranchIsDefault = finalStatus.isDefaultBranch;
19581959
}
19591960

19601961
const explicitResultPr =
@@ -2006,6 +2007,7 @@ export const make = Effect.gen(function* () {
20062007
}
20072008
: (result.action === "push" || result.action === "commit_push") &&
20082009
result.push.status === "pushed" &&
2010+
finalStatus !== null &&
20092011
!currentBranchIsDefault
20102012
? {
20112013
kind: "run_action" as const,

0 commit comments

Comments
 (0)