Skip to content

Commit

Permalink
Refine #974 safe directory code (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Apr 23, 2022
1 parent d9c1dee commit 352fba4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 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('*');
// Fix for git>=2.36.0
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

16 comments on commit 352fba4

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

Please sign in to comment.