File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ async function getCommitMessages(settings) {
19
19
const { cwd, from, to, edit} = settings ;
20
20
21
21
if ( edit ) {
22
- return getEditCommit ( cwd ) ;
22
+ return getEditCommit ( cwd , edit ) ;
23
23
}
24
24
25
25
if ( await isShallow ( cwd ) ) {
@@ -57,15 +57,19 @@ async function isShallow(cwd) {
57
57
}
58
58
59
59
// Get recently edited commit message
60
- // (cwd: string) => Promise<Array<String>>
61
- async function getEditCommit ( cwd ) {
60
+ // (cwd: string, edit: any ) => Promise<Array<String>>
61
+ async function getEditCommit ( cwd , edit ) {
62
62
const top = await toplevel ( cwd ) ;
63
63
64
64
if ( typeof top !== 'string' ) {
65
65
throw new TypeError ( `Could not find git root from ${ cwd } ` ) ;
66
66
}
67
67
68
- const editFilePath = path . join ( top , '.git/COMMIT_EDITMSG' ) ;
68
+ const editFilePath =
69
+ typeof edit === 'string'
70
+ ? path . resolve ( top , edit )
71
+ : path . join ( top , '.git/COMMIT_EDITMSG' ) ;
72
+
69
73
const editFile = await sander . readFile ( editFilePath ) ;
70
74
return [ `${ editFile . toString ( 'utf-8' ) } \n` ] ;
71
75
}
Original file line number Diff line number Diff line change @@ -6,6 +6,16 @@ import * as sander from '@marionebl/sander';
6
6
import pkg from '../package' ;
7
7
import read from './read' ;
8
8
9
+ test ( 'get edit commit message specified by the `edit` flag' , async t => {
10
+ const cwd = await git . bootstrap ( ) ;
11
+
12
+ await sander . writeFile ( cwd , 'commit-msg-file' , 'foo' ) ;
13
+
14
+ const expected = [ 'foo\n' ] ;
15
+ const actual = await read ( { edit : 'commit-msg-file' , cwd} ) ;
16
+ t . deepEqual ( actual , expected ) ;
17
+ } ) ;
18
+
9
19
test ( 'get edit commit message from git root' , async t => {
10
20
const cwd = await git . bootstrap ( ) ;
11
21
You can’t perform that action at this time.
0 commit comments