11import type { Container } from '../../container' ;
2+ import type { MergeOptions } from '../../git/gitProvider' ;
23import type { GitBranch } from '../../git/models/branch' ;
34import type { GitLog } from '../../git/models/log' ;
45import type { GitReference } from '../../git/models/reference' ;
56import { createRevisionRange , getReferenceLabel , isRevisionReference } from '../../git/models/reference' ;
67import type { Repository } from '../../git/models/repository' ;
8+ import { showGenericErrorMessage } from '../../messages' ;
79import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive' ;
810import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive' ;
911import type { FlagsQuickPickItem } from '../../quickpicks/items/flags' ;
1012import { createFlagsQuickPickItem } from '../../quickpicks/items/flags' ;
13+ import { Logger } from '../../system/logger' ;
1114import { pluralize } from '../../system/string' ;
1215import type { ViewsWithRepositoryFolders } from '../../views/viewBase' ;
1316import type {
@@ -35,12 +38,10 @@ interface Context {
3538 title : string ;
3639}
3740
38- type Flags = '--ff-only' | '--no-ff' | '--squash' | '--no-commit' ;
39-
4041interface State {
4142 repo : string | Repository ;
4243 reference : GitReference ;
43- flags : Flags [ ] ;
44+ options : MergeOptions ;
4445}
4546
4647export interface MergeGitCommandArgs {
@@ -76,8 +77,13 @@ export class MergeGitCommand extends QuickCommand<State> {
7677 return false ;
7778 }
7879
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+ }
8187 }
8288
8389 protected async * steps ( state : PartialStepState < State > ) : StepGenerator {
@@ -93,8 +99,8 @@ export class MergeGitCommand extends QuickCommand<State> {
9399 title : this . title ,
94100 } ;
95101
96- if ( state . flags == null ) {
97- state . flags = [ ] ;
102+ if ( state . options == null ) {
103+ state . options = { } ;
98104 }
99105
100106 let skippedStepOne = false ;
@@ -197,16 +203,16 @@ export class MergeGitCommand extends QuickCommand<State> {
197203 const result = yield * this . confirmStep ( state as MergeStepState , context ) ;
198204 if ( result === StepResultBreak ) continue ;
199205
200- state . flags = result ;
206+ state . options = Object . assign ( { } , ... result ) ;
201207
202208 endSteps ( state ) ;
203- this . execute ( state as MergeStepState ) ;
209+ await this . execute ( state as MergeStepState ) ;
204210 }
205211
206212 return state . counter < 0 ? StepResultBreak : undefined ;
207213 }
208214
209- private async * confirmStep ( state : MergeStepState , context : Context ) : AsyncStepResultGenerator < Flags [ ] > {
215+ private async * confirmStep ( state : MergeStepState , context : Context ) : AsyncStepResultGenerator < MergeOptions [ ] > {
210216 const counts = await this . container . git . getLeftRightCommitCount (
211217 state . repo . path ,
212218 createRevisionRange ( context . destination . ref , state . reference . ref , '...' ) ,
@@ -240,31 +246,31 @@ export class MergeGitCommand extends QuickCommand<State> {
240246 return StepResultBreak ;
241247 }
242248
243- const step : QuickPickStep < FlagsQuickPickItem < Flags > > = this . createConfirmStep (
249+ const step : QuickPickStep < FlagsQuickPickItem < MergeOptions > > = this . createConfirmStep (
244250 appendReposToTitle ( `Confirm ${ title } ` , state , context ) ,
245251 [
246- createFlagsQuickPickItem < Flags > ( state . flags , [ ] , {
252+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ ] , {
247253 label : this . title ,
248254 detail : `Will merge ${ pluralize ( 'commit' , count ) } from ${ getReferenceLabel ( state . reference , {
249255 label : false ,
250256 } ) } into ${ getReferenceLabel ( context . destination , { label : false } ) } `,
251257 } ) ,
252- createFlagsQuickPickItem < Flags > ( state . flags , [ '--ff-only' ] , {
258+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { fastForwardOnly : true } ] , {
253259 label : `Fast-forward ${ this . title } ` ,
254260 description : '--ff-only' ,
255261 detail : `Will fast-forward merge ${ pluralize ( 'commit' , count ) } from ${ getReferenceLabel (
256262 state . reference ,
257263 { label : false } ,
258264 ) } into ${ getReferenceLabel ( context . destination , { label : false } ) } `,
259265 } ) ,
260- createFlagsQuickPickItem < Flags > ( state . flags , [ '-- squash' ] , {
266+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { squash : true } ] , {
261267 label : `Squash ${ this . title } ` ,
262268 description : '--squash' ,
263269 detail : `Will squash ${ pluralize ( 'commit' , count ) } from ${ getReferenceLabel ( state . reference , {
264270 label : false ,
265271 } ) } into one when merging into ${ getReferenceLabel ( context . destination , { label : false } ) } `,
266272 } ) ,
267- createFlagsQuickPickItem < Flags > ( state . flags , [ '--no-ff' ] , {
273+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { noFastForward : true } ] , {
268274 label : `No Fast-forward ${ this . title } ` ,
269275 description : '--no-ff' ,
270276 detail : `Will create a merge commit when merging ${ pluralize (
@@ -275,7 +281,7 @@ export class MergeGitCommand extends QuickCommand<State> {
275281 { label : false } ,
276282 ) } `,
277283 } ) ,
278- createFlagsQuickPickItem < Flags > ( state . flags , [ '--no-ff' , '--no-commit' ] , {
284+ createFlagsQuickPickItem < MergeOptions > ( [ ] , [ { noCommit : true , noFastForward : true } ] , {
279285 label : `Don't Commit ${ this . title } ` ,
280286 description : '--no-commit --no-ff' ,
281287 detail : `Will pause before committing the merge of ${ pluralize (
0 commit comments