1
1
import type { Container } from '../../container' ;
2
+ import type { RebaseOptions } 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' ;
@@ -38,13 +39,9 @@ interface Context {
38
39
title : string ;
39
40
}
40
41
41
- type Flags = '--interactive' ;
42
- type RebaseOptions = { interactive ?: boolean } ;
43
-
44
42
interface State {
45
43
repo : string | Repository ;
46
44
destination : GitReference ;
47
- flags : Flags [ ] ;
48
45
options : RebaseOptions ;
49
46
}
50
47
@@ -90,7 +87,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
90
87
}
91
88
92
89
try {
93
- await state . repo . git . rebase ( state . destination . ref , configs , state . options ) ;
90
+ await state . repo . git . rebase ( null , state . destination . ref , configs , state . options ) ;
94
91
} catch ( ex ) {
95
92
Logger . error ( ex , this . title ) ;
96
93
void showGenericErrorMessage ( ex ) ;
@@ -111,7 +108,9 @@ export class RebaseGitCommand extends QuickCommand<State> {
111
108
} ;
112
109
113
110
if ( state . options == null ) {
114
- state . options = { } ;
111
+ state . options = {
112
+ autostash : true ,
113
+ } ;
115
114
}
116
115
117
116
let skippedStepOne = false ;
@@ -214,7 +213,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
214
213
const result = yield * this . confirmStep ( state as RebaseStepState , context ) ;
215
214
if ( result === StepResultBreak ) continue ;
216
215
217
- state . options = Object . assign ( state . options ?? { } , ...result ) ;
216
+ state . options = Object . assign ( { autostash : true } , ...result ) ;
218
217
219
218
endSteps ( state ) ;
220
219
void this . execute ( state as RebaseStepState ) ;
@@ -255,9 +254,40 @@ export class RebaseGitCommand extends QuickCommand<State> {
255
254
return StepResultBreak ;
256
255
}
257
256
258
- const optionsArr : RebaseOptions [ ] = [ ] ;
257
+ try {
258
+ await state . repo . git . rebase ( null , null , undefined , { checkActiveRebase : true } ) ;
259
+ } catch {
260
+ const step : QuickPickStep < FlagsQuickPickItem < RebaseOptions > > = this . createConfirmStep (
261
+ appendReposToTitle ( title , state , context ) ,
262
+ [
263
+ createFlagsQuickPickItem < RebaseOptions > ( [ ] , [ { abort : true } ] , {
264
+ label : 'Abort Rebase' ,
265
+ description : '--abort' ,
266
+ detail : 'Will abort the current rebase' ,
267
+ } ) ,
268
+ createFlagsQuickPickItem < RebaseOptions > ( [ ] , [ { continue : true } ] , {
269
+ label : 'Continue Rebase' ,
270
+ description : '--continue' ,
271
+ detail : 'Will continue the current rebase' ,
272
+ } ) ,
273
+ createFlagsQuickPickItem < RebaseOptions > ( [ ] , [ { skip : true } ] , {
274
+ label : 'Skip Rebase' ,
275
+ description : '--skip' ,
276
+ detail : 'Will skip the current commit and continue the rebase' ,
277
+ } ) ,
278
+ ] ,
279
+ createDirectiveQuickPickItem ( Directive . Cancel , true , {
280
+ label : 'Do nothing. A rebase is already in progress' ,
281
+ detail : "If that is not the case, you can run `rm -rf '.git/rebase-merge'` and try again" ,
282
+ } ) ,
283
+ ) ;
284
+
285
+ const selection : StepSelection < typeof step > = yield step ;
286
+ return canPickStepContinue ( step , state , selection ) ? selection [ 0 ] . item : StepResultBreak ;
287
+ }
288
+
259
289
const rebaseItems = [
260
- createFlagsQuickPickItem < RebaseOptions > ( optionsArr , [ { interactive : true } ] , {
290
+ createFlagsQuickPickItem < RebaseOptions > ( [ ] , [ { interactive : true } ] , {
261
291
label : `Interactive ${ this . title } ` ,
262
292
description : '--interactive' ,
263
293
detail : `Will interactively update ${ getReferenceLabel ( context . branch , {
@@ -270,7 +300,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
270
300
271
301
if ( behind > 0 ) {
272
302
rebaseItems . unshift (
273
- createFlagsQuickPickItem < RebaseOptions > ( optionsArr , [ { } ] , {
303
+ createFlagsQuickPickItem < RebaseOptions > ( [ ] , [ { } ] , {
274
304
label : this . title ,
275
305
detail : `Will update ${ getReferenceLabel ( context . branch , {
276
306
label : false ,
@@ -286,7 +316,6 @@ export class RebaseGitCommand extends QuickCommand<State> {
286
316
rebaseItems ,
287
317
) ;
288
318
289
- state . options = Object . assign ( state . options , ...optionsArr ) ;
290
319
const selection : StepSelection < typeof step > = yield step ;
291
320
return canPickStepContinue ( step , state , selection ) ? selection [ 0 ] . item : StepResultBreak ;
292
321
}
0 commit comments