Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85eb0dd

Browse files
committed
fix: when determining git directory, use fs.realpath() only for symlinks
1 parent 82eded4 commit 85eb0dd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'lint-staged': patch
3+
---
4+
5+
When determining git directory, use `fs.realpath()` only for symlinks. It looks like `fs.realpath()` changes some Windows mapped network filepaths unexpectedly, causing issues.

‎lib/resolveGitRepo.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ const debugLog = debug('lint-staged:resolveGitRepo')
1515
*/
1616
const resolveGitConfigDir = async (gitDir) => {
1717
// Get the real path in case it's a symlink
18-
const defaultDir = await fs.realpath(path.join(gitDir, '.git'))
18+
const defaultDir = path.join(gitDir, '.git')
1919
const stats = await fs.lstat(defaultDir)
20+
2021
// If .git is a directory, use it
21-
if (stats.isDirectory()) return defaultDir
22+
if (stats.isDirectory()) {
23+
return defaultDir
24+
}
25+
26+
// If .git is a symlink, return the real location
27+
if (stats.isSymbolicLink()) {
28+
return await fs.realpath(gitDir)
29+
}
30+
2231
// Otherwise .git is a file containing path to real location
2332
const file = (await readFile(defaultDir)).toString()
2433
return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()

0 commit comments

Comments
 (0)