Skip to content

Commit

Permalink
refactor: extract filenames into object instead of using raw strings
Browse files Browse the repository at this point in the history
Signed-off-by: Kipras Melnikovas <[email protected]>
kiprasmel committed Dec 22, 2021
1 parent e756d0a commit a673aa3
Showing 5 changed files with 24 additions and 8 deletions.
6 changes: 4 additions & 2 deletions apply.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import Git from "nodegit";
import { createQuestion } from "./util/createQuestion";
import { noop } from "./util/noop";

import { filenames } from "./filenames";
import { configKeys } from "./configKeys";
import {
BranchSequencerBase, //
@@ -107,10 +108,11 @@ const getPathOfFilenameOfNeedsToApply = (pathToStackedRebaseDirInsideDotGit: str
export const unmarkThatNeedsToApply = (
pathToStackedRebaseDirInsideDotGit: string,
mark = getPathOfFilenameOfNeedsToApply(pathToStackedRebaseDirInsideDotGit),
rewrittenListFile: string = path.join(pathToStackedRebaseDirInsideDotGit, "rewritten-list")
rewrittenListFile: string = path.join(pathToStackedRebaseDirInsideDotGit, filenames.rewrittenList),
rewrittenListAppliedFile: string = path.join(pathToStackedRebaseDirInsideDotGit, filenames.rewrittenListApplied)
): void => (
fs.existsSync(mark) && fs.unlinkSync(mark),
fs.existsSync(rewrittenListFile) && fs.renameSync(rewrittenListFile, rewrittenListFile + ".applied"),
fs.existsSync(rewrittenListFile) && fs.renameSync(rewrittenListFile, rewrittenListAppliedFile),
void 0
);

6 changes: 4 additions & 2 deletions branchSequencer.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import assert from "assert";

import Git from "nodegit";

import { filenames } from "./filenames";

import { createExecSyncInRepo } from "./util/execSyncInRepo";
import { EitherExitFinal, fail } from "./util/Exitable";

@@ -52,7 +54,7 @@ export type BranchSequencerArgs = BranchSequencerArgsBase & {
actionInsideEachCheckedOutBranch: ActionInsideEachCheckedOutBranch;
delayMsBetweenCheckouts?: number;
callbackAfterDone?: CallbackAfterDone;
rewrittenListFile?: "rewritten-list" | "rewritten-list.applied";
rewrittenListFile?: typeof filenames.rewrittenList | typeof filenames.rewrittenListApplied;
};

export type BranchSequencerBase = (args: BranchSequencerArgsBase) => Promise<EitherExitFinal>;
@@ -68,7 +70,7 @@ export const branchSequencer: BranchSequencer = async ({
// callbackBeforeBegin,
actionInsideEachCheckedOutBranch,
callbackAfterDone = (): void => {},
rewrittenListFile = "rewritten-list",
rewrittenListFile = filenames.rewrittenList,
}) => {
if (!fs.existsSync(pathToStackedRebaseDirInsideDotGit)) {
return fail(`\n\nno stacked-rebase in progress? (nothing to ${rootLevelCommandName})\n\n`);
10 changes: 10 additions & 0 deletions filenames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* both their & ours.
*/
export const filenames = {
rewrittenList: "rewritten-list",
rewrittenListApplied: "rewritten-list.applied",
/**
* TODO extract others into here
*/
} as const;
7 changes: 4 additions & 3 deletions git-stacked-rebase.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import path from "path";
import assert from "assert";
import { bullets } from "nice-comment";

import { filenames } from "./filenames";
import { configKeys } from "./configKeys";
import { apply, applyIfNeedsToApply } from "./apply";
import { forcePush } from "./forcePush";
@@ -415,10 +416,10 @@ export const gitStackedRebase = async (
#DIR="\${BASH_SOURCE[0]}"
#REBASE_MERGE_DIR="$(realpath "$DIR/../rebase-merge")"
REBASE_MERGE_DIR="$(pwd)/.git/rebase-merge"
REWRITTEN_LIST_FILE_PATH="$REBASE_MERGE_DIR/rewritten-list"
REWRITTEN_LIST_FILE_PATH="$REBASE_MERGE_DIR/${filenames.rewrittenList}"
STACKED_REBASE_DIR="$(pwd)/.git/stacked-rebase"
REWRITTEN_LIST_BACKUP_FILE_PATH="$STACKED_REBASE_DIR/rewritten-list"
REWRITTEN_LIST_BACKUP_FILE_PATH="$STACKED_REBASE_DIR/${filenames.rewrittenList}"
#echo "REBASE_MERGE_DIR $REBASE_MERGE_DIR; STACKED_REBASE_DIR $STACKED_REBASE_DIR;"
@@ -549,7 +550,7 @@ cat "$REWRITTEN_LIST_FILE_PATH" > "$REWRITTEN_LIST_BACKUP_FILE_PATH"
*
*/
const canAndShouldBeApplying: boolean =
/** part 1 */ fs.existsSync(path.join(pathToStackedRebaseDirInsideDotGit, "rewritten-list")) &&
/** part 1 */ fs.existsSync(path.join(pathToStackedRebaseDirInsideDotGit, filenames.rewrittenList)) &&
/** part 2 (incomplete?) */ !fs.existsSync(pathToRegularRebaseDirInsideDotGit) &&
/** part 2 (complete?) (is this even needed?) */ goodCommands.every(
(cmd) => !namesOfRebaseCommandsThatMakeRebaseExitToPause.includes(cmd.commandName)
3 changes: 2 additions & 1 deletion parse-todo-of-stacked-rebase/parseNewGoodCommands.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import assert from "assert";
import Git from "nodegit";
import { array } from "nice-comment";

import { filenames } from "../filenames";
import { EitherExit, fail, succ } from "../util/Exitable";

import { parseTodoOfStackedRebase } from "./parseTodoOfStackedRebase";
@@ -15,7 +16,7 @@ import { GoodCommand, stackedRebaseCommands } from "./validator";
export function parseNewGoodCommands(
repo: Git.Repository,
pathToStackedRebaseTodoFile: string, //
rewrittenListFile: "rewritten-list" | "rewritten-list.applied"
rewrittenListFile: typeof filenames.rewrittenList | typeof filenames.rewrittenListApplied
): EitherExit<GoodCommand[]> {
const [exit, goodCommands] = parseTodoOfStackedRebase(pathToStackedRebaseTodoFile);
if (!goodCommands) return fail(exit);

0 comments on commit a673aa3

Please sign in to comment.