Skip to content

Commit

Permalink
fix: when determining git directory, use fs.realpath() only for sym…
Browse files Browse the repository at this point in the history
…links
  • Loading branch information
iiroj committed Dec 2, 2023
1 parent 82eded4 commit 85eb0dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-apes-attend.md
@@ -0,0 +1,5 @@
---
'lint-staged': patch
---

When determining git directory, use `fs.realpath()` only for symlinks. It looks like `fs.realpath()` changes some Windows mapped network filepaths unexpectedly, causing issues.
13 changes: 11 additions & 2 deletions lib/resolveGitRepo.js
Expand Up @@ -15,10 +15,19 @@ const debugLog = debug('lint-staged:resolveGitRepo')
*/
const resolveGitConfigDir = async (gitDir) => {
// Get the real path in case it's a symlink
const defaultDir = await fs.realpath(path.join(gitDir, '.git'))
const defaultDir = path.join(gitDir, '.git')
const stats = await fs.lstat(defaultDir)

// If .git is a directory, use it
if (stats.isDirectory()) return defaultDir
if (stats.isDirectory()) {
return defaultDir
}

// If .git is a symlink, return the real location
if (stats.isSymbolicLink()) {
return await fs.realpath(gitDir)
}

// Otherwise .git is a file containing path to real location
const file = (await readFile(defaultDir)).toString()
return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()
Expand Down

0 comments on commit 85eb0dd

Please sign in to comment.