File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
Expand file tree Collapse file tree 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) => {
1616 type : 'directory' ,
1717 } )
1818
19- if ( gitDirectory ) {
20- return path . dirname ( gitDirectory )
21- }
22-
2319 const gitWorkTreeFile = findUp . sync ( '.git' , {
2420 cwd : directory ,
2521 type : 'file' ,
2622 } )
2723
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 ) {
2935 return path . dirname ( gitWorkTreeFile )
3036 }
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
3144}
3245
3346const runGit = ( directory : string , args : string [ ] ) =>
You can’t perform that action at this time.
0 commit comments