Skip to content

Commit f21ae8a

Browse files
committed
feat: --continue
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
1 parent 3d3b21f commit f21ae8a

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

git-stacked-rebase.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type OptionsForGitStackedRebase = {
4141

4242
viewTodoOnly: boolean;
4343
apply: boolean;
44+
continue: boolean;
4445
push: boolean;
4546
forcePush: boolean;
4647

@@ -61,6 +62,7 @@ export const getDefaultOptions = (): OptionsForGitStackedRebase => ({
6162
gitCmd: process.env.GIT_CMD ?? defaultGitCmd,
6263
viewTodoOnly: false,
6364
apply: false,
65+
continue: false,
6466
push: false,
6567
forcePush: false,
6668
branchSequencer: false,
@@ -73,6 +75,7 @@ function areOptionsIncompetible(
7375
): boolean {
7476
if (options.viewTodoOnly) {
7577
if (options.apply) reasons.push("--apply cannot be used together with --view-todo");
78+
if (options.continue) reasons.push("--continue cannot be used together with --view-todo");
7679
if (options.push) reasons.push("--push cannot be used together with --view-todo");
7780
if (options.forcePush) reasons.push("--push --force cannot be used together with --view-todo");
7881
if (options.branchSequencer) reasons.push("--branch-sequencer cannot be used together with --view-todo");
@@ -284,6 +287,8 @@ export const gitStackedRebase = async (
284287
const pathToStackedRebaseDirInsideDotGit: string = parsed.pathToStackedRebaseDirInsideDotGit;
285288
const pathToStackedRebaseTodoFile: string = parsed.pathToStackedRebaseTodoFile;
286289

290+
const checkIsRegularRebaseStillInProgress = (): boolean => fs.existsSync(pathToRegularRebaseDirInsideDotGit);
291+
287292
if (fs.existsSync(path.join(pathToStackedRebaseDirInsideDotGit, filenames.willNeedToApply))) {
288293
_markThatNeedsToApply(pathToStackedRebaseDirInsideDotGit);
289294
}
@@ -298,6 +303,35 @@ export const gitStackedRebase = async (
298303
});
299304
}
300305

306+
if (options.continue) {
307+
execSyncInRepo(`${options.gitCmd} rebase --continue`);
308+
309+
if (checkIsRegularRebaseStillInProgress()) {
310+
/**
311+
* still not done - further `--continue`s will be needed.
312+
*/
313+
return;
314+
}
315+
316+
console.log("after --continue, rebase done. trying to --apply");
317+
318+
/**
319+
* rebase has finished. we can try to --apply now
320+
* so that the partial branches do not get out of sync.
321+
*/
322+
await applyIfNeedsToApply({
323+
repo,
324+
pathToStackedRebaseTodoFile,
325+
pathToStackedRebaseDirInsideDotGit, //
326+
rootLevelCommandName: "--apply (automatically after --continue)",
327+
gitCmd: options.gitCmd,
328+
autoApplyIfNeeded: configValues.autoApplyIfNeeded,
329+
config,
330+
});
331+
332+
return;
333+
}
334+
301335
const { neededToApply, userAllowedToApplyAndWeApplied, markThatNeedsToApply } = await applyIfNeedsToApply({
302336
repo,
303337
pathToStackedRebaseTodoFile,
@@ -357,7 +391,7 @@ export const gitStackedRebase = async (
357391
);
358392
const currentBranch: Git.Reference = await repo.getCurrentBranch();
359393

360-
const wasRegularRebaseInProgress: boolean = fs.existsSync(pathToRegularRebaseDirInsideDotGit);
394+
const wasRegularRebaseInProgress: boolean = checkIsRegularRebaseStillInProgress();
361395
// const
362396

363397
console.log({ wasRegularRebaseInProgress });
@@ -1349,6 +1383,16 @@ git-stacked-rebase <branch> [-a|--apply]
13491383
2. but wil not push the partial branches to a remote until --push --force is used.
13501384
13511385
1386+
git-stacked-rebase <branch> [-c|--continue]
1387+
1388+
(!) should be used instead of git-rebase's --continue
1389+
1390+
...because, additionally to invoking git rebase --continue,
1391+
this option automatically (prompts you to) --apply (if the rebase
1392+
has finished), thus ensuring that the partial branches
1393+
do not go out of sync with the newly rewritten history.
1394+
1395+
13521396
git-stacked-rebase <branch> [--push|-p --force|-f]
13531397
13541398
1. will checkout each branch and will push --force,
@@ -1454,10 +1498,11 @@ git-stacked-rebase ${gitStackedRebaseVersionStr} __BUILD_DATE_REPLACEMENT_STR__
14541498
const isViewTodoOnly: boolean =
14551499
!!second && ["--view-todo", "-v", "--view-only", "--view-todo-only"].includes(second);
14561500
const isApply: boolean = !!second && ["--apply", "-a"].includes(second);
1501+
const isContinue: boolean = !!second && ["--continue", "-c"].includes(second);
14571502
const isPush: boolean = !!second && ["--push", "-p"].includes(second);
14581503
const isBranchSequencer: boolean = !!second && ["--branch-sequencer", "--bs", "-s"].includes(second);
14591504

1460-
if (isViewTodoOnly || isApply || isPush || isBranchSequencer) {
1505+
if (isViewTodoOnly || isContinue || isApply || isPush || isBranchSequencer) {
14611506
eatNextArg();
14621507
}
14631508

@@ -1507,6 +1552,7 @@ git-stacked-rebase ${gitStackedRebaseVersionStr} __BUILD_DATE_REPLACEMENT_STR__
15071552
gitDir,
15081553
viewTodoOnly: isViewTodoOnly,
15091554
apply: isApply,
1555+
continue: isContinue,
15101556
push: isPush,
15111557
forcePush: isForcePush,
15121558
branchSequencer: isBranchSequencer,

0 commit comments

Comments
 (0)