From 352fba44faf2eb69d81d4cb5f60220f60f5f8e49 Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Sat, 23 Apr 2022 11:52:21 +0200 Subject: [PATCH] Refine #974 safe directory code (#986) --- src/cml.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cml.js b/src/cml.js index 721047d4b..2bb070fdf 100755 --- a/src/cml.js +++ b/src/cml.js @@ -71,7 +71,7 @@ const getDriver = (opts) => { }; const fixGitSafeDirectory = () => { - const getOrSetGitConfigSafeDirectory = (value) => + const gitConfigSafeDirectory = (value) => spawnSync( 'git', [ @@ -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); } };