lint-staged 11.3.0-beta.1 → 11.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/resolveGitRepo.js +23 -2
- package/package.json +1 -1
package/lib/resolveGitRepo.js
CHANGED
|
@@ -25,10 +25,25 @@ const resolveGitConfigDir = async (gitDir) => {
|
|
|
25
25
|
return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
const determineGitDir = (cwd, relativeDir) => {
|
|
29
|
+
// if relative dir and cwd have different endings normalize it
|
|
30
|
+
// this happens under windows, where normalize is unable to normalize git's output
|
|
31
|
+
if (relativeDir && relativeDir.endsWith(path.sep)) {
|
|
32
|
+
relativeDir = relativeDir.slice(0, -1)
|
|
33
|
+
}
|
|
34
|
+
if (relativeDir) {
|
|
35
|
+
// the current working dir is inside the git top-level directory
|
|
36
|
+
return normalize(cwd.substring(0, cwd.lastIndexOf(relativeDir)))
|
|
37
|
+
} else {
|
|
38
|
+
// the current working dir is the top-level git directory
|
|
39
|
+
return normalize(cwd)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
28
43
|
/**
|
|
29
44
|
* Resolve git directory and possible submodule paths
|
|
30
45
|
*/
|
|
31
|
-
const resolveGitRepo = async (cwd) => {
|
|
46
|
+
const resolveGitRepo = async (cwd = process.cwd()) => {
|
|
32
47
|
try {
|
|
33
48
|
debugLog('Resolving git repo from `%s`', cwd)
|
|
34
49
|
|
|
@@ -38,7 +53,10 @@ const resolveGitRepo = async (cwd) => {
|
|
|
38
53
|
debugLog('Unset GIT_WORK_TREE (was `%s`)', process.env.GIT_WORK_TREE)
|
|
39
54
|
delete process.env.GIT_WORK_TREE
|
|
40
55
|
|
|
41
|
-
|
|
56
|
+
// read the path of the current directory relative to the top-level directory
|
|
57
|
+
// don't read the toplevel directly, it will lead to an posix conform path on non posix systems (cygwin)
|
|
58
|
+
const gitRel = normalize(await execGit(['rev-parse', '--show-prefix']))
|
|
59
|
+
const gitDir = determineGitDir(normalize(cwd), gitRel)
|
|
42
60
|
const gitConfigDir = normalize(await resolveGitConfigDir(gitDir))
|
|
43
61
|
|
|
44
62
|
debugLog('Resolved git directory to be `%s`', gitDir)
|
|
@@ -52,3 +70,6 @@ const resolveGitRepo = async (cwd) => {
|
|
|
52
70
|
}
|
|
53
71
|
|
|
54
72
|
module.exports = resolveGitRepo
|
|
73
|
+
|
|
74
|
+
// exported for test
|
|
75
|
+
module.exports.determineGitDir = determineGitDir
|