Skip to content

Commit 7b35dcd

Browse files
committed
allow aliases too
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
1 parent 9b22f85 commit 7b35dcd

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

git-stacked-rebase.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import { uniq } from "./util/uniq";
2121
import { parseTodoOfStackedRebase } from "./parse-todo-of-stacked-rebase/parseTodoOfStackedRebase";
2222
import { Termination } from "./util/error";
2323
import { assertNever } from "./util/assertNever";
24+
import { Single, Tuple } from "./util/tuple";
2425
import {
2526
GoodCommand,
2627
GoodCommandStacked, //
2728
namesOfRebaseCommandsThatMakeRebaseExitToPause,
2829
StackedRebaseCommand,
29-
StackedRebaseEitherCommandOrAlias,
30+
StackedRebaseCommandAlias,
3031
} from "./parse-todo-of-stacked-rebase/validator";
3132

3233
// console.log = () => {};
@@ -607,17 +608,20 @@ export const gitStackedRebase = async (
607608
const editedRebaseTodo: string = fs.readFileSync(pathToStackedRebaseTodoFile, { encoding: "utf-8" });
608609
const linesOfEditedRebaseTodo: string[] = editedRebaseTodo.split("\n");
609610

610-
replaceCommandInText(oldLatestBranchCmd, "branch-end-last", "branch-end");
611-
replaceCommandInText(newLatestBranchCmd, "branch-end-new", "branch-end-last");
611+
replaceCommandInText(oldLatestBranchCmd, ["branch-end-last"], "branch-end");
612+
replaceCommandInText(newLatestBranchCmd, ["branch-end-new", "ben"], "branch-end-last");
612613

613614
// eslint-disable-next-line no-inner-declarations
614615
function replaceCommandInText(
615616
cmd: GoodCommandStacked, //
616-
expectedOldName: StackedRebaseEitherCommandOrAlias,
617+
allowedOldName: Single<StackedRebaseCommand> | Tuple<StackedRebaseCommand, StackedRebaseCommandAlias>,
617618
newName: StackedRebaseCommand
618619
): void {
619620
const words = linesOfEditedRebaseTodo[cmd.lineNumber].split(" ");
620-
assert.equal(words[0], expectedOldName);
621+
assert(
622+
allowedOldName.some((n) => n === words[0]),
623+
`invalid old name of command in git-rebase-todo file. got "${words[0]}", expected one of "${allowedOldName}".`
624+
);
621625
words[0] = newName;
622626
linesOfEditedRebaseTodo[oldLatestBranchCmd.lineNumber] = words.join(" ");
623627
}

util/tuple.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* ...because eslint >5 sucks
3+
*/
4+
5+
export type Single<A> = [A];
6+
export type ReadonlySingle<A> = readonly [A];
7+
8+
export type Tuple<A, B> = [A, B];
9+
export type ReadonlyTuple<A, B> = readonly [A, B];

0 commit comments

Comments
 (0)