diff --git a/lib/resolveGitRepo.js b/lib/resolveGitRepo.js index fbd28ce63..33e5e36c7 100644 --- a/lib/resolveGitRepo.js +++ b/lib/resolveGitRepo.js @@ -15,7 +15,7 @@ const debugLog = debug('lint-staged:resolveGitRepo') */ const resolveGitConfigDir = async (gitDir) => { // Get the real path in case it's a symlink - const defaultDir = normalizePath(await fs.realpath(path.join(gitDir, '.git'))) + const defaultDir = await fs.realpath(path.join(gitDir, '.git')) const stats = await fs.lstat(defaultDir) // If .git is a directory, use it if (stats.isDirectory()) return defaultDir @@ -33,10 +33,10 @@ export const determineGitDir = (cwd, relativeDir) => { } if (relativeDir) { // the current working dir is inside the git top-level directory - return normalizePath(cwd.substring(0, cwd.lastIndexOf(relativeDir))) + return cwd.substring(0, cwd.lastIndexOf(relativeDir)) } else { // the current working dir is the top-level git directory - return normalizePath(cwd) + return cwd } } @@ -56,7 +56,7 @@ 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 = determineGitDir(normalizePath(cwd), gitRel) + const gitDir = normalizePath(determineGitDir(normalizePath(cwd), gitRel)) const gitConfigDir = normalizePath(await resolveGitConfigDir(gitDir)) debugLog('Resolved git directory to be `%s`', gitDir) diff --git a/test/unit/resolveGitRepo.spec.js b/test/unit/resolveGitRepo.spec.js index ecee89c26..9f63d0835 100644 --- a/test/unit/resolveGitRepo.spec.js +++ b/test/unit/resolveGitRepo.spec.js @@ -53,21 +53,21 @@ describe('resolveGitRepo', () => { const cwd = process.cwd() const relativeDir = undefined const rootDir = determineGitDir(cwd, relativeDir) - expect(rootDir).toEqual(normalizePath(cwd)) + expect(normalizePath(rootDir)).toEqual(normalizePath(cwd)) }) it('should resolve to parent dir when relative dir is child', () => { const relativeDir = 'bar' const cwd = process.cwd() + path.sep + 'bar' const rootDir = determineGitDir(cwd, relativeDir) - expect(rootDir).toEqual(normalizePath(process.cwd())) + expect(normalizePath(rootDir)).toEqual(normalizePath(process.cwd())) }) it('should resolve to parent dir when relative dir is child and child has trailing dir separator', () => { const relativeDir = 'bar' + path.sep const cwd = process.cwd() + path.sep + 'bar' const rootDir = determineGitDir(cwd, relativeDir) - expect(rootDir).toEqual(normalizePath(process.cwd())) + expect(normalizePath(rootDir)).toEqual(normalizePath(process.cwd())) }) }) })