1
1
import type { Container } from '../../container' ;
2
+ import type { MergeOptions } from '../../git/gitProvider' ;
2
3
import type { GitBranch } from '../../git/models/branch' ;
3
4
import type { GitLog } from '../../git/models/log' ;
4
5
import type { GitReference } from '../../git/models/reference' ;
5
6
import { createRevisionRange , getReferenceLabel , isRevisionReference } from '../../git/models/reference' ;
6
7
import type { Repository } from '../../git/models/repository' ;
8
+ import { showGenericErrorMessage } from '../../messages' ;
7
9
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive' ;
8
10
import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive' ;
9
11
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags' ;
10
12
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags' ;
13
+ import { Logger } from '../../system/logger' ;
11
14
import { pluralize } from '../../system/string' ;
12
15
import type { ViewsWithRepositoryFolders } from '../../views/viewBase' ;
13
16
import type {
@@ -35,12 +38,10 @@ interface Context {
35
38
title : string ;
36
39
}
37
40
38
- type Flags = '--ff-only' | '--no-ff' | '--squash' | '--no-commit' ;
39
-
40
41
interface State {
41
42
repo : string | Repository ;
42
43
reference : GitReference ;
43
- flags : Flags [ ] ;
44
+ options : MergeOptions ;
44
45
}
45
46
46
47
export interface MergeGitCommandArgs {
@@ -76,8 +77,13 @@ export class MergeGitCommand extends QuickCommand<State> {
76
77
return false ;
77
78
}
78
79
79
- execute ( state : MergeStepState ) {
80
- state . repo . merge ( ...state . flags , state . reference . ref ) ;
80
+ async execute ( state : MergeStepState ) {
81
+ try {
82
+ await state . repo . git . merge ( state . reference . ref , state . options ) ;
83
+ } catch ( ex ) {
84
+ Logger . error ( ex , this . title ) ;
85
+ void showGenericErrorMessage ( ex ) ;
86
+ }
81
87
}
82
88
83
89
protected async * steps ( state : PartialStepState < State > ) : StepGenerator {
@@ -93,8 +99,8 @@ export class MergeGitCommand extends QuickCommand<State> {
93
99
title : this . title ,
94
100
} ;
95
101
96
- if ( state . flags == null ) {
97
- state . flags = [ ] ;
102
+ if ( state . options == null ) {
103
+ state . options = { } ;
98
104
}
99
105
100
106
let skippedStepOne = false ;
@@ -197,16 +203,16 @@ export class MergeGitCommand extends QuickCommand<State> {
197
203
const result = yield * this . confirmStep ( state as MergeStepState , context ) ;
198
204
if ( result === StepResultBreak ) continue ;
199
205
200
- state . flags = result ;
206
+ state . options = Object . assign ( { } , ... result ) ;
201
207
202
208
endSteps ( state ) ;
203
- this . execute ( state as MergeStepState ) ;
209
+ await this . execute ( state as MergeStepState ) ;
204
210
}
205
211
206
212
return state . counter < 0 ? StepResultBreak : undefined ;
207
213
}
208
214
209
- private async * confirmStep ( state : MergeStepState , context : Context ) : AsyncStepResultGenerator < Flags [ ] > {
215
+ private async * confirmStep ( state : MergeStepState , context : Context ) : AsyncStepResultGenerator < MergeOptions [ ] > {
210
216
const counts = await this . container . git . getLeftRightCommitCount (
211
217
state . repo . path ,
212
218
createRevisionRange ( context . destination . ref , state . reference . ref , '...' ) ,
@@ -240,31 +246,31 @@ export class MergeGitCommand extends QuickCommand<State> {
240
246
return StepResultBreak ;
241
247
}
242
248
243
- const step : QuickPickStep < FlagsQuickPickItem < Flags > > = this . createConfirmStep (
249
+ const step : QuickPickStep < FlagsQuickPickItem < MergeOptions > > = this . createConfirmStep (
244
250
appendReposToTitle ( `Confirm ${ title } ` , state , context ) ,
245
251
[
246
- createFlagsQuickPickItem < Flags > ( state . flags , [ ] , {
252
+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ ] , {
247
253
label : this . title ,
248
254
detail : `Will merge ${ pluralize ( 'commit' , count ) } from ${ getReferenceLabel ( state . reference , {
249
255
label : false ,
250
256
} ) } into ${ getReferenceLabel ( context . destination , { label : false } ) } `,
251
257
} ) ,
252
- createFlagsQuickPickItem < Flags > ( state . flags , [ '--ff-only' ] , {
258
+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { fastForwardOnly : true } ] , {
253
259
label : `Fast-forward ${ this . title } ` ,
254
260
description : '--ff-only' ,
255
261
detail : `Will fast-forward merge ${ pluralize ( 'commit' , count ) } from ${ getReferenceLabel (
256
262
state . reference ,
257
263
{ label : false } ,
258
264
) } into ${ getReferenceLabel ( context . destination , { label : false } ) } `,
259
265
} ) ,
260
- createFlagsQuickPickItem < Flags > ( state . flags , [ '-- squash' ] , {
266
+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { squash : true } ] , {
261
267
label : `Squash ${ this . title } ` ,
262
268
description : '--squash' ,
263
269
detail : `Will squash ${ pluralize ( 'commit' , count ) } from ${ getReferenceLabel ( state . reference , {
264
270
label : false ,
265
271
} ) } into one when merging into ${ getReferenceLabel ( context . destination , { label : false } ) } `,
266
272
} ) ,
267
- createFlagsQuickPickItem < Flags > ( state . flags , [ '--no-ff' ] , {
273
+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { noFastForward : true } ] , {
268
274
label : `No Fast-forward ${ this . title } ` ,
269
275
description : '--no-ff' ,
270
276
detail : `Will create a merge commit when merging ${ pluralize (
@@ -275,7 +281,7 @@ export class MergeGitCommand extends QuickCommand<State> {
275
281
{ label : false } ,
276
282
) } `,
277
283
} ) ,
278
- createFlagsQuickPickItem < Flags > ( state . flags , [ '--no-ff' , '--no-commit' ] , {
284
+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { noCommit : true , noFastForward : true } ] , {
279
285
label : `Don't Commit ${ this . title } ` ,
280
286
description : '--no-commit --no-ff' ,
281
287
detail : `Will pause before committing the merge of ${ pluralize (
0 commit comments