@@ -227,6 +227,15 @@ export type BranchSequencerArgs = BranchSequencerArgsBase & {
227227 actionInsideEachCheckedOutBranch : ActionInsideEachCheckedOutBranch ;
228228 delayMsBetweenCheckouts ?: number ;
229229 behaviorOfGetBranchBoundaries ?: Parameters < typeof pickBoundaryParser > [ 0 ] [ "behaviorOfGetBranchBoundaries" ] ;
230+
231+ /**
232+ * normally, you checkout to the 1st partial branch in the stack,
233+ * then the 2nd, etc, up until you reach the latest branch.
234+ *
235+ * use `reverseCheckoutOrder` to do the opposite.
236+ *
237+ */
238+ reverseCheckoutOrder : boolean ;
230239} ;
231240
232241export type BranchSequencerBase = ( args : BranchSequencerArgsBase ) => Promise < void > ;
@@ -245,6 +254,8 @@ export const branchSequencer: BranchSequencer = async ({
245254 behaviorOfGetBranchBoundaries = defaultGetBranchBoundariesBehavior ,
246255 initialBranch,
247256 currentBranch,
257+ //
258+ reverseCheckoutOrder = false ,
248259} ) => {
249260 const execSyncInRepo = createExecSyncInRepo ( repo ) ;
250261
@@ -261,6 +272,10 @@ export const branchSequencer: BranchSequencer = async ({
261272 initialBranch,
262273 currentBranch,
263274 } ) ;
275+ if ( reverseCheckoutOrder ) {
276+ branchesAndCommits . reverse ( ) ;
277+ }
278+ const originalBoundariesLength : number = branchesAndCommits . length ;
264279
265280 return checkout ( branchesAndCommits . slice ( 1 ) as any ) ; // TODO TS
266281
@@ -269,7 +284,7 @@ export const branchSequencer: BranchSequencer = async ({
269284 return ;
270285 }
271286
272- console . log ( "\ncheckout" , boundaries . length ) ;
287+ console . log ( "\ncheckout" , boundaries . length , reverseCheckoutOrder ? "(reversed)" : "" ) ;
273288
274289 const goNext = ( ) =>
275290 new Promise < void > ( ( r ) => {
@@ -341,7 +356,9 @@ export const branchSequencer: BranchSequencer = async ({
341356
342357 // console.log({ targetCommitSHA, target: targetBranch });
343358
344- const isLatestBranch : boolean = boundaries . length === 1 ;
359+ const isLatestBranch : boolean = reverseCheckoutOrder
360+ ? boundaries . length === originalBoundariesLength
361+ : boundaries . length === 1 ;
345362
346363 /**
347364 * https://libgit2.org/libgit2/#HEAD/group/checkout/git_checkout_head
0 commit comments