11import type { Container } from '../../container' ;
2+ import type { RebaseOptions } from '../../git/gitProvider' ;
23import type { GitBranch } from '../../git/models/branch' ;
34import type { GitLog } from '../../git/models/log' ;
45import type { GitReference } from '../../git/models/reference' ;
@@ -38,13 +39,9 @@ interface Context {
3839 title : string ;
3940}
4041
41- type Flags = '--interactive' ;
42- type RebaseOptions = { interactive ?: boolean } ;
43-
4442interface State {
4543 repo : string | Repository ;
4644 destination : GitReference ;
47- flags : Flags [ ] ;
4845 options : RebaseOptions ;
4946}
5047
@@ -90,7 +87,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
9087 }
9188
9289 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 ) ;
9491 } catch ( ex ) {
9592 Logger . error ( ex , this . title ) ;
9693 void showGenericErrorMessage ( ex ) ;
@@ -111,7 +108,9 @@ export class RebaseGitCommand extends QuickCommand<State> {
111108 } ;
112109
113110 if ( state . options == null ) {
114- state . options = { } ;
111+ state . options = {
112+ autostash : true ,
113+ } ;
115114 }
116115
117116 let skippedStepOne = false ;
@@ -214,7 +213,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
214213 const result = yield * this . confirmStep ( state as RebaseStepState , context ) ;
215214 if ( result === StepResultBreak ) continue ;
216215
217- state . options = Object . assign ( state . options ?? { } , ...result ) ;
216+ state . options = Object . assign ( { autostash : true } , ...result ) ;
218217
219218 endSteps ( state ) ;
220219 void this . execute ( state as RebaseStepState ) ;
@@ -255,9 +254,40 @@ export class RebaseGitCommand extends QuickCommand<State> {
255254 return StepResultBreak ;
256255 }
257256
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+
259289 const rebaseItems = [
260- createFlagsQuickPickItem < RebaseOptions > ( optionsArr , [ { interactive : true } ] , {
290+ createFlagsQuickPickItem < RebaseOptions > ( [ ] , [ { interactive : true } ] , {
261291 label : `Interactive ${ this . title } ` ,
262292 description : '--interactive' ,
263293 detail : `Will interactively update ${ getReferenceLabel ( context . branch , {
@@ -270,7 +300,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
270300
271301 if ( behind > 0 ) {
272302 rebaseItems . unshift (
273- createFlagsQuickPickItem < RebaseOptions > ( optionsArr , [ { } ] , {
303+ createFlagsQuickPickItem < RebaseOptions > ( [ ] , [ { } ] , {
274304 label : this . title ,
275305 detail : `Will update ${ getReferenceLabel ( context . branch , {
276306 label : false ,
@@ -286,7 +316,6 @@ export class RebaseGitCommand extends QuickCommand<State> {
286316 rebaseItems ,
287317 ) ;
288318
289- state . options = Object . assign ( state . options , ...optionsArr ) ;
290319 const selection : StepSelection < typeof step > = yield step ;
291320 return canPickStepContinue ( step , state , selection ) ? selection [ 0 ] . item : StepResultBreak ;
292321 }
0 commit comments