GeezerVison is showing github.com — fix(server): project identity follows gh repo set-default (#35005) · pingdotgg/t3code@3126806
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/RepositoryIdentityResolver.test.ts +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -303,6 +303,26 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => { | 303 | 303 | }).pipe(Effect.provide(RepositoryIdentityResolver.layer)), | 304 | 304 | ); | 305 | 305 |
| | 306 | + it.effect("uses the fork as the identity when gh repo set-default points at it", () => | | 307 | + Effect.gen(function* () { | | 308 | + const fileSystem = yield* FileSystem.FileSystem; | | 309 | + const cwd = yield* fileSystem.makeTempDirectoryScoped({ | | 310 | + prefix: "t3-repository-identity-gh-default-test-", | | 311 | + }); | | 312 | + | | 313 | + yield* git(cwd, ["init"]); | | 314 | + yield* git(cwd, ["remote", "add", "origin", "[email protected]:julius/t3code-fork.git"]); | | 315 | + yield* git(cwd, ["remote", "add", "upstream", "[email protected]:T3Tools/t3code.git"]); | | 316 | + yield* git(cwd, ["config", "remote.origin.gh-resolved", "base"]); | | 317 | + | | 318 | + const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver; | | 319 | + const identity = yield* resolver.resolve(cwd); | | 320 | + | | 321 | + expect(identity?.canonicalKey).toBe("github.com/julius/t3code-fork"); | | 322 | + expect(identity?.locator.remoteName).toBe("origin"); | | 323 | + }).pipe(Effect.provide(RepositoryIdentityResolver.layer)), | | 324 | + ); | | 325 | + | 306 | 326 | it.effect("uses the last remote path segment as the repository name for nested groups", () => | 307 | 327 | Effect.gen(function* () { | 308 | 328 | const fileSystem = yield* FileSystem.FileSystem; | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/RepositoryIdentityResolver.ts +33-2Lines changed: 33 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,10 +70,21 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> { | 70 | 70 | return remotes; | 71 | 71 | } | 72 | 72 |
| | 73 | +// `gh repo set-default` marks the chosen remote with `remote.<name>.gh-resolved base`. | | 74 | +function parseGhDefaultRemoteName(stdout: string): string | null { | | 75 | + const marked = stdout | | 76 | + .split("\n") | | 77 | + .map((line) => /^remote\.(.+)\.gh-resolved\s+base$/.exec(line.trim())?.[1]) | | 78 | + .filter((name): name is string => name !== undefined); | | 79 | + return marked.length === 1 ? marked[0]! : null; | | 80 | +} | | 81 | + | 73 | 82 | function pickPrimaryRemote( | 74 | 83 | remotes: ReadonlyMap<string, string>, | | 84 | + ghDefaultRemoteName: string | null, | 75 | 85 | ): { readonly remoteName: string; readonly remoteUrl: string } | null { | 76 | | - for (const preferredRemoteName of ["upstream", "origin"] as const) { | | 86 | + for (const preferredRemoteName of [ghDefaultRemoteName, "upstream", "origin"]) { | | 87 | + if (preferredRemoteName === null) continue; | 77 | 88 | const remoteUrl = remotes.get(preferredRemoteName); | 78 | 89 | if (remoteUrl) { | 79 | 90 | return { remoteName: preferredRemoteName, remoteUrl }; | @@ -239,8 +250,28 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn( | 239 | 250 | return null; | 240 | 251 | } | 241 | 252 |
| | 253 | + const ghResolvedResult = yield* processRunner | | 254 | + .run({ | | 255 | + command: "git", | | 256 | + args: [ | | 257 | + "-C", | | 258 | + cacheKey.rootPath, | | 259 | + ...(cacheKey.isBare ? ["--git-dir=."] : []), | | 260 | + "config", | | 261 | + "--get-regexp", | | 262 | + "^remote\\..*\\.gh-resolved$", | | 263 | + ], | | 264 | + env: explicitBareRepositoryEnv(process.env, yield* HostProcess.Platform), | | 265 | + timeoutBehavior: "timedOutResult", | | 266 | + }) | | 267 | + .pipe(Effect.option); | | 268 | + const ghDefaultRemoteName = | | 269 | + ghResolvedResult._tag === "Some" && ghResolvedResult.value.code === 0 | | 270 | + ? parseGhDefaultRemoteName(ghResolvedResult.value.stdout) | | 271 | + : null; | | 272 | + | 242 | 273 | const remotes = parseRemoteFetchUrls(remoteResult.value.stdout); | 243 | | - const remote = pickPrimaryRemote(remotes); | | 274 | + const remote = pickPrimaryRemote(remotes, ghDefaultRemoteName); | 244 | 275 | return remote | 245 | 276 | ? buildRepositoryIdentity({ | 246 | 277 | ...remote, | |
|