Skip to content

Commit 7edad00

Browse files
committed
test,fs: add fs.rm() tests for .git directories
Git for Windows creates read-only files inside the .git directory. fs.rm() was built in a way, to work around any EPERM error that can happen while deleting the .git directory by turning the directory into a writable one. This change adds a regression test for that. Refs: isaacs/rimraf#21 Refs: nodejs#38810 (comment) Signed-off-by: Darshan Sen <[email protected]>
1 parent 46a0d0d commit 7edad00

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/parallel/test-fs-rm.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ function removeAsync(dir) {
130130
}));
131131
}
132132

133+
// Removing a .git directory should not throw an EPERM.
134+
// Refs: https://github.com/isaacs/rimraf/issues/21.
135+
{
136+
const gitDirectory = nextDirPath();
137+
fs.mkdirSync(gitDirectory);
138+
execSync(`git -C ${gitDirectory} init`);
139+
fs.rm(gitDirectory, { recursive: true }, common.mustSucceed(() => {
140+
assert.strictEqual(fs.existsSync(gitDirectory), false);
141+
}));
142+
}
143+
133144
// Test the synchronous version.
134145
{
135146
const dir = nextDirPath();
@@ -179,6 +190,16 @@ function removeAsync(dir) {
179190
assert.throws(() => fs.rmSync(dir), { syscall: 'stat' });
180191
}
181192

193+
// Removing a .git directory should not throw an EPERM.
194+
// Refs: https://github.com/isaacs/rimraf/issues/21.
195+
{
196+
const gitDirectory = nextDirPath();
197+
fs.mkdirSync(gitDirectory);
198+
execSync(`git -C ${gitDirectory} init`);
199+
fs.rmSync(gitDirectory, { recursive: true });
200+
assert.strictEqual(fs.existsSync(gitDirectory), false);
201+
}
202+
182203
// Test the Promises based version.
183204
(async () => {
184205
const dir = nextDirPath();
@@ -230,6 +251,16 @@ function removeAsync(dir) {
230251
}
231252
})().then(common.mustCall());
232253

254+
// Removing a .git directory should not throw an EPERM.
255+
// Refs: https://github.com/isaacs/rimraf/issues/21.
256+
(async () => {
257+
const gitDirectory = nextDirPath();
258+
fs.mkdirSync(gitDirectory);
259+
execSync(`git -C ${gitDirectory} init`);
260+
await fs.promises.rm(gitDirectory, { recursive: true });
261+
assert.strictEqual(fs.existsSync(gitDirectory), false);
262+
})().then(common.mustCall());
263+
233264
// Test input validation.
234265
{
235266
const dir = nextDirPath();

0 commit comments

Comments
 (0)