Skip to content

Commit 66de31a

Browse files
Merge branch 'main' into fix/git-status-numstat-merge
2 parents c366f65 + d19039a commit 66de31a

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎apps/server/src/vcs/VcsDriverRegistry.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,49 @@ describe("VcsDriverRegistry", () => {
9292
);
9393
}).pipe(Effect.provide(layer));
9494
});
95+
96+
it.effect("detects a repository created after a negative lookup", () => {
97+
let insideWorkTreeChecks = 0;
98+
const layer = Layer.effect(VcsDriverRegistry.VcsDriverRegistry, VcsDriverRegistry.make).pipe(
99+
Layer.provide(NodeServices.layer),
100+
Layer.provide(
101+
Layer.mock(VcsProjectConfig.VcsProjectConfig)({
102+
resolveKind: (input) => Effect.succeed(input.requestedKind ?? "auto"),
103+
}),
104+
),
105+
Layer.provide(
106+
Layer.mock(VcsProcess.VcsProcess)({
107+
run: (input) =>
108+
Effect.sync(() => {
109+
const command = normalizeGitArgs(input.args).join(" ");
110+
if (command === "rev-parse --is-inside-work-tree") {
111+
insideWorkTreeChecks += 1;
112+
return insideWorkTreeChecks === 1
113+
? {
114+
...processOutput(""),
115+
exitCode: ChildProcessSpawner.ExitCode(128),
116+
stderr: "fatal: not a git repository",
117+
}
118+
: processOutput("true\n");
119+
}
120+
if (command === "rev-parse --show-toplevel") {
121+
return processOutput("/repo\n");
122+
}
123+
if (command === "rev-parse --git-common-dir") {
124+
return processOutput("/repo/.git\n");
125+
}
126+
return processOutput("");
127+
}),
128+
}),
129+
),
130+
);
131+
132+
return Effect.gen(function* () {
133+
const registry = yield* VcsDriverRegistry.VcsDriverRegistry;
134+
135+
assert.equal(yield* registry.detect({ cwd: "/repo" }), null);
136+
assert.equal((yield* registry.detect({ cwd: "/repo" }))?.repository.rootPath, "/repo");
137+
assert.equal(insideWorkTreeChecks, 2);
138+
}).pipe(Effect.provide(layer));
139+
});
95140
});

‎apps/server/src/vcs/VcsDriverRegistry.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ export const make = Effect.gen(function* () {
115115
(key) => detectResolvedKind(parseDetectionCacheKey(key)),
116116
{
117117
capacity: DETECTION_CACHE_CAPACITY,
118-
timeToLive: (exit) => (Exit.isSuccess(exit) ? DETECTION_CACHE_TTL : Duration.zero),
118+
timeToLive: Exit.match({
119+
onSuccess: (detected) => (detected === null ? Duration.zero : DETECTION_CACHE_TTL),
120+
onFailure: () => Duration.zero,
121+
}),
119122
},
120123
);
121124

0 commit comments

Comments
 (0)