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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case sensitivity in finding .git root folder #1403

Open
Olgsie opened this issue Apr 5, 2024 · 3 comments
Open

Case sensitivity in finding .git root folder #1403

Olgsie opened this issue Apr 5, 2024 · 3 comments

Comments

@Olgsie
Copy link

Olgsie commented Apr 5, 2024

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch lint-staged@15.2.2 for the project I'm working on.

I have a repo with two directories, one frontend, one backend. So the .git root is not in my frontend folder.
There have been fixes for this issue already, checking for the .git folder in the parent directory, but my specific issue is that the current code is case sensitive and our frontend directory is ../Clients, causing the lastIndexOf function not to find anything.

Simple solution: toLowerCase().

Here is the diff that solved my problem:

diff --git a/node_modules/lint-staged/lib/resolveGitRepo.js b/node_modules/lint-staged/lib/resolveGitRepo.js
index 99635f0..8faf98a 100644
--- a/node_modules/lint-staged/lib/resolveGitRepo.js
+++ b/node_modules/lint-staged/lib/resolveGitRepo.js
@@ -65,7 +65,8 @@ export const resolveGitRepo = async (cwd = process.cwd()) => {
     // read the path of the current directory relative to the top-level directory
     // don't read the toplevel directly, it will lead to an posix conform path on non posix systems (cygwin)
     const gitRel = normalizePath(await execGit(['rev-parse', '--show-prefix'], { cwd }))
-    const gitDir = normalizePath(determineGitDir(normalizePath(cwd), gitRel))
+    const gitDir = normalizePath(determineGitDir(normalizePath(cwd), gitRel.toLowerCase()))
+    
     const gitConfigDir = normalizePath(await resolveGitConfigDir(gitDir))
 
     debugLog('Resolved git directory to be `%s`', gitDir)

This issue body was partially generated by patch-package.

@iiroj
Copy link
Member

iiroj commented Apr 6, 2024

Are you working on a case-sensitive file system? I wouldn't want to start converting filename case manually inside lint-staged, it sounds like introducing a bug.

@Olgsie
Copy link
Author

Olgsie commented Apr 10, 2024

Working on windows, but regardless of file system it's a simple string comparison that's going wrong isn't it?

@iiroj
Copy link
Member

iiroj commented Apr 10, 2024

If the file system is case-sensitive, then /foo and /Foo are two different paths so it's not that simple.

EDIT: I assume your problem is that your FS is case-insensitive but Git is sensitive; have to Google around if there's some common solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants