Skip to content

Commit 084bbf5

Browse files
committed
replace the command names in the git-rebase-todo file as well (keep in sync / source of truth)
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
1 parent 8850786 commit 084bbf5

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

git-stacked-rebase.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = () => {};
@@ -592,18 +593,37 @@ export const gitStackedRebase = async (
592593
await repo.checkoutBranch(newLatestBranchCmd.targets![0]);
593594

594595
/**
595-
* TODO update in the actual `git-rebase-todo` file
596+
* need to change to "branch-end", instead of "branch-end-new",
597+
* since obviously the branch already exists
596598
*/
599+
oldLatestBranchCmd.commandName = "branch-end";
600+
oldLatestBranchCmd.commandOrAliasName = "branch-end";
601+
602+
newLatestBranchCmd.commandName = "branch-end-last";
603+
newLatestBranchCmd.commandOrAliasName = "branch-end-last";
597604

598605
/**
599-
* need to change to "branch-end", instead of "branch-end-new",
600-
* since obviously the branch already exists
606+
* TODO FIXME don't do this so hackishly lmao
601607
*/
602-
goodCommands[oldLatestBranchCmdIndex].commandName = "branch-end";
603-
goodCommands[oldLatestBranchCmdIndex].commandOrAliasName = "branch-end";
608+
const editedRebaseTodo: string = fs.readFileSync(pathToStackedRebaseTodoFile, { encoding: "utf-8" });
609+
const linesOfEditedRebaseTodo: string[] = editedRebaseTodo.split("\n");
610+
611+
replaceCommandInText(oldLatestBranchCmd, "branch-end-last", "branch-end");
612+
replaceCommandInText(newLatestBranchCmd, "branch-end-new", "branch-end-last");
613+
614+
// eslint-disable-next-line no-inner-declarations
615+
function replaceCommandInText(
616+
cmd: GoodCommandStacked, //
617+
expectedOldName: StackedRebaseEitherCommandOrAlias,
618+
newName: StackedRebaseCommand
619+
): void {
620+
const words = linesOfEditedRebaseTodo[cmd.lineNumber].split(" ");
621+
assert.equal(words[0], expectedOldName);
622+
words[0] = newName;
623+
linesOfEditedRebaseTodo[oldLatestBranchCmd.lineNumber] = words.join(" ");
624+
}
604625

605-
goodCommands[newLatestBranchCmdIndex].commandName = "branch-end-last";
606-
goodCommands[newLatestBranchCmdIndex].commandOrAliasName = "branch-end-last";
626+
fs.writeFileSync(pathToStackedRebaseTodoFile, linesOfEditedRebaseTodo.join("\n"), { encoding: "utf-8" });
607627

608628
/**
609629
* it's fine if the new "latest branch" does not have

parse-todo-of-stacked-rebase/validator.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export const regularRebaseCommands = {
144144
} as const;
145145

146146
export type RegularRebaseCommand = keyof typeof regularRebaseCommands;
147+
export type RegularRebaseEitherCommandOrAlias = RegularRebaseCommand | RegularRebaseCommandAlias;
147148

148149
/**
149150
* TODO: assert each value is `RegularRebaseCommand`,
@@ -227,8 +228,12 @@ const stackedRebaseCommandAliases = {
227228
ben: "branch-end-new",
228229
} as const;
229230

230-
type StackedRebaseCommandAlias = keyof typeof stackedRebaseCommandAliases;
231+
export type StackedRebaseCommandAlias = keyof typeof stackedRebaseCommandAliases;
232+
export type StackedRebaseEitherCommandOrAlias = StackedRebaseCommand | StackedRebaseCommandAlias;
231233

234+
/**
235+
* combined
236+
*/
232237
export type EitherRebaseCommand = RegularRebaseCommand | StackedRebaseCommand;
233238
export type EitherRebaseCommandAlias = RegularRebaseCommandAlias | StackedRebaseCommandAlias;
234239

0 commit comments

Comments
 (0)