Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
iiroj committed Mar 30, 2020
1 parent 52125a9 commit a653c55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Expand Up @@ -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 },
Expand Down
6 changes: 3 additions & 3 deletions lib/resolveGitRepo.js
Expand Up @@ -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 }))
Expand Down

0 comments on commit a653c55

Please sign in to comment.