Skip to content

Commit 615fdec

Browse files
committed
refactor: get rid of the duplicate markThatNeedsToApply tomfoolery
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
1 parent 733064b commit 615fdec

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

apply.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,19 @@ const defaultApplyAction: ActionInsideEachCheckedOutBranch = async ({
6363
export const getBackupPathOfPreviousStackedRebase = (pathToStackedRebaseDirInsideDotGit: string): string =>
6464
pathToStackedRebaseDirInsideDotGit + ".previous";
6565

66-
export type ReturnOfApplyIfNeedsToApply = {
67-
markThatNeedsToApply: () => void;
68-
} & (
66+
export type ReturnOfApplyIfNeedsToApply =
6967
| {
7068
neededToApply: false;
7169
userAllowedToApplyAndWeApplied?: never;
7270
}
7371
| {
7472
neededToApply: true;
7573
userAllowedToApplyAndWeApplied: false;
76-
// markThatNeedsToApply?: never; // TODO TS infer auto - force code owner to exit
7774
}
7875
| {
7976
neededToApply: true;
8077
userAllowedToApplyAndWeApplied: true;
81-
}
82-
);
78+
};
8379
export async function applyIfNeedsToApply({
8480
repo,
8581
pathToStackedRebaseTodoFile,
@@ -92,16 +88,12 @@ export async function applyIfNeedsToApply({
9288
config: Git.Config;
9389
}): Promise<ReturnOfApplyIfNeedsToApply> {
9490
const needsToApply: boolean = doesNeedToApply(pathToStackedRebaseDirInsideDotGit);
95-
const _markThatNeedsToApply = (): void => markThatNeedsToApply(pathToStackedRebaseDirInsideDotGit);
9691

9792
if (!needsToApply) {
9893
return {
9994
neededToApply: false,
100-
markThatNeedsToApply: _markThatNeedsToApply,
10195
};
102-
}
103-
104-
if (needsToApply) {
96+
} else {
10597
if (!autoApplyIfNeeded) {
10698
const question = createQuestion();
10799

@@ -119,7 +111,6 @@ export async function applyIfNeedsToApply({
119111
return {
120112
neededToApply: true,
121113
userAllowedToApplyAndWeApplied: false,
122-
markThatNeedsToApply: _markThatNeedsToApply,
123114
};
124115
}
125116

@@ -139,7 +130,6 @@ export async function applyIfNeedsToApply({
139130
return {
140131
neededToApply: true,
141132
userAllowedToApplyAndWeApplied: true, //
142-
markThatNeedsToApply: _markThatNeedsToApply,
143133
};
144134
}
145135

@@ -219,9 +209,7 @@ const doesNeedToApply = (pathToStackedRebaseDirInsideDotGit: string): boolean =>
219209
return needsToApplyPart2;
220210
};
221211

222-
export function readRewrittenListNotAppliedOrAppliedOrError(
223-
repoPath: string
224-
): {
212+
export function readRewrittenListNotAppliedOrAppliedOrError(repoPath: string): {
225213
pathOfRewrittenList: string;
226214
pathOfRewrittenListApplied: string;
227215
rewrittenListRaw: string;
@@ -243,9 +231,7 @@ export function readRewrittenListNotAppliedOrAppliedOrError(
243231
} else if (fs.existsSync(pathOfRewrittenListApplied)) {
244232
rewrittenListRaw = fs.readFileSync(pathOfRewrittenListApplied, { encoding: "utf-8" });
245233
} else {
246-
throw new Error(
247-
`rewritten-list not found neither in ${pathOfRewrittenList}, nor in ${pathOfRewrittenListApplied}`
248-
);
234+
throw new Error(`rewritten-list not found neither in ${pathOfRewrittenList}, nor in ${pathOfRewrittenListApplied}`);
249235
}
250236

251237
const { combinedRewrittenList } = combineRewrittenLists(rewrittenListRaw);

git-stacked-rebase.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
parseOptions,
2424
SomeOptionsForGitStackedRebase,
2525
} from "./options";
26-
import { apply, applyIfNeedsToApply, markThatNeedsToApply as _markThatNeedsToApply } from "./apply";
26+
import { apply, applyIfNeedsToApply, markThatNeedsToApply } from "./apply";
2727
import { forcePush } from "./forcePush";
2828
import { BehaviorOfGetBranchBoundaries, branchSequencer } from "./branchSequencer";
2929
import { autosquash } from "./autosquash";
@@ -87,7 +87,7 @@ export async function gitStackedRebase(
8787
const currentBranch: Git.Reference = await repo.getCurrentBranch();
8888

8989
if (fs.existsSync(path.join(pathToStackedRebaseDirInsideDotGit, filenames.willNeedToApply))) {
90-
_markThatNeedsToApply(pathToStackedRebaseDirInsideDotGit);
90+
markThatNeedsToApply(pathToStackedRebaseDirInsideDotGit);
9191
}
9292

9393
if (options.apply) {
@@ -133,7 +133,7 @@ export async function gitStackedRebase(
133133
return;
134134
}
135135

136-
const { neededToApply, userAllowedToApplyAndWeApplied, markThatNeedsToApply } = await applyIfNeedsToApply({
136+
const { neededToApply, userAllowedToApplyAndWeApplied } = await applyIfNeedsToApply({
137137
repo,
138138
pathToStackedRebaseTodoFile,
139139
pathToStackedRebaseDirInsideDotGit, //
@@ -636,7 +636,7 @@ mv -f "${preparedRegularRebaseTodoFile}" "${pathToRegularRebaseTodoFile}"
636636

637637
fs.unlinkSync(path.join(pathToStackedRebaseDirInsideDotGit, filenames.willNeedToApply));
638638
if (rebaseChangedLocalHistory) {
639-
markThatNeedsToApply();
639+
markThatNeedsToApply(pathToStackedRebaseDirInsideDotGit);
640640
} else {
641641
// /**
642642
// * TODO `unmarkThatNeedsToApply` (NOT the same as `markThatApplied`!)

0 commit comments

Comments
 (0)