File tree 2 files changed +23
-5
lines changed
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " pretty-quick " : patch
3
+ ---
4
+
5
+ fix: more robust computation of git directory
Original file line number Diff line number Diff line change @@ -16,18 +16,31 @@ export const detect = (directory: string) => {
16
16
type : 'directory' ,
17
17
} )
18
18
19
- if ( gitDirectory ) {
20
- return path . dirname ( gitDirectory )
21
- }
22
-
23
19
const gitWorkTreeFile = findUp . sync ( '.git' , {
24
20
cwd : directory ,
25
21
type : 'file' ,
26
22
} )
27
23
28
- if ( gitWorkTreeFile ) {
24
+ // if both of these are null then return null
25
+ if ( ! gitDirectory && ! gitWorkTreeFile ) {
26
+ return null
27
+ }
28
+
29
+ // if only one of these exists then return it
30
+ if ( gitDirectory && ! gitWorkTreeFile ) {
31
+ return path . dirname ( gitDirectory )
32
+ }
33
+
34
+ if ( gitWorkTreeFile && ! gitDirectory ) {
29
35
return path . dirname ( gitWorkTreeFile )
30
36
}
37
+
38
+ const gitRepoDirectory = path . dirname ( gitDirectory ! )
39
+ const gitWorkTreeDirectory = path . dirname ( gitWorkTreeFile ! )
40
+ // return the deeper of these two
41
+ return gitRepoDirectory . length > gitWorkTreeDirectory . length
42
+ ? gitRepoDirectory
43
+ : gitWorkTreeDirectory
31
44
}
32
45
33
46
const runGit = ( directory : string , args : string [ ] ) =>
You can’t perform that action at this time.
0 commit comments