35
35
const { action : startAction } = require ( './start' ) ;
36
36
const { UIError, cmdLine, assertNoFork } = require ( '../common' ) ;
37
37
38
+ /**
39
+ * @param {import('../typedefs').CmdDeps } deps
40
+ * @param {string } from
41
+ */
38
42
async function createFeatureMerge ( { git, log } , from ) {
39
43
await git . reset ( 'hard' ) ;
40
- await startAction ( { git , log } , `merge- ${ from } ` ) ;
41
- try {
42
- await git . merge ( [ from ] ) ;
43
- } catch ( err ) {
44
- /* */
45
- }
44
+ await startAction ( {
45
+ deps : { git , log } ,
46
+ args : [ `merge- ${ from } ` ] ,
47
+ opts : { parent : { } } ,
48
+ } ) ;
49
+ await git . merge ( [ from ] ) . catch ( ( ) => { } ) ;
46
50
throw new UIError ( 'When conflicts are resolved, commit and `wf pr`' ) ;
47
51
}
48
52
53
+ /**
54
+ * @param {import('simple-git/promise').SimpleGit } git
55
+ * @param {string } branch
56
+ */
49
57
async function switchAndPull ( git , branch ) {
50
58
await git . checkout ( branch ) ;
59
+ // @ts -ignore
51
60
await git . pull ( { '--no-rebase' : true } ) ;
52
61
}
53
62
54
- async function tryMerge ( { git, log } , from , to ) {
63
+ /**
64
+ * @param {import('../typedefs').CmdDeps } deps
65
+ * @param {string } from
66
+ * @param {string } to
67
+ */
68
+ async function tryMerge ( deps , from , to ) {
69
+ const { git, log } = deps ;
55
70
log ( `${ to } ← ${ from } ` ) ;
56
71
await switchAndPull ( git , to ) ;
57
72
@@ -65,7 +80,7 @@ async function tryMerge({ git, log }, from, to) {
65
80
if ( / \n C O N F L I C T / . test ( output ) ) throw new Error ( output ) ;
66
81
} catch ( err ) {
67
82
log ( 'Automated merge failed; creating feature branch for resolution' ) ;
68
- await createFeatureMerge ( { git , log } , from ) ; // will throw
83
+ await createFeatureMerge ( deps , from ) ; // will throw
69
84
}
70
85
71
86
log ( `Merged cleanly; committing & pushing results to ${ to } branch` ) ;
@@ -76,7 +91,8 @@ async function tryMerge({ git, log }, from, to) {
76
91
await git . push ( ) ;
77
92
}
78
93
79
- async function mergeBackAction ( deps ) {
94
+ /** @type {import('../typedefs').ActionFn } */
95
+ async function mergeBackAction ( { deps } ) {
80
96
const { git, log } = deps ;
81
97
82
98
await assertNoFork ( git , 'merge-back' ) ;
@@ -94,6 +110,7 @@ async function mergeBackAction(deps) {
94
110
return true ;
95
111
}
96
112
113
+ /** @type {import('../typedefs').Action } */
97
114
module . exports = {
98
115
action : mergeBackAction ,
99
116
command ( prog , wrapAction ) {
0 commit comments