From a653c55a397e7e6f04fa5aefb0ddf2c7543569d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Thu, 27 Feb 2020 17:41:50 +0200 Subject: [PATCH] fix: unset GIT_LITERAL_PATHSPECS env variable before running This makes git treat all pathspecs literally, so that for example '.' would refer to a file named only a dot --- lib/index.js | 4 ++++ lib/resolveGitRepo.js | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index e5ca47b00..2fe455955 100644 --- a/lib/index.js +++ b/lib/index.js @@ -92,6 +92,10 @@ module.exports = async function lintStaged( debugLog('lint-staged config:\n%O', config) } + // Unset GIT_LITERAL_PATHSPECS to not mess with path interpretation + debugLog('Unset GIT_LITERAL_PATHSPECS (was `%s`)', process.env.GIT_LITERAL_PATHSPECS) + delete process.env.GIT_LITERAL_PATHSPECS + try { await runAll( { allowEmpty, concurrent, config, debug, maxArgLength, quiet, relative, shell }, diff --git a/lib/resolveGitRepo.js b/lib/resolveGitRepo.js index 886e2abe2..1ce92db08 100644 --- a/lib/resolveGitRepo.js +++ b/lib/resolveGitRepo.js @@ -31,9 +31,9 @@ const resolveGitConfigDir = async gitDir => { const resolveGitRepo = async cwd => { try { debugLog('Resolving git repo from `%s`', cwd) - // git cli uses GIT_DIR to fast track its response however it might be set to a different path - // depending on where the caller initiated this from, hence clear GIT_DIR - debugLog('Deleting GIT_DIR from env with value `%s`', process.env.GIT_DIR) + + // Unset GIT_DIR before running any git operations in case it's pointing to an incorrect location + debugLog('Unset GIT_DIR (was `%s`)', process.env.GIT_DIR) delete process.env.GIT_DIR const gitDir = normalize(await execGit(['rev-parse', '--show-toplevel'], { cwd }))