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
17 changes: 16 additions & 1 deletion src/signal/origin/remote.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { expect, test } from "bun:test";
import { normalizeRemoteOrigin, normalizeRemoteRepository } from "./remote";
import os from "node:os";
import path from "node:path";
import {
normalizeRemoteOrigin,
normalizeRemoteRepository,
readGitRemote,
} from "./remote";

test("a missing working directory has no Git remote", async () => {
const missingDirectory = path.join(
os.tmpdir(),
`shadowclone-missing-${crypto.randomUUID()}`,
);

expect(await readGitRemote(missingDirectory)).toBeNull();
});

test("nested namespaces stay distinct owners", () => {
const first = normalizeRemoteOrigin("https://gitlab.com/group/alpha/service");
Expand Down
30 changes: 17 additions & 13 deletions src/signal/origin/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,24 @@ export function normalizeRemoteRepository(
}

export async function readGitRemote(cwd: string): Promise<string | null> {
const { exitCode, stdout } = await runHostCommand({
arguments: [
"git",
"-C",
try {
const { exitCode, stdout } = await runHostCommand({
arguments: [
"git",
"-C",
cwd,
"config",
"--local",
"--get",
"remote.origin.url",
],
cwd,
"config",
"--local",
"--get",
"remote.origin.url",
],
cwd,
});
const value = stdout.trim();
return exitCode === 0 && value.length > 0 ? value : null;
});
const value = stdout.trim();
return exitCode === 0 && value.length > 0 ? value : null;
} catch {
return null;
}
}

export function originDirectoryName(id: string): string {
Expand Down