TypeScript
fix(server): recognize partial-clone remote annotations (#16316)
Maxwell Younga195ba0809b5
diff --git a/apps/server/src/project/RepositoryIdentityResolver.test.ts b/apps/server/src/project/RepositoryIdentityResolver.test.tsindex 5f4e60f0130..6893b360c9f 100644--- a/apps/server/src/project/RepositoryIdentityResolver.test.ts+++ b/apps/server/src/project/RepositoryIdentityResolver.test.ts@@ -203,6 +203,30 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),);+ it.effect("resolves the fetch remote of a partial clone", () =>+ Effect.gen(function* () {+ const fileSystem = yield* FileSystem.FileSystem;+ const cwd = yield* fileSystem.makeTempDirectoryScoped({+ prefix: "t3-repository-identity-partial-clone-test-",+ });++ yield* git(cwd, ["init"]);+ yield* git(cwd, ["remote", "add", "origin", "[email protected]:T3Tools/t3code.git"]);+ yield* git(cwd, ["remote", "set-url", "--push", "origin", "[email protected]:T3Tools/push.git"]);+ yield* git(cwd, ["config", "remote.origin.promisor", "true"]);+ yield* git(cwd, ["config", "remote.origin.partialclonefilter", "blob:none"]);++ const remotes = yield* git(cwd, ["remote", "-v"]);+ expect(remotes.stdout).toContain("(fetch) [blob:none]");++ const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;+ const identity = yield* resolver.resolve(cwd);+ expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");+ expect(identity?.locator.remoteUrl).toBe("[email protected]:T3Tools/t3code.git");+ expect(identity?.locator.remoteName).toBe("origin");+ }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),+ );+it.effect("returns the git top-level root path when resolving from a nested workspace", () =>Effect.gen(function* () {const fileSystem = yield* FileSystem.FileSystem;diff --git a/apps/server/src/project/RepositoryIdentityResolver.ts b/apps/server/src/project/RepositoryIdentityResolver.tsindex 80d5b39823a..8447509b954 100644--- a/apps/server/src/project/RepositoryIdentityResolver.ts+++ b/apps/server/src/project/RepositoryIdentityResolver.ts@@ -58,7 +58,8 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> {for (const line of stdout.split("\n")) {const trimmed = line.trim();if (trimmed.length === 0) continue;- const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)$/.exec(trimmed);+ // Partial clones append the promisor filter, e.g. `(fetch) [blob:none]`.+ const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)(?:\s+\[[^\]]+\])?$/.exec(trimmed);if (!match) continue;const [, remoteName = "", remoteUrl = "", direction = ""] = match;if (diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.tsindex 83587e65134..9ac83d1dd9d 100644--- a/apps/server/src/vcs/GitVcsDriver.test.ts+++ b/apps/server/src/vcs/GitVcsDriver.test.ts@@ -9,6 +9,7 @@ import * as Fiber from "effect/Fiber";import * as TestClock from "effect/testing/TestClock";import * as FileSystem from "effect/FileSystem";import * as Layer from "effect/Layer";+import * as Option from "effect/Option";import * as Path from "effect/Path";import * as PlatformError from "effect/PlatformError";import { ChildProcessSpawner } from "effect/process";@@ -97,6 +98,37 @@ runVcsDriverContractSuite<GitVcsDriver.GitVcsDriver, GitContractError>({},});+it.effect("lists the fetch and push URLs of a partial clone remote", () =>+ Effect.gen(function* () {+ const fileSystem = yield* FileSystem.FileSystem;+ const cwd = yield* fileSystem.makeTempDirectoryScoped({+ prefix: "t3-partial-clone-remotes-",+ });+ const driver = yield* GitVcsDriver.makeVcsDriverShape();+ yield* runGit(cwd, ["init"]);+ yield* runGit(cwd, ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"]);+ yield* runGit(cwd, [+ "remote",+ "set-url",+ "--push",+ "origin",+ "[email protected]:octocat/t3code.git",+ ]);+ yield* runGit(cwd, ["config", "remote.origin.promisor", "true"]);+ yield* runGit(cwd, ["config", "remote.origin.partialclonefilter", "blob:none"]);++ const result = yield* driver.listRemotes(cwd);+ assert.deepEqual(result.remotes, [+ {+ name: "origin",+ url: "https://github.com/pingdotgg/t3code.git",+ pushUrl: Option.some("[email protected]:octocat/t3code.git"),+ isPrimary: true,+ },+ ]);+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),+);+const makeCheckpointFixture = Effect.fn("makeCheckpointFixture")(function* (driver: Effect.Success<ReturnType<typeof GitVcsDriver.makeVcsDriverShape>>,cwd: string,diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.tsindex f08e250d58d..8a780150f63 100644--- a/apps/server/src/vcs/GitVcsDriver.ts+++ b/apps/server/src/vcs/GitVcsDriver.ts@@ -466,7 +466,8 @@ function parseGitRemoteVerboseOutput(continue;}- const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)$/.exec(trimmed);+ // Partial clones append the promisor filter, e.g. `(fetch) [blob:none]`.+ const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)(?:\s+\[[^\]]+\])?$/.exec(trimmed);if (!match) {continue;}diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.tsindex 75d5335f1b7..85670aa7ffb 100644--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts@@ -4054,6 +4054,30 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {});describe("remote operations", () => {+ it.effect("ensureRemote reuses a partial clone remote and avoids its name", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTmpDir();+ yield* git(cwd, ["init"]);+ yield* git(cwd, ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"]);+ yield* git(cwd, ["config", "remote.origin.promisor", "true"]);+ yield* git(cwd, ["config", "remote.origin.partialclonefilter", "blob:none"]);+ const driver = yield* GitVcsDriver.GitVcsDriver;++ const reused = yield* driver.ensureRemote({+ cwd,+ preferredName: "origin",+ url: "[email protected]:pingdotgg/t3code.git",+ });+ assert.equal(reused, "origin");+ const added = yield* driver.ensureRemote({+ cwd,+ preferredName: "origin",+ url: "https://github.com/another-owner/t3code.git",+ });+ assert.equal(added, "origin-1");+ }),+ );+it.effect("explains a real fetch failure for a missing local remote", () =>Effect.gen(function* () {const cwd = yield* makeTmpDir();diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.tsindex 754dd535a82..219467c2953 100644--- a/apps/server/src/vcs/GitVcsDriverCore.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.ts@@ -334,7 +334,8 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> {for (const line of stdout.split("\n")) {const trimmed = line.trim();if (trimmed.length === 0) continue;- const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)$/.exec(trimmed);+ // Partial clones append the promisor filter, e.g. `(fetch) [blob:none]`.+ const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)(?:\s+\[[^\]]+\])?$/.exec(trimmed);if (!match) continue;const [, remoteName = "", remoteUrl = "", direction = ""] = match;if (direction !== "fetch" || remoteName.length === 0 || remoteUrl.length === 0) {diff --git a/packages/source-control-forgejo/src/server/ForgejoCli.ts b/packages/source-control-forgejo/src/server/ForgejoCli.tsindex 81e96f61fa9..2df2a8ab5b4 100644--- a/packages/source-control-forgejo/src/server/ForgejoCli.ts+++ b/packages/source-control-forgejo/src/server/ForgejoCli.ts@@ -515,7 +515,10 @@ export const make = Effect.gen(function* () {const matchingUrls = [...new Set(result.stdout.split("\n").flatMap((line) => {- const url = /^\S+\s+(https?:\/\/\S+)\s+\(fetch\)$/.exec(line.trim())?.[1];+ // Partial clones append the promisor filter, e.g. `(fetch) [blob:none]`.+ const url = /^\S+\s+(https?:\/\/\S+)\s+\(fetch\)(?:\s+\[[^\]]+\])?$/.exec(+ line.trim(),+ )?.[1];return url && parseForgejoRemote(url)?.host === input.host?.toLowerCase()? [url]: [];diff --git a/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts b/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.tsindex 354edbb981e..a6a453c3f32 100644--- a/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts+++ b/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts@@ -1046,7 +1046,9 @@ it.effect("prefers fj for HTTP and ported SSH aliases on root servers", () => {input.cwd === "/no-remotes"? processOutput("", { exitCode: ChildProcessSpawner.ExitCode(2) }): processOutput(- `${input.cwd === "/upstream-only" ? "upstream" : "origin"}\thttp://forgejo.local:3000/maria/project.git (fetch)\nother\thttp://forgejo.local:3000/maria/other.git (fetch)\nunrelated\thttp://other.local:3000/maria/project.git (fetch)`,+ input.cwd === "/upstream-only"+ ? "upstream\thttp://forgejo.local:3000/maria/project.git (fetch) [blob:none]\nother\thttp://forgejo.local:3000/maria/other.git (fetch) [blob:none]\nunrelated\thttp://other.local:3000/maria/project.git (fetch) [blob:none]"+ : "origin\thttp://forgejo.local:3000/maria/project.git (fetch)\nother\thttp://forgejo.local:3000/maria/other.git (fetch)\nunrelated\thttp://other.local:3000/maria/project.git (fetch)",),);assert.strictEqual(input.command, "fj");diff --git a/packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts b/packages/source-control-github/src/server/gitHubRepositoryResolution.test.tsindex 7c6f754192b..c78c1fd7612 100644--- a/packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts+++ b/packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts@@ -31,6 +31,11 @@ describe("selectGitHubBaseRepository", () => {select({ remotes: fork, resolved: "remote.origin.gh-resolved acme/other" }),{ owner: "acme", name: "other" },);+ const partialClone = fork.replaceAll("(fetch)", "(fetch) [blob:none]");+ assert.deepStrictEqual(+ select({ remotes: partialClone, resolved: "remote.origin.gh-resolved base" }),+ { owner: "me", name: "web" },+ );assert.deepStrictEqual(select({remotes: remotes(diff --git a/packages/source-control-github/src/server/gitHubRepositoryResolution.ts b/packages/source-control-github/src/server/gitHubRepositoryResolution.tsindex bd36758605e..d9e2e9743e1 100644--- a/packages/source-control-github/src/server/gitHubRepositoryResolution.ts+++ b/packages/source-control-github/src/server/gitHubRepositoryResolution.ts@@ -13,9 +13,10 @@ export interface GitHubRepositoryLocator {export function parseFetchRemotes(remotes: string,): ReadonlyArray<{ readonly name: string; readonly url: string }> {+ // Partial clones append the promisor filter, e.g. `(fetch) [blob:none]`.return remotes.split("\n")- .map((line) => /^(\S+)\s+(\S+)\s+\(fetch\)$/u.exec(line.trim()))+ .map((line) => /^(\S+)\s+(\S+)\s+\(fetch\)(?:\s+\[[^\]]+\])?$/u.exec(line.trim())).filter((match): match is RegExpExecArray => match !== null).map((match) => ({ name: match[1]!, url: match[2]! }));}