@@ -41,11 +41,29 @@ async function getEditCommit(cwd, edit) {
41
41
throw new TypeError ( `Could not find git root from ${ cwd } ` ) ;
42
42
}
43
43
44
- const editFilePath =
45
- typeof edit === 'string'
46
- ? path . resolve ( top , edit )
47
- : path . join ( top , '.git/COMMIT_EDITMSG' ) ;
44
+ const editFilePath = await getEditFilePath ( top , edit ) ;
48
45
49
46
const editFile = await sander . readFile ( editFilePath ) ;
50
47
return [ `${ editFile . toString ( 'utf-8' ) } \n` ] ;
51
48
}
49
+
50
+ // Get path to recently edited commit message file
51
+ // (top: string, edit: any) => Promise<String>
52
+ async function getEditFilePath ( top , edit ) {
53
+ let editFilePath ;
54
+ if ( typeof edit === 'string' ) {
55
+ editFilePath = path . resolve ( top , edit ) ;
56
+ } else {
57
+ const dotgitPath = path . join ( top , '.git' ) ;
58
+ const dotgitStats = sander . lstatSync ( dotgitPath ) ;
59
+ if ( dotgitStats . isDirectory ( ) ) {
60
+ editFilePath = path . join ( top , '.git/COMMIT_EDITMSG' ) ;
61
+ } else {
62
+ const gitFile = await sander . readFile ( dotgitPath , 'utf8' ) ;
63
+ const relativeGitPath = gitFile . replace ( 'gitdir: ' , '' ) . replace ( '\n' , '' ) ;
64
+ editFilePath = path . join ( top , relativeGitPath , 'COMMIT_EDITMSG' ) ;
65
+ }
66
+ }
67
+
68
+ return editFilePath ;
69
+ }
0 commit comments