1
+ import path from 'path' ;
2
+ import homeOrTmp from 'home-or-tmp' ;
1
3
import dedent from 'dedent' ;
2
4
import { commit as gitCommit , log } from '../git' ;
5
+ import * as cache from './cache' ;
3
6
4
7
export default commit ;
5
-
8
+
9
+ /**
10
+ * Takes all of the final inputs needed in order to make dispatch a git commit
11
+ */
12
+ function dispatchGitCommit ( sh , repoPath , template , options , overrideOptions , done ) {
13
+
14
+ // Commit the user input -- side effect that we'll test
15
+ gitCommit ( sh , repoPath , template , { ...options , ...overrideOptions } , function ( ) {
16
+ done ( template ) ;
17
+ } ) ;
18
+
19
+ }
20
+
6
21
/**
7
22
* Asynchronously commits files using commitizen
8
23
*/
9
24
function commit ( sh , inquirer , repoPath , prompter , options , done ) {
10
25
11
- // Get user input -- side effect that is hard to test
12
- prompter ( inquirer , function ( template , overrideOptions ) {
26
+ var cachePath = path . join ( homeOrTmp , 'commitizen.json' ) ;
27
+
28
+ if ( options . retryLastCommit ) {
13
29
14
- // Commit the user input -- side effect that we'll test
15
- gitCommit ( sh , repoPath , template , { ...options , ...overrideOptions } , function ( ) {
16
- done ( template ) ;
17
- } ) ;
18
- } ) ;
30
+ console . log ( 'Retrying last commit attempt.' ) ;
31
+
32
+ // We want to use the last commit instead of the current commit,
33
+ // so lets override some options using the values from cache.
34
+ let {
35
+ options : retryOptions ,
36
+ overrideOptions : retryOverrideOptions ,
37
+ template : retryTemplate
38
+ } = cache . getCacheValueSync ( cachePath , repoPath ) ;
39
+ dispatchGitCommit ( sh , repoPath , retryTemplate , retryOptions , retryOverrideOptions , done ) ;
40
+
41
+ } else {
42
+ // Get user input -- side effect that is hard to test
43
+ prompter ( inquirer , function ( template , overrideOptions ) {
44
+
45
+ // We don't want to add retries to the cache, only actual commands
46
+ cache . setCacheValueSync ( cachePath , repoPath , { template, options, overrideOptions } ) ;
47
+ dispatchGitCommit ( sh , repoPath , template , options , overrideOptions , done ) ;
48
+ } ) ;
49
+ }
19
50
20
51
}
0 commit comments