Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions apps/server/src/project/RepositoryIdentityResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
);

it.effect.each(["add", "replace"] as const)(
"refreshes the primary upstream after %s before cache expiry",
"keeps origin as primary when upstream is %s before cache expiry",
(change) =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand All @@ -291,9 +291,7 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {

const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
const initialIdentity = yield* resolver.resolve(cwd);
expect(initialIdentity?.canonicalKey).toBe(
change === "add" ? "github.com/julius/t3code" : "github.com/t3tools/previous",
);
expect(initialIdentity?.canonicalKey).toBe("github.com/julius/t3code");

yield* git(cwd, [
"remote",
Expand All @@ -305,13 +303,35 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
const identity = yield* resolver.resolve(cwd, { refresh: true });

expect(identity).not.toBeNull();
expect(identity?.locator.remoteName).toBe("upstream");
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
expect(identity?.displayName).toBe("t3tools/t3code");
expect(identity?.locator.remoteName).toBe("origin");
expect(identity?.locator.remoteUrl).toBe("git@github.com:julius/t3code.git");
expect(identity?.canonicalKey).toBe("github.com/julius/t3code");
expect(identity?.displayName).toBe("julius/t3code");
expect(yield* resolver.resolve(cwd)).toEqual(identity);
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);

it.effect("falls back to upstream when origin is absent", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const cwd = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-repository-identity-upstream-only-test-",
});

yield* git(cwd, ["init"]);
yield* git(cwd, ["remote", "add", "upstream", "git@github.com:T3Tools/t3code.git"]);

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

expect(identity).not.toBeNull();
expect(identity?.locator.remoteName).toBe("upstream");
expect(identity?.locator.remoteUrl).toBe("git@github.com:T3Tools/t3code.git");
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
expect(identity?.displayName).toBe("t3tools/t3code");
}).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
2 changes: 1 addition & 1 deletion apps/server/src/project/RepositoryIdentityResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> {
function pickPrimaryRemote(
remotes: ReadonlyMap<string, string>,
): { readonly remoteName: string; readonly remoteUrl: string } | null {
for (const preferredRemoteName of ["upstream", "origin"] as const) {
for (const preferredRemoteName of ["origin", "upstream"] as const) {
const remoteUrl = remotes.get(preferredRemoteName);
if (remoteUrl) {
return { remoteName: preferredRemoteName, remoteUrl };
Expand Down
Loading