Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: run cd dir && git init && cd - instead of git init -C dir
Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Mar 26, 2022
commit a2da073c5c25c022cd17aaef7d6f2dfca8639d70
17 changes: 11 additions & 6 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const isGitPresent = (() => {
try { execSync('git --version'); return true; } catch { return false; }
})();

function gitInit(gitDirectory) {
const cwd = process.cwd();
fs.mkdirSync(gitDirectory);
process.chdir(gitDirectory);
execSync('git init');
process.chdir(cwd);
}

function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) {
fs.mkdirSync(dirname, { recursive: true });
fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8');
Expand Down Expand Up @@ -138,8 +146,7 @@ function removeAsync(dir) {
// Refs: https://github.com/isaacs/rimraf/issues/21.
if (isGitPresent) {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
gitInit(gitDirectory);
fs.rm(gitDirectory, { recursive: true }, common.mustSucceed(() => {
assert.strictEqual(fs.existsSync(gitDirectory), false);
}));
Expand Down Expand Up @@ -198,8 +205,7 @@ if (isGitPresent) {
// Refs: https://github.com/isaacs/rimraf/issues/21.
if (isGitPresent) {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
gitInit(gitDirectory);
fs.rmSync(gitDirectory, { recursive: true });
assert.strictEqual(fs.existsSync(gitDirectory), false);
}
Expand Down Expand Up @@ -260,8 +266,7 @@ if (isGitPresent) {
if (isGitPresent) {
(async () => {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
gitInit(gitDirectory);
await fs.promises.rm(gitDirectory, { recursive: true });
assert.strictEqual(fs.existsSync(gitDirectory), false);
})().then(common.mustCall());
Expand Down