Skip to content

Commit

Permalink
Refine #974 safe directory code
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Apr 22, 2022
1 parent d9c1dee commit 6be57ef
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const getDriver = (opts) => {
};

const fixGitSafeDirectory = () => {
const getOrSetGitConfigSafeDirectory = (value) =>
const gitConfigSafeDirectory = (value) =>
spawnSync(
'git',
[
Expand All @@ -84,23 +84,24 @@ const fixGitSafeDirectory = () => {
{
encoding: 'utf8'
}
).stdout.split(/[\r\n]+/);
).stdout;

const addSafeDirectoryIdempotent = (directory) =>
getOrSetGitConfigSafeDirectory().includes(directory) ||
getOrSetGitConfigSafeDirectory(directory);
const addSafeDirectory = (directory) =>
gitConfigSafeDirectory()
.split(/[\r\n]+/)
.includes(directory) || gitConfigSafeDirectory(directory);

// Fix for git>2.36.0
addSafeDirectoryIdempotent('*');
addSafeDirectory('*');

// Fix for git^2.35.2
addSafeDirectoryIdempotent('/');
addSafeDirectory('/');
for (
let root, dir = process.cwd();
root !== dir;
{ root, dir } = path.parse(dir)
) {
addSafeDirectoryIdempotent(dir);
addSafeDirectory(dir);
}
};

Expand Down

0 comments on commit 6be57ef

Please sign in to comment.