@devries-cameron20 / t3code Mirror · read-only / commits / d6888999db
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 04:15 UTC

perf(server): skip unused probes when switching Git refs (#20140)

IfkumRfnl committed Oct 18, 2026 at 23:13 UTC d6888999dba6052b04708cf586eecf36897dd264
2 files changed +65 -20
apps/server/src/vcs/GitVcsDriverCore.test.ts
+46 -2
@@ -3062,23 +3062,67 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3062 const cwd = yield* makeTmpDir();
3063 const remote = yield* makeTmpDir("git-remote-");
3064 const { initialBranch } = yield* initRepoWithCommit(cwd);
3065 - const driver = yield* GitVcsDriver.GitVcsDriver;
3065 + const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
3066 + const commands: Array<ReadonlyArray<string>> = [];
3067 + const spawner = ChildProcessSpawner.make((command) =>
3068 + Effect.gen(function* () {
3069 + if (ChildProcess.isStandardCommand(command)) commands.push(command.args);
3070 + return yield* delegate.spawn(command);
3071 + }),
3072 + );
3073 + const driver = yield* makeGitVcsDriverCore().pipe(
3074 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
3075 + Effect.provide(layerServerConfig),
3076 + );
3077 + const assertCheckout = (
3078 + checkoutArgs: ReadonlyArray<string>,
3079 + existenceReads: number,
3080 + trackingReads: number,
3081 + ) => {
3082 + assert.deepEqual(
3083 + commands.filter((args) => args[0] === "checkout"),
3084 + [checkoutArgs],
3085 + );
3086 + assert.equal(commands.filter((args) => args[0] === "show-ref").length, existenceReads);
3087 + assert.equal(commands.filter((args) => args[0] === "for-each-ref").length, trackingReads);
3088 + assert.deepEqual(
3089 + commands.filter((args) => args[0] === "branch"),
3090 + [["branch", "--show-current"]],
3091 + );
3092 + };
3093 yield* git(remote, ["init", "--bare"]);
3094 yield* git(cwd, ["remote", "add", "origin", remote]);
3095 yield* git(cwd, ["push", "origin", "HEAD:refs/heads/remote-only"]);
3096
3097 for (let attempt = 0; attempt < 2; attempt += 1) {
3098 + commands.length = 0;
3099 const result = yield* driver.switchRef({ cwd, refName: "origin/remote-only" });
3072 - assert.equal(result.refName, "remote-only");
3100 + assert.equal(result.refName, attempt === 0 ? "remote-only" : "review/renamed");
3101 + assertCheckout(
3102 + attempt === 0
3103 + ? ["checkout", "--track", "origin/remote-only", "--"]
3104 + : ["checkout", "review/renamed", "--"],
3105 + attempt === 0 ? 3 : 2,
3106 + 1,
3107 + );
3108 assert.equal(
3109 yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]),
3110 "origin/remote-only",
3111 );
3112 + if (attempt === 0) yield* git(cwd, ["branch", "-m", "review/renamed"]);
3113 yield* driver.switchRef({ cwd, refName: initialBranch });
3114 }
3115 + yield* git(cwd, ["branch", "origin/remote-only"]);
3116 + commands.length = 0;
3117 + const shadowed = yield* driver.switchRef({ cwd, refName: "origin/remote-only" });
3118 + assert.equal(shadowed.refName, "origin/remote-only");
3119 + assertCheckout(["checkout", "origin/remote-only", "--"], 2, 0);
3120 +
3121 const commit = yield* git(cwd, ["rev-parse", "HEAD"]);
3122 + commands.length = 0;
3123 const detached = yield* driver.switchRef({ cwd, refName: commit });
3124 assert.equal(detached.refName, null);
3125 + assertCheckout(["checkout", commit, "--"], 2, 0);
3126 assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), commit);
3127 }),
3128 );
apps/server/src/vcs/GitVcsDriverCore.ts
+19 -18
@@ -3933,27 +3933,28 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3933 { concurrency: "unbounded" },
3934 );
3935
3936 - const localTrackingBranch = remoteExists
3937 - ? yield* executeGit(
3938 - "GitVcsDriver.switchRef.localTrackingBranch",
3939 - input.cwd,
3940 - ["for-each-ref", "--format=%(refname:short)\t%(upstream:short)", "refs/heads"],
3941 - {
3942 - timeoutMs: 5_000,
3943 - allowNonZeroExit: true,
3944 - },
3945 - ).pipe(
3946 - Effect.map((result) =>
3947 - result.exitCode === 0
3948 - ? parseTrackingBranchByUpstreamRef(result.stdout, input.refName)
3949 - : null,
3950 - ),
3951 - )
3952 - : null;
3936 + const localTrackingBranch =
3937 + remoteExists && !localInputExists
3938 + ? yield* executeGit(
3939 + "GitVcsDriver.switchRef.localTrackingBranch",
3940 + input.cwd,
3941 + ["for-each-ref", "--format=%(refname:short)\t%(upstream:short)", "refs/heads"],
3942 + {
3943 + timeoutMs: 5_000,
3944 + allowNonZeroExit: true,
3945 + },
3946 + ).pipe(
3947 + Effect.map((result) =>
3948 + result.exitCode === 0
3949 + ? parseTrackingBranchByUpstreamRef(result.stdout, input.refName)
3950 + : null,
3951 + ),
3952 + )
3953 + : null;
3954
3955 const localTrackedBranchCandidate = deriveLocalBranchNameFromRemoteRef(input.refName);
3956 const localTrackedBranchTargetExists =
3956 - remoteExists && localTrackedBranchCandidate
3957 + remoteExists && !localInputExists && !localTrackingBranch && localTrackedBranchCandidate
3958 ? yield* executeGit(
3959 "GitVcsDriver.switchRef.localTrackedBranchTargetExists",
3960 input.cwd,