@@ -244,13 +244,88 @@ export const gitStackedRebase = async (
244244 console . log ( { wasRegularRebaseInProgress } ) ;
245245
246246 if ( ! wasRegularRebaseInProgress ) {
247- await createInitialEditTodoOfGitStackedRebase (
247+ // await createInitialEditTodoOfGitStackedRebase(
248+ // repo, //
249+ // initialBranch,
250+ // currentBranch,
251+ // // __default__pathToStackedRebaseTodoFile
252+ // pathToStackedRebaseTodoFile
253+ // );
254+
255+ const referenceToOid = ( ref : Git . Reference ) : Promise < Git . Oid > =>
256+ ref . peel ( Git . Object . TYPE . COMMIT ) . then ( ( x ) => x . id ( ) ) ;
257+
258+ // const commitOfInitialBranch: Git.Oid = await referenceToOid(bb);
259+ const commitOfInitialBranch : Git . Oid = await referenceToOid ( initialBranch ) ;
260+ const commitOfCurrentBranch : Git . Oid = await referenceToOid ( currentBranch ) ;
261+
262+ // https://stackoverflow.com/a/1549155/9285308
263+ const latestCommitOfOursThatInitialBranchAlreadyHas : Git . Oid = await Git . Merge . base (
248264 repo , //
249- initialBranch ,
250- currentBranch ,
251- // __default__pathToStackedRebaseTodoFile
252- pathToStackedRebaseTodoFile
265+ commitOfInitialBranch ,
266+ commitOfCurrentBranch
253267 ) ;
268+
269+ const editorScript = `\
270+ #!/usr/bin/env bash
271+
272+ printf "yes sir\n\n"
273+
274+ pushd "${ dotGitDirPath } "
275+
276+ printf "pwd: $(pwd)\n"
277+
278+ # cat rebase-merge/git-rebase-todo
279+ cat ${ pathToRegularRebaseTodoFile }
280+
281+ # cat ${ pathToRegularRebaseTodoFile } > ${ pathToStackedRebaseTodoFile } .regular
282+ cp -r ${ pathToRegularRebaseDirInsideDotGit } ${ pathToRegularRebaseDirInsideDotGit } .bp
283+
284+ # abort the rebase before even starting it
285+ exit 1
286+ ` ;
287+ const editorScriptPath : string = path . join ( dotGitDirPath , "editorScript.sh" ) ;
288+ fs . writeFileSync ( editorScriptPath , editorScript , { mode : 0o777 } ) ;
289+
290+ try {
291+ execSyncInRepo (
292+ [
293+ options . gitCmd ,
294+ "rebase" ,
295+ "--interactive" ,
296+ latestCommitOfOursThatInitialBranchAlreadyHas . tostrS ( ) ,
297+ "--onto" ,
298+ initialBranch . name ( ) ,
299+ ">/dev/null 2>&1" ,
300+ ] . join ( " " ) ,
301+ {
302+ env : {
303+ // https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt-sequenceeditor
304+ GIT_SEQUENCE_EDITOR : editorScriptPath ,
305+ } ,
306+ }
307+ ) ;
308+ } catch ( e ) {
309+ // as expected. do nothing.
310+ // TODO verify that it actually came from our script exiting intentionally
311+ }
312+
313+ console . log ( "rebase -i exited" ) ;
314+
315+ const [ _exit , goodRegularCommands ] = parseTodoOfStackedRebase (
316+ path . join ( pathToRegularRebaseDirInsideDotGit + ".bp" , filenames . gitRebaseTodo )
317+ ) ;
318+
319+ console . log ( "parsedRegular: %O" , _exit , goodRegularCommands ) ;
320+
321+ execSyncInRepo ( "read" ) ;
322+
323+ /**
324+ * TODO - would now have to use the logic from `getWantedCommitsWithBranchBoundaries`
325+ * & subsequent utils, though adapted differently - we already have the commits,
326+ * now we gotta add the branch boundaries & then continue like regular.
327+ *
328+ */
254329 }
255330
256331 if ( ! wasRegularRebaseInProgress || options . viewTodoOnly ) {
@@ -672,6 +747,7 @@ export function removeUndefinedProperties<T, K extends keyof Partial<T>>(
672747 ) ;
673748}
674749
750+ noop ( createInitialEditTodoOfGitStackedRebase ) ;
675751async function createInitialEditTodoOfGitStackedRebase (
676752 repo : Git . Repository , //
677753 initialBranch : Git . Reference ,
0 commit comments