@@ -87,6 +87,115 @@ function areOptionsIncompetible(
8787 return reasons . length > 0 ;
8888}
8989
90+ /**
91+ * some notes:
92+ *
93+ * 1. re: "the different ways to launch git rebase":
94+ *
95+ * 1.1 initially, we started probably the hardest way:
96+ * we tried to replicate the behavior of git rebase, by:
97+ *
98+ * 1) finding which commits we need (manually by ourselves),
99+ * 2) letting the user edit our own git-rebase-todo file
100+ * (already containing branch boundaries generated by us),
101+ * 3) creating & writing to files inside `.git/rebase-{merge|apply}/`,
102+ * just like git rebase would, to represent the current state [1].
103+ * 4) and then exec'ing a `git rebase --continue`,
104+ * so that the user gets launched into the rebase.
105+ *
106+ *
107+ * 1.2 later, we started using 2 rebases - 1st for finding the commits, 2nd for the actual rebase.
108+ *
109+ * important switch that i didn't think had significance until 1.3 --
110+ * using `editorScript`s (providing an env var - a string of a path to a bash script
111+ * that will move the user-edited & our-processed git-rebase-todo file
112+ * into the proper place (.git/rebase-{merge|apply}/git-rebase-todo)
113+ * right when the rebase starts, thus no longer having to `--continue` (!),
114+ * which is what broke things that were discovered
115+ * and fixed in 1.3 by (fabricately) introducing `--continue` back)
116+ *
117+ *
118+ * 1.3 but soon after, things started breaking.
119+ *
120+ * i didn't understand why.
121+ *
122+ * but after playing w/ it for a while, realized that it's stuff like `reword`
123+ * that breaks, as long as we launch the rebase with an `editorScript`.
124+ * e.g. git would ask to identify yourself - config wouldn't be detected,
125+ * and our `--apply` was completely broken as well [2].
126+ *
127+ * thus we started manually adding a first command `break`
128+ * into the proper `git-rebase-todo` file [3]
129+ * so that we can launch `--continue` again,
130+ * after the `editorScript` had finished,
131+ * and that somehow fixed everything & we're back to normal.
132+ *
133+ *
134+ *
135+ * i am still not sure what the best approach is,
136+ * though i think i know which one's aren't.
137+ *
138+ * 1.1 seems bad because imitating the full behavior is hard,
139+ *
140+ * e.g. respecting commit.gpgSign required creating a file `gpg_sign_opt`
141+ * with content `-S` - there's probably a ton of stuff like this i didn't even realize
142+ * that git has, and it's possible more will be added in the future.
143+ * you can obviously see the problems that stem from this.
144+ *
145+ * 1.2 seems bad because it, apart from being broken until 1.3,
146+ * also used 2 rebases instead of 1, and that is kinda hacky.
147+ * stuff like git hooks exists, e.g. post-write,
148+ * that even we ourselves utilize,
149+ * and launching 2 rebases means producing side-effects
150+ * like this, and we're potentially breaking end users' workflows.
151+ *
152+ * thus, 1.3 seems like a clear winner, at least for now.
153+ * especially up until we investigate the break + continue thingie -
154+ * ideally we wouldn't need it.
155+ *
156+ *
157+ *
158+ * ---
159+ *
160+ * [1]
161+ * on representing the _state_ -- git rebase,
162+ * specifically the --interactive one (which is what we have here as well),
163+ * is _not_ a continuous command that goes through and is 100% done when it exits.
164+ *
165+ * there are some cases where it intentionally exits, to allow the user
166+ * to do further interactions, and later --continue the rebase
167+ * (e.g. `edit`, `break` etc.).
168+ *
169+ * thus, some state needs to be saved, so that the user, once they're done,
170+ * can tell git to --continue.
171+ *
172+ * turns out, git does this very simply - by saving files inside `.git/`,
173+ * and `.git/rebase-{merge|apply}/` folders.
174+ * this simple design is a big part in allowing tools like us,
175+ * git-stacked-rebase, to work, or rather - to expand upon the existing stuff,
176+ * w/o having to re-implement everything ourselves.
177+ *
178+ * [2]
179+ * on the --apply being broken - it's the logic of `parseNewGoodCommands` that seems broken.
180+ *
181+ * right before realizing 1.3 and writing this comment,
182+ * i wrote a lengthy comment there as well, with thoughts of what's likely broken.
183+ *
184+ * but now, after discovering 1.3, i do not understand yet how the
185+ * `--continue` exec fixes things, and am not sure if i want to mess
186+ * with the `parseNewGoodCommands` logic before i do.
187+ *
188+ * [3]
189+ * the user would never see the `break` command, since just like in 1.1 2),
190+ * we give the user to edit our own git-rebase-todo file, which contains branch boundaries,
191+ * and then extracting the normal git rebase commands and creating
192+ * the git-rebase-todo file for git rebase to run on.
193+ *
194+ * ---
195+ *
196+ *
197+ *
198+ */
90199export const gitStackedRebase = async (
91200 nameOfInitialBranch : string ,
92201 specifiedOptions : SomeOptionsForGitStackedRebase = { }
@@ -293,6 +402,11 @@ export const gitStackedRebase = async (
293402 // let lastCommitFromEditedTodo;
294403 const regularRebaseTodoLines : string [ ] = [ ] ;
295404
405+ /**
406+ * part 1 of "the different ways to launch git rebase"
407+ */
408+ regularRebaseTodoLines . push ( "break" ) ;
409+
296410 const goodCommands : GoodCommand [ ] = parseTodoOfStackedRebase ( pathToStackedRebaseTodoFile ) ;
297411
298412 const proms : Promise < void > [ ] = goodCommands . map ( async ( cmd ) => {
@@ -587,6 +701,11 @@ mv -f "${preparedRegularRebaseTodoFile}" "${pathToRegularRebaseTodoFile}"
587701 ) ;
588702 console . log ( "big buns - the proper rebase returned" ) ;
589703
704+ /**
705+ * part 2 of "the different ways to launch git rebase"
706+ */
707+ execSyncInRepo ( `${ options . gitCmd } rebase --continue` ) ;
708+
590709 /** END COPY-PASTA */
591710
592711 /**
0 commit comments