diff --git a/src/signal/origin/remote.test.ts b/src/signal/origin/remote.test.ts index 1cdeb16..530709e 100644 --- a/src/signal/origin/remote.test.ts +++ b/src/signal/origin/remote.test.ts @@ -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"); diff --git a/src/signal/origin/remote.ts b/src/signal/origin/remote.ts index a66ff6f..8045a31 100644 --- a/src/signal/origin/remote.ts +++ b/src/signal/origin/remote.ts @@ -145,20 +145,24 @@ export function normalizeRemoteRepository( } export async function readGitRemote(cwd: string): Promise { - 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 {