File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -14,18 +14,30 @@ export const detect = (directory) => {
14
14
cwd : directory ,
15
15
type : 'directory' ,
16
16
} ) ;
17
- if ( gitDirectory ) {
18
- return dirname ( gitDirectory ) ;
19
- }
20
17
21
18
const gitWorktreeFile = findUp . sync ( '.git' , {
22
19
cwd : directory ,
23
20
type : 'file' ,
24
21
} ) ;
22
+ // if both of these are null then return null
23
+ if ( ! gitDirectory && ! gitWorktreeFile ) {
24
+ return null ;
25
+ }
25
26
26
- if ( gitWorktreeFile ) {
27
+ // if only one of these exists then return it
28
+ if ( gitDirectory && ! gitWorktreeFile ) {
29
+ return dirname ( gitDirectory ) ;
30
+ }
31
+ if ( gitWorktreeFile && ! gitDirectory ) {
27
32
return dirname ( gitWorktreeFile ) ;
28
33
}
34
+
35
+ const gitRepoDirectory = dirname ( gitDirectory ) ;
36
+ const gitWorktreeDirectory = dirname ( gitWorktreeFile ) ;
37
+ // return the deeper of these two
38
+ return gitRepoDirectory . length > gitWorktreeDirectory . length
39
+ ? gitRepoDirectory
40
+ : gitWorktreeDirectory ;
29
41
} ;
30
42
31
43
const runGit = ( directory , args ) =>
You can’t perform that action at this time.
0 commit comments