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 22, 23:15 UTC
perf(server): skip unused default-branch lookups (#19825)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
IfkumRfnl committed
Oct 20, 2026 at 08:11 UTC
be21de48bc48e0976fa0bd64bccfe206d5c30035
2 files changed
+72
-12
apps/server/src/vcs/GitVcsDriverCore.test.ts
+54
-3
@@ -2963,6 +2963,27 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
2963
aheadOfDefaultCount: 0,
2964
});
2965
}
2966
+
2967
+ yield* git(cwd, ["branch", "-f", initialBranch, "HEAD"]);
2968
+ yield* git(cwd, ["update-ref", "refs/remotes/origin/trunk", "HEAD"]);
2969
+ yield* git(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/trunk"]);
2970
+ for (const base of [initialBranch, "missing-base"]) {
2971
+ yield* git(cwd, ["config", "branch.feature/local-only.gh-merge-base", base]);
2972
+ commands.length = 0;
2973
+ const status = yield* driver.statusDetailsLocal(cwd, {
2974
+ includeDivergence: false,
2975
+ includeBranchChanges: true,
2976
+ });
2977
+ assert.deepEqual(status.branchChanges, {
2978
+ baseRef: `origin/${base === initialBranch ? initialBranch : "trunk"}`,
2979
+ insertions: base === initialBranch ? 3 : 2,
2980
+ deletions: 0,
2981
+ });
2982
+ assert.lengthOf(
2983
+ commands.filter((args) => args.join(" ") === "symbolic-ref refs/remotes/origin/HEAD"),
2984
+ base === initialBranch ? 0 : 1,
2985
+ );
2986
+ }
2987
}),
2988
);
2989
@@ -2970,27 +2991,57 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
2991
Effect.gen(function* () {
2992
const cwd = yield* makeTmpDir();
2993
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
2973
- const { initialBranch } = yield* initRepoWithCommit(cwd);
2994
+ yield* initRepoWithCommit(cwd);
2995
+ yield* git(cwd, ["branch", "-M", "trunk"]);
2996
yield* git(remote, ["init", "--bare"]);
2997
yield* git(cwd, ["remote", "add", "origin", remote]);
2976
- yield* git(cwd, ["push", "-u", "origin", initialBranch]);
2998
+ yield* git(cwd, ["push", "-u", "origin", "trunk"]);
2999
yield* git(cwd, ["checkout", "-b", "feature/remote-status"]);
3000
yield* writeTextFile(cwd, "feature.txt", "feature\n");
3001
yield* git(cwd, ["add", "feature.txt"]);
3002
yield* git(cwd, ["commit", "-m", "feature commit"]);
3003
yield* git(cwd, ["push", "-u", "origin", "feature/remote-status"]);
3004
yield* writeTextFile(cwd, "untracked.txt", "local-only\n");
3005
+ yield* git(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/trunk"]);
3006
2984
- const status = yield* (yield* GitVcsDriver.GitVcsDriver).statusDetailsRemote(cwd);
3007
+ const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
3008
+ let originHeadReads = 0;
3009
+ let failFirstOriginHead = false;
3010
+ const spawner = ChildProcessSpawner.make((command) =>
3011
+ Effect.gen(function* () {
3012
+ if (
3013
+ ChildProcess.isStandardCommand(command) &&
3014
+ command.args.join(" ") === "symbolic-ref refs/remotes/origin/HEAD"
3015
+ ) {
3016
+ originHeadReads++;
3017
+ if (failFirstOriginHead && originHeadReads === 1) return makeNonRepositoryHandle();
3018
+ }
3019
+ return yield* delegate.spawn(command);
3020
+ }),
3021
+ );
3022
+ const driver = yield* makeGitVcsDriverCore().pipe(
3023
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
3024
+ Effect.provide(layerServerConfig),
3025
+ );
3026
+ const status = yield* driver.statusDetailsRemote(cwd, { refreshUpstream: false });
3027
3028
assert.equal(status.isRepo, true);
3029
assert.equal(status.branch, "feature/remote-status");
3030
+ assert.equal(status.defaultBranch, "trunk");
3031
assert.equal(status.hasUpstream, true);
3032
assert.equal(status.aheadCount, 0);
3033
assert.equal(status.behindCount, 0);
3034
assert.equal(status.aheadOfDefaultCount, 1);
3035
assert.notProperty(status, "workingTree");
3036
assert.notProperty(status, "hasWorkingTreeChanges");
3037
+ assert.equal(originHeadReads, 1);
3038
+
3039
+ // With no main/master fallback, the retry must resolve trunk to preserve the ahead count.
3040
+ originHeadReads = 0;
3041
+ failFirstOriginHead = true;
3042
+ const retried = yield* driver.statusDetailsRemote(cwd, { refreshUpstream: false });
3043
+ assert.deepEqual(retried, { ...status, defaultBranch: null });
3044
+ assert.equal(originHeadReads, 2);
3045
}),
3046
);
3047
apps/server/src/vcs/GitVcsDriverCore.ts
+18
-9
@@ -1701,7 +1701,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1701
const resolveBaseBranchForNoUpstream = Effect.fn("resolveBaseBranchForNoUpstream")(function* (
1702
cwd: string,
1703
refName: string,
1704
- options?: { readonly allowRemoteOfCurrent?: boolean },
1704
+ options?: {
1705
+ readonly allowRemoteOfCurrent?: boolean;
1706
+ readonly knownOriginDefaultBranch?: string | null;
1707
+ },
1708
) {
1709
const configuredBaseRef = yield* readConfigValue(cwd, `branch.${refName}.t3-merge-base-ref`);
1710
if (
@@ -1735,15 +1738,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1738
const primaryRemoteName = yield* resolvePrimaryRemoteName(cwd).pipe(
1739
Effect.orElseSucceed(() => null),
1740
);
1738
- const defaultBranch =
1739
- primaryRemoteName === null ? null : yield* resolveDefaultBranchName(cwd, primaryRemoteName);
1741
const candidates = [
1741
- configuredBaseBranch.length > 0 ? configuredBaseBranch : null,
1742
- defaultBranch,
1743
- ...DEFAULT_BASE_BRANCH_CANDIDATES,
1742
+ Effect.succeed(configuredBaseBranch),
1743
+ primaryRemoteName === null
1744
+ ? Effect.succeed(null)
1745
+ : primaryRemoteName === "origin" && options?.knownOriginDefaultBranch != null
1746
+ ? Effect.succeed(options.knownOriginDefaultBranch)
1747
+ : resolveDefaultBranchName(cwd, primaryRemoteName),
1748
+ ...DEFAULT_BASE_BRANCH_CANDIDATES.map(Effect.succeed),
1749
];
1750
1746
- for (const candidate of candidates) {
1751
+ for (const readCandidate of candidates) {
1752
+ const candidate = yield* readCandidate;
1753
if (!candidate) {
1754
continue;
1755
}
@@ -1804,8 +1810,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1810
const computeAheadCountAgainstBase = Effect.fn("computeAheadCountAgainstBase")(function* (
1811
cwd: string,
1812
refName: string,
1813
+ options?: { readonly knownOriginDefaultBranch: string | null },
1814
) {
1808
- const base = yield* resolveBaseBranchForNoUpstream(cwd, refName);
1815
+ const base = yield* resolveBaseBranchForNoUpstream(cwd, refName, options);
1816
if (!base) {
1817
return 0;
1818
}
@@ -1903,7 +1910,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1910
branch && !isDefaultBranch
1911
? upstreamRef === null
1912
? aheadCount
1906
- : yield* computeAheadCountAgainstBase(cwd, branch).pipe(Effect.orElseSucceed(() => 0))
1913
+ : yield* computeAheadCountAgainstBase(cwd, branch, {
1914
+ knownOriginDefaultBranch: defaultBranch,
1915
+ }).pipe(Effect.orElseSucceed(() => 0))
1916
: 0;
1917
1918
return {