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, 13:15 UTC
fix(server): a branch named like a tag no longer reads as heads/<name> (#24258)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
MarcoDotIO committed
Oct 29, 2026 at 13:50 UTC
849d2b5ac8fc9b1a891f0115f030c73d672ec646
2 files changed
+35
-13
apps/server/src/vcs/GitVcsDriverCore.test.ts
+17
@@ -404,6 +404,7 @@ describe("pullCurrentBranch", () => {
404
const driver = yield* GitVcsDriver.GitVcsDriver;
405
const fs = yield* FileSystem.FileSystem;
406
const { cwd, updater, initialBranch, remoteHead } = yield* cloneBehindRemote;
407
+ yield* git(cwd, ["tag", initialBranch]);
408
yield* git(updater, ["push", "origin", "HEAD:refs/heads/other"]);
409
const remoteName = customMapping ? "team/upstream" : "origin";
410
const refPrefix = customMapping
@@ -2279,6 +2280,22 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
2280
});
2281
2282
describe("repository status", () => {
2283
+ it.effect("reads the current branch by name when a tag shares it", () =>
2284
+ Effect.gen(function* () {
2285
+ const cwd = yield* makeTmpDir();
2286
+ yield* initRepoWithCommit(cwd);
2287
+ yield* git(cwd, ["checkout", "-b", "release"]);
2288
+ yield* git(cwd, ["tag", "release"]);
2289
+ const driver = yield* GitVcsDriver.GitVcsDriver;
2290
+
2291
+ const remoteStatus = yield* driver.statusDetailsRemote(cwd, { refreshUpstream: false });
2292
+ assert.equal(remoteStatus.branch, "release");
2293
+ const preview = yield* driver.getReviewDiffPreview({ cwd });
2294
+ const branchRange = preview.sources.find((source) => source.kind === "branch-range");
2295
+ assert.equal(branchRange?.headRef, "release");
2296
+ }),
2297
+ );
2298
+
2299
it.effect("does not open a project folder laid out as a bare repository", () =>
2300
Effect.gen(function* () {
2301
const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+18
-13
@@ -514,6 +514,15 @@ function classifyGitFailure(stderr: string): GitCommandFailureReason | null {
514
return null;
515
}
516
517
+// `--short` and `--abbrev-ref` print `heads/<name>` when a tag shares the branch's name, so
518
+// branch reads take the full ref and strip the prefix themselves.
519
+function branchNameFromHeadRef(value: string): string | null {
520
+ const ref = value.trim();
521
+ return ref.startsWith("refs/heads/") && ref.length > "refs/heads/".length
522
+ ? ref.slice("refs/heads/".length)
523
+ : null;
524
+}
525
+
526
function parseDefaultBranchFromRemoteHeadRef(value: string, remoteName: string): string | null {
527
const trimmed = value.trim();
528
const prefix = `refs/remotes/${remoteName}/`;
@@ -1412,7 +1421,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1421
executeGit(
1422
"GitVcsDriver.resolveRepositoryPaths.currentBranch",
1423
cwd,
1415
- ["symbolic-ref", "--quiet", "--short", "HEAD"],
1424
+ ["symbolic-ref", "--quiet", "HEAD"],
1425
{
1426
timeoutMs: 5_000,
1427
allowNonZeroExit: true,
@@ -1443,11 +1452,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1452
Effect.map((physicalCwd) => path.relative(worktreeRoot, physicalCwd) === ""),
1453
Effect.orElseSucceed(() => undefined),
1454
);
1446
- const currentBranchOutput = currentBranchResult.stdout.trim();
1455
const currentBranch =
1448
- currentBranchResult.exitCode === 0 && currentBranchOutput.length > 0
1449
- ? currentBranchOutput
1450
- : null;
1456
+ currentBranchResult.exitCode === 0 ? branchNameFromHeadRef(currentBranchResult.stdout) : null;
1457
1458
return {
1459
gitCommonDir,
@@ -1938,7 +1944,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1944
const branchResult = yield* executeGitWithStableDiagnostics(
1945
"GitVcsDriver.statusDetailsRemote.branch",
1946
cwd,
1941
- ["rev-parse", "--abbrev-ref", "HEAD"],
1947
+ ["rev-parse", "--symbolic-full-name", "HEAD"],
1948
{ allowNonZeroExit: true },
1949
).pipe(
1950
Effect.catchTags({
@@ -1960,7 +1966,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1966
...gitCommandContext({
1967
operation: "GitVcsDriver.statusDetailsRemote.branch",
1968
cwd,
1963
- args: ["rev-parse", "--abbrev-ref", "HEAD"],
1969
+ args: ["rev-parse", "--symbolic-full-name", "HEAD"],
1970
}),
1971
detail: "Git branch lookup failed.",
1972
exitCode: branchResult.exitCode,
@@ -1972,12 +1978,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1978
const branchValue = yield* runGitStdout(
1979
"GitVcsDriver.statusDetailsRemote.unbornBranch",
1980
cwd,
1975
- ["symbolic-ref", "--quiet", "--short", "HEAD"],
1981
+ ["symbolic-ref", "--quiet", "HEAD"],
1982
);
1977
- branch = branchValue.trim() || null;
1983
+ branch = branchNameFromHeadRef(branchValue);
1984
} else {
1979
- const branchValue = branchResult.stdout.trim();
1980
- branch = branchValue.length > 0 && branchValue !== "HEAD" ? branchValue : null;
1985
+ branch = branchNameFromHeadRef(branchResult.stdout);
1986
}
1987
const currentUpstreamRef = yield* readCurrentUpstreamRef(cwd);
1988
let upstreamRef =
@@ -2781,9 +2786,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2786
runGitStdout(
2787
"GitVcsDriver.pullCurrentBranch.currentBranch",
2788
cwd,
2784
- ["symbolic-ref", "--quiet", "--short", "HEAD"],
2789
+ ["symbolic-ref", "--quiet", "HEAD"],
2790
true,
2786
- ).pipe(Effect.map((stdout) => stdout.trim())),
2791
+ ).pipe(Effect.map(branchNameFromHeadRef)),
2792
runGitStdout("GitVcsDriver.pullCurrentBranch.currentSha", cwd, ["rev-parse", "HEAD"]).pipe(
2793
Effect.map((stdout) => stdout.trim()),
2794
),