Skip to content

Commit 2813437

Browse files
fix(server): commit links open any commit the repository has locally
Requiring the commit to be an ancestor of HEAD sent links to commits on other local branches to the browser. Check that the commit object is present instead, still without lazy-fetching it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 130cec6 commit 2813437

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,8 +1546,22 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
15461546
const firstParent = yield* git(cwd, ["rev-parse", "HEAD"]);
15471547
yield* git(cwd, ["merge", "--no-ff", "--no-edit", "feature/side"]);
15481548
const mergeSha = yield* git(cwd, ["rev-parse", "HEAD"]);
1549+
yield* git(cwd, ["checkout", "-b", "feature/elsewhere", initialBranch]);
1550+
yield* writeTextFile(cwd, "elsewhere.txt", "elsewhere\n");
1551+
yield* git(cwd, ["add", "elsewhere.txt"]);
1552+
yield* git(cwd, ["commit", "-m", "elsewhere change"]);
1553+
const elsewhereSha = yield* git(cwd, ["rev-parse", "HEAD"]);
1554+
yield* git(cwd, ["checkout", "feature/merge-preview"]);
15491555
yield* writeTextFile(cwd, "README.md", "# dirty tree\n");
15501556

1557+
const elsewhere = yield* driver.getReviewDiffPreview({ cwd, commitSha: elsewhereSha });
1558+
assert.deepStrictEqual(
1559+
elsewhere.sources
1560+
.find((candidate) => candidate.kind === "commit")
1561+
?.files?.map((file) => file.path),
1562+
["elsewhere.txt"],
1563+
);
1564+
15511565
const preview = yield* driver.getReviewDiffPreview({
15521566
cwd,
15531567
baseRef: initialBranch,

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,13 +3134,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31343134
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(sha)) {
31353135
return yield* reviewCommitError(cwd, "Selected commit is invalid or no longer available.");
31363136
}
3137-
const reachable = yield* executeGit(
3138-
"GitVcsDriver.reviewCommit.reachable",
3137+
const present = yield* executeGit(
3138+
"GitVcsDriver.reviewCommit.present",
31393139
cwd,
3140-
["merge-base", "--is-ancestor", sha, "HEAD"],
3141-
{ allowNonZeroExit: true },
3140+
["cat-file", "-e", `${sha}^{commit}`],
3141+
{ allowNonZeroExit: true, env: { GIT_NO_LAZY_FETCH: "1" } },
31423142
);
3143-
if (reachable.exitCode !== 0) {
3143+
if (present.exitCode !== 0) {
31443144
return yield* reviewCommitError(cwd, "Selected commit is invalid or no longer available.");
31453145
}
31463146
// The raw object keeps the parents a shallow clone grafts away, so a boundary is not a root.

‎docs/user/source-control.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ On web and desktop, open the Diff pane source picker and choose **Commits** to r
1414
commit at a time. The list shows the newest 100 commits in the branch comparison. A merge commit
1515
shows its changes against its first parent.
1616

17-
A commit link from a supported code host opens in the Diff pane when the commit is on the current
18-
thread's checked-out branch. Otherwise a pull request commit link opens the pull request. Other
17+
A commit link from a supported code host opens in the Diff pane when the thread's repository has
18+
that commit locally, on any branch. Otherwise a pull request commit link opens the pull request. Other
1919
commit links follow your **Open links in** setting; on web, when that opens a new tab, T3 Code first
2020
shows an **Open link** button. Command/Ctrl+Click always opens the link in your browser. Commit links follow the **Open pull requests in T3 Code**
2121
setting in **Settings → Diffs**.

0 commit comments

Comments
 (0)