@@ -25,10 +25,20 @@ const resolveGitConfigDir = async (gitDir) => {
25
25
return path . resolve ( gitDir , file . replace ( / ^ g i t d i r : / , '' ) ) . trim ( )
26
26
}
27
27
28
+ const determineGitDir = ( cwd , relativeDir ) => {
29
+ if ( relativeDir ) {
30
+ // the current working dir is inside the git top-level directory
31
+ return normalize ( cwd . substring ( 0 , cwd . lastIndexOf ( relativeDir ) ) )
32
+ } else {
33
+ // the current working dir is the top-level git directory
34
+ return normalize ( cwd )
35
+ }
36
+ }
37
+
28
38
/**
29
39
* Resolve git directory and possible submodule paths
30
40
*/
31
- const resolveGitRepo = async ( cwd ) => {
41
+ const resolveGitRepo = async ( cwd = process . cwd ( ) ) => {
32
42
try {
33
43
debugLog ( 'Resolving git repo from `%s`' , cwd )
34
44
@@ -38,7 +48,10 @@ const resolveGitRepo = async (cwd) => {
38
48
debugLog ( 'Unset GIT_WORK_TREE (was `%s`)' , process . env . GIT_WORK_TREE )
39
49
delete process . env . GIT_WORK_TREE
40
50
41
- const gitDir = normalize ( await execGit ( [ 'rev-parse' , '--show-toplevel' ] , { cwd } ) )
51
+ // read the path of the current directory relative to the top-level directory
52
+ // don't read the toplevel directly, it will lead to an posix conform path on non posix systems (cygwin)
53
+ const gitRel = normalize ( await execGit ( [ 'rev-parse' , '--show-prefix' ] ) )
54
+ const gitDir = determineGitDir ( cwd , gitRel )
42
55
const gitConfigDir = normalize ( await resolveGitConfigDir ( gitDir ) )
43
56
44
57
debugLog ( 'Resolved git directory to be `%s`' , gitDir )
0 commit comments