@@ -26,6 +26,7 @@ import {
2626 GoodCommandStacked , //
2727 namesOfRebaseCommandsThatMakeRebaseExitToPause ,
2828 StackedRebaseCommand ,
29+ StackedRebaseEitherCommandOrAlias ,
2930} from "./parse-todo-of-stacked-rebase/validator" ;
3031
3132// console.log = () => {};
@@ -595,8 +596,8 @@ export const gitStackedRebase = async (
595596 * update the commands
596597 * TODO update in the actual `git-rebase-todo` file
597598 */
598- // swapKeys(goodCommands[oldLatestBranchCmdIndex], goodCommands[newLatestBranchCmdIndex] , "commandName");
599- // swapKeys(goodCommands[oldLatestBranchCmdIndex], goodCommands[newLatestBranchCmdIndex] , "commandOrAliasName"); // eslint-disable-line prettier/prettier
599+ // swapKeys(oldLatestBranchCmd, newLatestBranchCmd , "commandName");
600+ // swapKeys(oldLatestBranchCmd, newLatestBranchCmd , "commandOrAliasName"); // eslint-disable-line prettier/prettier
600601
601602 // // eslint-disable-next-line no-inner-declarations
602603 // function swapKeys<T>(A: T, B: T, key: keyof T): void {
@@ -607,11 +608,47 @@ export const gitStackedRebase = async (
607608 * need to change to "branch-end", instead of "branch-end-new",
608609 * since obviously the branch already exists
609610 */
610- goodCommands [ oldLatestBranchCmdIndex ] . commandName = "branch-end" ;
611- goodCommands [ oldLatestBranchCmdIndex ] . commandOrAliasName = "branch-end" ;
611+ oldLatestBranchCmd . commandName = "branch-end" ;
612+ oldLatestBranchCmd . commandOrAliasName = "branch-end" ;
612613
613- goodCommands [ newLatestBranchCmdIndex ] . commandName = "branch-end-last" ;
614- goodCommands [ newLatestBranchCmdIndex ] . commandOrAliasName = "branch-end-last" ;
614+ newLatestBranchCmd . commandName = "branch-end-last" ;
615+ newLatestBranchCmd . commandOrAliasName = "branch-end-last" ;
616+
617+ /**
618+ * TODO FIXME don't do this so hackishly lmao
619+ */
620+ const editedRebaseTodo : string = fs . readFileSync ( pathToStackedRebaseTodoFile , { encoding : "utf-8" } ) ;
621+ const linesOfEditedRebaseTodo : string [ ] = editedRebaseTodo . split ( "\n" ) ;
622+
623+ /**
624+ * replace the "branch-end-last" with "branch-end"
625+ */
626+ // const oldLineBefore = linesOfEditedRebaseTodo[oldLatestBranchCmd.lineNumber].split(" ");
627+ // assert.equal(oldLineBefore[0], "branch-end-last");
628+ // oldLineBefore.splice(0, 1, "branch-end"); // remove 1st word ("branch-end-last") and add "branch-end"
629+ // linesOfEditedRebaseTodo[oldLatestBranchCmd.lineNumber] = oldLineBefore.join(" ");
630+
631+ // const newLineBefore = linesOfEditedRebaseTodo[newLatestBranchCmd.lineNumber].split(" ");
632+ // assert.equal(newLineBefore[0], "branch-end-new");
633+ // newLineBefore.splice(0, 1, "branch-end-last"); // remove 1st word ("branch-end") and add "branch-end-last"
634+ // linesOfEditedRebaseTodo[newLatestBranchCmd.lineNumber] = newLineBefore.join(" ");
635+
636+ replaceCommandInText ( oldLatestBranchCmd , "branch-end-last" , "branch-end" ) ;
637+ replaceCommandInText ( newLatestBranchCmd , "branch-end-new" , "branch-end-last" ) ;
638+
639+ // eslint-disable-next-line no-inner-declarations
640+ function replaceCommandInText (
641+ cmd : GoodCommandStacked , //
642+ expectedOldName : StackedRebaseEitherCommandOrAlias ,
643+ newName : StackedRebaseCommand
644+ ) : void {
645+ const words = linesOfEditedRebaseTodo [ cmd . lineNumber ] . split ( " " ) ;
646+ assert . equal ( words [ 0 ] , expectedOldName ) ;
647+ words [ 0 ] = newName ;
648+ linesOfEditedRebaseTodo [ oldLatestBranchCmd . lineNumber ] = words . join ( " " ) ;
649+ }
650+
651+ fs . writeFileSync ( pathToStackedRebaseTodoFile , linesOfEditedRebaseTodo . join ( "\n" ) , { encoding : "utf-8" } ) ;
615652
616653 /**
617654 * it's fine if the new "latest branch" does not have
0 commit comments