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 }))