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, 01:45 UTC
fix(server): Changes totals compare the default branch with its tracking upstream (#15393)
Co-authored-by: abderbj <115119179+abderbj@users.noreply.github.com> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
abderrahmen bejaoui committed
Oct 19, 2026 at 20:29 UTC
b8d96370034e89d584f8d20160921644b31e1427
2 files changed
+77
-13
apps/server/src/vcs/GitVcsDriverCore.test.ts
+44
@@ -2593,6 +2593,50 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
2593
}),
2594
);
2595
2596
+ it.effect("Changes compares the default branch with its tracking upstream, not origin", () =>
2597
+ Effect.gen(function* () {
2598
+ // `origin` is a fork whose main is behind; the checkout tracks the
2599
+ // canonical repository through a second remote (#15314).
2600
+ const canonical = yield* makeTmpDir();
2601
+ yield* initRepoWithCommit(canonical);
2602
+ yield* git(canonical, ["branch", "-M", "main"]);
2603
+ const fork = yield* makeTmpDir();
2604
+ yield* git(fork, ["clone", "--quiet", canonical, "."]);
2605
+ yield* writeTextFile(canonical, "canonical.txt", "one\ntwo\nthree\n");
2606
+ yield* git(canonical, ["add", "canonical.txt"]);
2607
+ yield* git(canonical, ["commit", "-m", "canonical moves ahead"]);
2608
+
2609
+ const cwd = yield* makeTmpDir();
2610
+ const driver = yield* GitVcsDriver.GitVcsDriver;
2611
+ yield* git(cwd, ["init", "-b", "main"]);
2612
+ yield* git(cwd, ["remote", "add", "origin", fork]);
2613
+ yield* git(cwd, ["remote", "add", "upstream", canonical]);
2614
+ yield* git(cwd, ["fetch", "--quiet", "--all"]);
2615
+ yield* git(cwd, ["reset", "--hard", "--quiet", "upstream/main"]);
2616
+ yield* git(cwd, ["branch", "--set-upstream-to=upstream/main", "main"]);
2617
+
2618
+ const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
2619
+ assert.deepStrictEqual(status.branchChanges, {
2620
+ baseRef: "upstream/main",
2621
+ insertions: 0,
2622
+ deletions: 0,
2623
+ });
2624
+ const preview = yield* driver.getReviewDiffPreview({ cwd });
2625
+ const changes = preview.sources.find((source) => source.kind === "branch-range")!;
2626
+ assert.strictEqual(changes.baseRef, "upstream/main");
2627
+ assert.deepStrictEqual(changes.files, []);
2628
+
2629
+ // Without an upstream the primary remote's copy stays the base.
2630
+ yield* git(cwd, ["branch", "--unset-upstream", "main"]);
2631
+ const untracked = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
2632
+ assert.deepStrictEqual(untracked.branchChanges, {
2633
+ baseRef: "origin/main",
2634
+ insertions: 3,
2635
+ deletions: 0,
2636
+ });
2637
+ }),
2638
+ );
2639
+
2640
it.effect("reports non-repository directories without failing", () =>
2641
Effect.gen(function* () {
2642
const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+33
-13
@@ -1658,6 +1658,23 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1658
return remoteBase.exitCode === 0 ? { baseRef, comparisonRef } : null;
1659
});
1660
1661
+ // Tracking may point to a different remote than the primary one. Resolve its
1662
+ // full ref so a similarly named local branch or tag cannot shadow it.
1663
+ const resolveTrackedRemoteBaseRef = Effect.fn("resolveTrackedRemoteBaseRef")(function* (
1664
+ cwd: string,
1665
+ refName: string,
1666
+ ) {
1667
+ const upstream = yield* executeGit(
1668
+ "GitVcsDriver.resolveTrackedRemoteBaseRef",
1669
+ cwd,
1670
+ ["rev-parse", "--symbolic-full-name", `${refName}@{upstream}`],
1671
+ { allowNonZeroExit: true },
1672
+ );
1673
+ const comparisonRef = upstream.stdout.trim();
1674
+ if (upstream.exitCode !== 0 || !comparisonRef.startsWith("refs/remotes/")) return null;
1675
+ return { baseRef: comparisonRef.slice("refs/remotes/".length), comparisonRef };
1676
+ });
1677
+
1678
const resolveBaseBranchForNoUpstream = Effect.fn("resolveBaseBranchForNoUpstream")(function* (
1679
cwd: string,
1680
refName: string,
@@ -1701,19 +1718,22 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1718
continue;
1719
}
1720
if (normalizedCandidate === refName) {
1704
- if (
1705
- options?.allowRemoteOfCurrent &&
1706
- primaryRemoteName &&
1707
- (yield* remoteBranchExists({
1708
- cwd,
1709
- remoteName: primaryRemoteName,
1710
- refName: normalizedCandidate,
1711
- }))
1712
- ) {
1713
- return {
1714
- baseRef: `${primaryRemoteName}/${normalizedCandidate}`,
1715
- comparisonRef: `refs/remotes/${primaryRemoteName}/${normalizedCandidate}`,
1716
- };
1721
+ if (options?.allowRemoteOfCurrent) {
1722
+ const trackedRemoteBase = yield* resolveTrackedRemoteBaseRef(cwd, refName);
1723
+ if (trackedRemoteBase !== null) return trackedRemoteBase;
1724
+ if (
1725
+ primaryRemoteName &&
1726
+ (yield* remoteBranchExists({
1727
+ cwd,
1728
+ remoteName: primaryRemoteName,
1729
+ refName: normalizedCandidate,
1730
+ }))
1731
+ ) {
1732
+ return {
1733
+ baseRef: `${primaryRemoteName}/${normalizedCandidate}`,
1734
+ comparisonRef: `refs/remotes/${primaryRemoteName}/${normalizedCandidate}`,
1735
+ };
1736
+ }
1737
}
1738
continue;
1739
}