| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1aff9fa commit a195b4f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,15 @@ let count = 0; | |||
| 15 | 15 | const nextDirPath = (name = 'rm') => | |
| 16 | 16 | path.join(tmpdir.path, `${name}-${count++}`); | |
| 17 | 17 | ||
| 18 | + const isGitPresent = (() => { | ||
| 19 | + try { execSync('git --version'); return true; } catch { return false; } | ||
| 20 | + })(); | ||
| 21 | + | ||
| 22 | + function gitInit(gitDirectory) { | ||
| 23 | + fs.mkdirSync(gitDirectory); | ||
| 24 | + execSync('git init', { cwd: gitDirectory }); | ||
| 25 | + } | ||
| 26 | + | ||
| 18 | 27 | function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) { | |
| 19 | 28 | fs.mkdirSync(dirname, { recursive: true }); | |
| 20 | 29 | fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8'); | |
@@ -129,6 +138,16 @@ function removeAsync(dir) { | |||
| 129 | 138 | })); | |
| 130 | 139 | } | |
| 131 | 140 | ||
| 141 | + // Removing a .git directory should not throw an EPERM. | ||
| 142 | + // Refs: https://github.com/isaacs/rimraf/issues/21. | ||
| 143 | + if (isGitPresent) { | ||
| 144 | + const gitDirectory = nextDirPath(); | ||
| 145 | + gitInit(gitDirectory); | ||
| 146 | + fs.rm(gitDirectory, { recursive: true }, common.mustSucceed(() => { | ||
| 147 | + assert.strictEqual(fs.existsSync(gitDirectory), false); | ||
| 148 | + })); | ||
| 149 | + } | ||
| 150 | + | ||
| 132 | 151 | // Test the synchronous version. | |
| 133 | 152 | { | |
| 134 | 153 | const dir = nextDirPath(); | |
@@ -178,6 +197,15 @@ function removeAsync(dir) { | |||
| 178 | 197 | assert.throws(() => fs.rmSync(dir), { syscall: 'stat' }); | |
| 179 | 198 | } | |
| 180 | 199 | ||
| 200 | + // Removing a .git directory should not throw an EPERM. | ||
| 201 | + // Refs: https://github.com/isaacs/rimraf/issues/21. | ||
| 202 | + if (isGitPresent) { | ||
| 203 | + const gitDirectory = nextDirPath(); | ||
| 204 | + gitInit(gitDirectory); | ||
| 205 | + fs.rmSync(gitDirectory, { recursive: true }); | ||
| 206 | + assert.strictEqual(fs.existsSync(gitDirectory), false); | ||
| 207 | + } | ||
| 208 | + | ||
| 181 | 209 | // Test the Promises based version. | |
| 182 | 210 | (async () => { | |
| 183 | 211 | const dir = nextDirPath(); | |
@@ -229,6 +257,17 @@ function removeAsync(dir) { | |||
| 229 | 257 | } | |
| 230 | 258 | })().then(common.mustCall()); | |
| 231 | 259 | ||
| 260 | + // Removing a .git directory should not throw an EPERM. | ||
| 261 | + // Refs: https://github.com/isaacs/rimraf/issues/21. | ||
| 262 | + if (isGitPresent) { | ||
| 263 | + (async () => { | ||
| 264 | + const gitDirectory = nextDirPath(); | ||
| 265 | + gitInit(gitDirectory); | ||
| 266 | + await fs.promises.rm(gitDirectory, { recursive: true }); | ||
| 267 | + assert.strictEqual(fs.existsSync(gitDirectory), false); | ||
| 268 | + })().then(common.mustCall()); | ||
| 269 | + } | ||
| 270 | + | ||
| 232 | 271 | // Test input validation. | |
| 233 | 272 | { | |
| 234 | 273 | const dir = nextDirPath(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments