Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when determining git directory, use fs.realpath() only for sym… #1373

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-apes-attend.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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