@@ -13,6 +13,7 @@ import { filenames } from "./filenames";
1313import { configKeys } from "./configKeys" ;
1414import { apply , applyIfNeedsToApply } from "./apply" ;
1515import { forcePush } from "./forcePush" ;
16+ import { branchSequencer } from "./branchSequencer" ;
1617
1718import { createExecSyncInRepo } from "./util/execSyncInRepo" ;
1819import { noop } from "./util/noop" ;
@@ -40,6 +41,9 @@ export type OptionsForGitStackedRebase = {
4041 apply : boolean ;
4142 push : boolean ;
4243 forcePush : boolean ;
44+
45+ branchSequencer : boolean ;
46+ branchSequencerExec : string | false ;
4347} ;
4448
4549export type SomeOptionsForGitStackedRebase = Partial < OptionsForGitStackedRebase > ;
@@ -52,6 +56,8 @@ const getDefaultOptions = (): OptionsForGitStackedRebase => ({
5256 apply : false ,
5357 push : false ,
5458 forcePush : false ,
59+ branchSequencer : false ,
60+ branchSequencerExec : false ,
5561} ) ;
5662
5763function areOptionsIncompetible (
@@ -62,6 +68,8 @@ function areOptionsIncompetible(
6268 if ( options . apply ) reasons . push ( "--apply cannot be used together with --view-todo" ) ;
6369 if ( options . push ) reasons . push ( "--apply cannot be used together with --push" ) ;
6470 if ( options . forcePush ) reasons . push ( "--apply cannot be used together with --push -f" ) ;
71+ if ( options . branchSequencer ) reasons . push ( "--apply cannot be used together with --branch-sequencer" ) ;
72+ if ( options . branchSequencerExec ) reasons . push ( "--apply cannot be used together with --branch-sequencer --exec" ) ;
6573 }
6674
6775 /**
@@ -197,6 +205,28 @@ export const gitStackedRebase = async (
197205 } ) ;
198206 }
199207
208+ if ( options . branchSequencer ) {
209+ if ( options . branchSequencerExec ) {
210+ const toExec : string = options . branchSequencerExec ;
211+
212+ return branchSequencer ( {
213+ gitCmd : options . gitCmd ,
214+ repo,
215+ rootLevelCommandName : "--branch-sequencer --exec" ,
216+ actionInsideEachCheckedOutBranch : ( { execSyncInRepo : execS } ) => ( execS ( toExec ) , void 0 ) ,
217+ pathToStackedRebaseDirInsideDotGit,
218+ pathToStackedRebaseTodoFile,
219+ } ) ;
220+ } else {
221+ /**
222+ * we'll likely end up adding more sub-commands
223+ * to branchSequencer later.
224+ */
225+
226+ return fail ( "\n--branch-sequencer (without --exec) - nothing to do?\n\n" ) ;
227+ }
228+ }
229+
200230 fs . mkdirSync ( pathToStackedRebaseDirInsideDotGit , { recursive : true } ) ;
201231
202232 const initialBranch : Git . Reference | void = await Git . Branch . lookup (
@@ -1065,19 +1095,40 @@ git-stacked-rebase ${gitStackedRebaseVersionStr}
10651095 ! ! second && [ "--view-todo" , "-v" , "--view-only" , "--view-todo-only" ] . includes ( second ) ;
10661096 const isApply : boolean = ! ! second && [ "--apply" , "-a" ] . includes ( second ) ;
10671097 const isPush : boolean = ! ! second && [ "--push" , "-p" ] . includes ( second ) ;
1098+ const isBranchSequencer : boolean = ! ! second && [ "--branch-sequencer" , "--bs" , "-s" ] . includes ( second ) ;
10681099
1069- if ( isViewTodoOnly || isApply || isPush ) {
1100+ if ( isViewTodoOnly || isApply || isPush || isBranchSequencer ) {
10701101 eatNextArg ( ) ;
10711102 }
10721103
10731104 let isForcePush : boolean = false ;
1074- if ( isPush && peakNextArg ( ) ) {
1075- const fourth = eatNextArg ( ) || "" ;
1105+ let branchSequencerExec : string | false = false ;
1106+
1107+ if ( peakNextArg ( ) && ( isPush || isBranchSequencer ) ) {
1108+ const third = eatNextArg ( ) || "" ;
10761109
1077- isForcePush = [ "--force" , "-f" ] . includes ( fourth ) ;
1110+ if ( isPush ) {
1111+ isForcePush = [ "--force" , "-f" ] . includes ( third ) ;
1112+ } else if ( isBranchSequencer ) {
1113+ /**
1114+ * TODO separate --exec & --something
1115+ * 1. for execing only the next arg (must be quoted), and
1116+ * 2. for stopping arg parsing & execing everything afterwards (no quoting)
1117+ *
1118+ * TODO also allow selecting if want to exec before, after (or both) each branch
1119+ *
1120+ */
1121+ const execNames = [ "--exec" , "-x" ] ;
1122+ if ( execNames . includes ( third ) && peakNextArg ( ) ) {
1123+ const fourth = eatNextArg ( ) ;
1124+ branchSequencerExec = fourth ? fourth : false ;
1125+ } else {
1126+ return fail ( `\n--branch-sequencer can only (for now) be followed by ${ execNames . join ( "|" ) } \n\n` ) ;
1127+ }
1128+ }
10781129
1079- if ( ! isForcePush ) {
1080- return fail ( `\nunrecognized 4th option (after --push) ( got "${ fourth } ")\n\n` ) ;
1130+ if ( ! isForcePush && ! branchSequencerExec ) {
1131+ return fail ( `\nunrecognized 3th option (got "${ third } ")\n\n` ) ;
10811132 }
10821133 }
10831134
@@ -1096,6 +1147,8 @@ git-stacked-rebase ${gitStackedRebaseVersionStr}
10961147 apply : isApply ,
10971148 push : isPush ,
10981149 forcePush : isForcePush ,
1150+ branchSequencer : isBranchSequencer ,
1151+ branchSequencerExec,
10991152 } ;
11001153
11011154 // await
0 commit comments