GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): repository identity prefers the gh default remote by donnes · Pull Request #14291 · pingdotgg/t3code

fix(server): repository identity prefers the gh default remote #14291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
donnes wants to merge 3 commits into pingdotgg:main from codemode-studio:fix/gh-default-remote-identity

Uh oh!

There was an error while loading. Please reload this page.

Closed

fix(server): repository identity prefers the gh default remote #14291

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
5e36fbe
fix(server): repository identity prefers the gh default remote
donnes Sep 29, 2026
ad658d8
chore(server): trim resolver comments
donnes Sep 29, 2026
bcf9123
fix(server): resolve gh OWNER/REPO default repositories
donnes Sep 29, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

51 changes: 50 additions & 1 deletion 51 apps/server/src/project/RepositoryIdentityResolver.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
expect(calls).toEqual([
["-C", "/repo/packages/web", "rev-parse", "--show-toplevel"],
["-C", "/repo", "remote", "-v"],
["-C", "/repo", "config", "--get-regexp", "^remote\\..*\\.gh-resolved$"],
]);

const refreshed = yield* resolver.resolve("/repo/packages/web", { refresh: true });
expect(refreshed?.rootPath).toBe("/repo/packages/web");
expect(yield* resolver.resolve("/repo/packages/web")).toEqual(refreshed);
expect(calls.slice(2)).toEqual([
expect(calls.slice(3)).toEqual([
["-C", "/repo/packages/web", "rev-parse", "--show-toplevel"],
["-C", "/repo/packages/web", "remote", "-v"],
["-C", "/repo/packages/web", "config", "--get-regexp", "^remote\\..*\\.gh-resolved$"],
]);
remoteUrl = "[email protected]:team/repo.git";
const forgejo = yield* resolver.resolve(rootPath, { refresh: true });
Expand Down Expand Up @@ -170,6 +172,7 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
["-C", "/repo/packages/web", "rev-parse", "--show-toplevel"],
["-C", "/repo/packages/web", "rev-parse", "--show-toplevel"],
["-C", "/repo", "remote", "-v"],
["-C", "/repo", "config", "--get-regexp", "^remote\\..*\\.gh-resolved$"],
]);
}).pipe(Effect.provide(Layer.merge(TestClock.layer(), resolverLayer)));
});
Expand Down Expand Up @@ -288,6 +291,52 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);

it.effect("prefers the remote gh marked as the default repository", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const cwd = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-repository-identity-gh-default-test-",
});

yield* git(cwd, ["init"]);
yield* git(cwd, ["remote", "add", "origin", "[email protected]:julius/t3code.git"]);
yield* git(cwd, ["remote", "add", "upstream", "[email protected]:T3Tools/t3code.git"]);

const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
expect((yield* resolver.resolve(cwd))?.locator.remoteName).toBe("upstream");

yield* git(cwd, ["config", "remote.origin.gh-resolved", "base"]);
const identity = yield* resolver.resolve(cwd, { refresh: true });

expect(identity?.locator.remoteName).toBe("origin");
expect(identity?.canonicalKey).toBe("github.com/julius/t3code");
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);

it.effect("resolves a gh default parent repository that has no remote", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const cwd = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-repository-identity-gh-parent-test-",
});

yield* git(cwd, ["init"]);
yield* git(cwd, ["remote", "add", "origin", "[email protected]:julius/t3code.git"]);
yield* git(cwd, ["config", "remote.origin.gh-resolved", "T3Tools/t3code"]);

const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
const identity = yield* resolver.resolve(cwd);

expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
expect(identity?.owner).toBe("t3tools");
expect(identity?.locator).toEqual({
source: "git-remote",
remoteName: "origin",
remoteUrl: "[email protected]:T3Tools/t3code.git",
});
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);

it.effect("uses the last remote path segment as the repository name for nested groups", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand Down
53 changes: 45 additions & 8 deletions 53 apps/server/src/project/RepositoryIdentityResolver.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,41 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> {
return remotes;
}

interface GhDefaultRemote {
readonly remoteName: string;
readonly resolution: string;
}

// `gh repo set-default` marks one remote with `remote.<name>.gh-resolved`: `base`
// for that remote's own repo, or `OWNER/REPO` for a parent repo with no remote.
function parseGhDefaultRemote(stdout: string): GhDefaultRemote | null {
for (const line of stdout.split("\n")) {
const match = /^remote\.(.+)\.gh-resolved\s+(\S+)$/.exec(line.trim());
const [, remoteName, resolution] = match ?? [];
if (remoteName && resolution) return { remoteName, resolution };
}
return null;
}

function withRepositoryPath(remoteUrl: string, repository: string): string | null {
if (!/^[^/\s]+\/[^/\s]+$/.test(repository)) return null;
const match = /^(.*[/:])[^/:]+\/[^/]+?(\.git)?\/?$/.exec(remoteUrl);
return match ? `${match[1]}${repository}${match[2] ?? ""}` : null;
}

function pickPrimaryRemote(
remotes: ReadonlyMap<string, string>,
ghDefault: GhDefaultRemote | null,
): { readonly remoteName: string; readonly remoteUrl: string } | null {
const ghRemoteUrl = ghDefault ? remotes.get(ghDefault.remoteName) : undefined;
if (ghDefault && ghRemoteUrl) {
const remoteUrl =
ghDefault.resolution === "base"
? ghRemoteUrl
: withRepositoryPath(ghRemoteUrl, ghDefault.resolution);
if (remoteUrl) return { remoteName: ghDefault.remoteName, remoteUrl };
}

for (const preferredRemoteName of ["upstream", "origin"] as const) {
const remoteUrl = remotes.get(preferredRemoteName);
if (remoteUrl) {
Expand Down Expand Up @@ -125,18 +157,23 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
cacheKey: string,
): Effect.fn.Return<RepositoryIdentity | null, never, ProcessRunner.ProcessRunner> {
const processRunner = yield* ProcessRunner.ProcessRunner;
const remoteResult = yield* processRunner
.run({
command: "git",
args: ["-C", cacheKey, "remote", "-v"],
timeoutBehavior: "timedOutResult",
})
.pipe(Effect.option);
const git = (args: ReadonlyArray<string>) =>
processRunner
.run({ command: "git", args: ["-C", cacheKey, ...args], timeoutBehavior: "timedOutResult" })
.pipe(Effect.option);
const [remoteResult, ghDefaultResult] = yield* Effect.all(
[git(["remote", "-v"]), git(["config", "--get-regexp", "^remote\\..*\\.gh-resolved$"])],
{ concurrency: "unbounded" },
);
if (remoteResult._tag === "None" || remoteResult.value.code !== 0) {
return null;
}

const remote = pickPrimaryRemote(parseRemoteFetchUrls(remoteResult.value.stdout));
const ghDefault =
ghDefaultResult._tag === "Some" && ghDefaultResult.value.code === 0
? parseGhDefaultRemote(ghDefaultResult.value.stdout)
: null;
const remote = pickPrimaryRemote(parseRemoteFetchUrls(remoteResult.value.stdout), ghDefault);
return remote ? buildRepositoryIdentity({ ...remote, rootPath: cacheKey }) : null;
});

Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.