@devries-cameron20 / t3code Mirror · read-only / commits / 0bc993ac09
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 21, 18:30 UTC

fix(server): Git status finds the default branch when the only remote isn't origin (#28815)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 12, 2026 at 15:52 UTC 0bc993ac09be75c679c7c3a3c9ddbf9a4024477d
2 files changed +72 -16
apps/server/src/vcs/GitVcsDriverCore.test.ts
+50
@@ -4480,6 +4480,56 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4480 }),
4481 );
4482
4483 + it.effect.each(["checkout", "bare-backed worktree"] as const)(
4484 + "uses the only remote's HEAD for default-branch detection without origin in a %s",
4485 + (layout) =>
4486 + Effect.gen(function* () {
4487 + const driver = yield* GitVcsDriver.GitVcsDriver;
4488 + const path = yield* Path.Path;
4489 + const source = yield* makeTmpDir();
4490 + const remote = yield* makeTmpDir("git-vcs-driver-github-");
4491 + yield* initRepoWithCommit(source);
4492 + yield* git(remote, ["init", "--bare"]);
4493 + yield* git(source, ["branch", "-M", "trunk"]);
4494 + yield* git(source, ["remote", "add", "github", remote]);
4495 + yield* git(source, ["push", "-u", "github", "trunk"]);
4496 + let cwd = source;
4497 + if (layout === "bare-backed worktree") {
4498 + const container = yield* makeTmpDir("git-vcs-driver-bare-");
4499 + const gitDirArgs = ["--git-dir", path.join(container, "repo.git")];
4500 + cwd = path.join(container, "trunk");
4501 + yield* git(container, ["init", "--bare", "repo.git"]);
4502 + yield* git(container, [...gitDirArgs, "config", "user.email", "test@test.com"]);
4503 + yield* git(container, [...gitDirArgs, "config", "user.name", "Test"]);
4504 + yield* git(container, [...gitDirArgs, "remote", "add", "github", remote]);
4505 + yield* git(container, [...gitDirArgs, "fetch", "github"]);
4506 + yield* git(container, [
4507 + ...gitDirArgs,
4508 + "worktree",
4509 + "add",
4510 + "--track",
4511 + "-b",
4512 + "trunk",
4513 + cwd,
4514 + "github/trunk",
4515 + ]);
4516 + }
4517 + yield* git(cwd, [
4518 + "symbolic-ref",
4519 + "refs/remotes/github/HEAD",
4520 + "refs/remotes/github/trunk",
4521 + ]);
4522 +
4523 + assert.isTrue((yield* driver.statusDetailsLocal(cwd)).isDefaultBranch);
4524 + const remoteStatus = yield* driver.statusDetailsRemote(cwd);
4525 + assert.equal(remoteStatus.defaultBranch, "trunk");
4526 + assert.isTrue(remoteStatus.isDefaultBranch);
4527 +
4528 + yield* git(cwd, ["remote", "add", "origin", remote]);
4529 + assert.isNull((yield* driver.statusDetailsRemote(cwd)).defaultBranch);
4530 + }),
4531 + );
4532 +
4533 it.effect("makes background upstream status fetches non-interactive", () =>
4534 Effect.gen(function* () {
4535 const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+22 -16
@@ -1580,17 +1580,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1580 const path = yield* Path.Path;
1581 const fetchCwd =
1582 path.basename(gitCommonDir) === ".git" ? path.dirname(gitCommonDir) : gitCommonDir;
1583 - return yield* executeGit(
1584 - "GitVcsDriver.statusDetails.defaultBranch",
1585 - fetchCwd,
1586 - ["--git-dir", gitCommonDir, "symbolic-ref", "refs/remotes/origin/HEAD"],
1587 - { allowNonZeroExit: true },
1588 - ).pipe(
1589 - Effect.map((result) => {
1590 - if (result.exitCode !== 0) return null;
1591 - return parseDefaultBranchFromRemoteHeadRef(result.stdout, "origin");
1592 - }),
1593 - );
1583 + return yield* resolvePrimaryDefaultBranchName(fetchCwd, ["--git-dir", gitCommonDir]);
1584 }),
1585 {
1586 capacity: 2_048,
@@ -1726,11 +1716,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1716 const resolveDefaultBranchName = (
1717 cwd: string,
1718 remoteName: string,
1719 + gitDirArgs: ReadonlyArray<string> = [],
1720 ): Effect.Effect<string | null, GitCommandError> =>
1721 executeGit(
1722 "GitVcsDriver.resolveDefaultBranchName",
1723 cwd,
1733 - ["symbolic-ref", `refs/remotes/${remoteName}/HEAD`],
1724 + [...gitDirArgs, "symbolic-ref", `refs/remotes/${remoteName}/HEAD`],
1725 { allowNonZeroExit: true },
1726 ).pipe(
1727 Effect.map((result) => {
@@ -1764,8 +1755,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1755 const originRemoteExists = (cwd: string): Effect.Effect<boolean, GitCommandError> =>
1756 remoteExists({ cwd, remoteName: "origin" });
1757
1767 - const listRemoteNames = (cwd: string): Effect.Effect<ReadonlyArray<string>, GitCommandError> =>
1768 - runGitStdout("GitVcsDriver.listRemoteNames", cwd, ["remote"]).pipe(
1758 + const listRemoteNames = (
1759 + cwd: string,
1760 + gitDirArgs: ReadonlyArray<string> = [],
1761 + ): Effect.Effect<ReadonlyArray<string>, GitCommandError> =>
1762 + runGitStdout("GitVcsDriver.listRemoteNames", cwd, [...gitDirArgs, "remote"]).pipe(
1763 Effect.map(parseRemoteNamesInGitOrder),
1764 );
1765
@@ -1788,6 +1782,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1782 return firstRemote ?? null;
1783 });
1784
1785 + const resolvePrimaryDefaultBranchName = Effect.fn("GitVcsDriver.resolvePrimaryDefaultBranchName")(
1786 + function* (cwd: string, gitDirArgs: ReadonlyArray<string> = []) {
1787 + const originDefault = yield* resolveDefaultBranchName(cwd, "origin", gitDirArgs);
1788 + if (originDefault !== null) return originDefault;
1789 + const remoteNames = yield* listRemoteNames(cwd, gitDirArgs);
1790 + const [firstRemote] = remoteNames;
1791 + return firstRemote === undefined || remoteNames.includes("origin")
1792 + ? null
1793 + : yield* resolveDefaultBranchName(cwd, firstRemote, gitDirArgs);
1794 + },
1795 + );
1796 +
1797 const resolvePrimaryRemoteName = (cwd: string) =>
1798 findPrimaryRemoteName(cwd).pipe(
1799 Effect.filterOrFail(
@@ -2123,7 +2129,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2129 );
2130 }
2131
2126 - const defaultBranch = yield* resolveDefaultBranchName(cwd, "origin");
2132 + const defaultBranch = yield* resolvePrimaryDefaultBranchName(cwd);
2133 const isDefaultBranch =
2134 branch !== null &&
2135 (branch === defaultBranch ||
@@ -2269,7 +2275,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2275 ),
2276 statusCacheKey
2277 ? Cache.get(defaultBranchCache, statusCacheKey).pipe(Effect.orElseSucceed(() => null))
2272 - : resolveDefaultBranchName(cwd, "origin").pipe(Effect.orElseSucceed(() => null)),
2278 + : resolvePrimaryDefaultBranchName(cwd).pipe(Effect.orElseSucceed(() => null)),
2279 statusCacheKey
2280 ? Cache.get(primaryRemoteExistsCache, statusCacheKey).pipe(
2281 Effect.orElseSucceed(() => false),