Skip to content

Commit bfbed21

Browse files
fix(shell): wrap git fs adapter unlink with fsError for proper ENOENT code (#1249)
1 parent 1933eb4 commit bfbed21

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/shell": patch
3+
---
4+
5+
Fix `git.clone()` without `depth` failing with `ENOENT: .git/shallow`. The git fs adapter's `unlink` now wraps errors with `.code` so isomorphic-git can handle missing files gracefully.

packages/shell/src/git/fs-adapter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ export function createGitFs(fs: FileSystem) {
119119
},
120120

121121
async unlink(path: string): Promise<void> {
122-
await fs.rm(path);
122+
try {
123+
await fs.rm(path);
124+
} catch (err) {
125+
throw fsError(path, err);
126+
}
123127
},
124128

125129
async readdir(path: string): Promise<string[]> {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Unit tests for the git fs adapter (createGitFs).
3+
*
4+
* Uses InMemoryFs so these run without a Durable Object or network access.
5+
*/
6+
7+
import { describe, expect, it } from "vitest";
8+
import { InMemoryFs } from "../fs/in-memory-fs";
9+
import { createGitFs } from "../git/fs-adapter";
10+
11+
function setup() {
12+
const fs = new InMemoryFs();
13+
const gitFs = createGitFs(fs).promises;
14+
return { fs, gitFs };
15+
}
16+
17+
describe("createGitFs", () => {
18+
describe("unlink", () => {
19+
it("deletes an existing file", async () => {
20+
const { fs, gitFs } = setup();
21+
await fs.writeFile("/file.txt", "content");
22+
await gitFs.unlink("/file.txt");
23+
await expect(fs.exists("/file.txt")).resolves.toBe(false);
24+
});
25+
26+
it("throws with code ENOENT for missing files", async () => {
27+
const { gitFs } = setup();
28+
try {
29+
await gitFs.unlink("/nonexistent.txt");
30+
expect.unreachable("should have thrown");
31+
} catch (err: unknown) {
32+
expect(err).toBeInstanceOf(Error);
33+
expect((err as Error & { code: string }).code).toBe("ENOENT");
34+
}
35+
});
36+
});
37+
});

0 commit comments

Comments
 (0)