Skip to content

Commit ee1b782

Browse files
committed
WIP multiple branches at commit
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
1 parent 5766d2c commit ee1b782

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

branchSequencer.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getWantedCommitsWithBranchBoundariesOurCustomImpl } from "./git-stacked
88
import { createExecSyncInRepo } from "./util/execSyncInRepo";
99
import { Termination } from "./util/error";
1010
import { assertNever } from "./util/assertNever";
11+
import { sequentialResolve } from "./util/sequentialResolve";
1112

1213
import { parseNewGoodCommands } from "./parse-todo-of-stacked-rebase/parseNewGoodCommands";
1314
import { GoodCommand, GoodCommandStacked } from "./parse-todo-of-stacked-rebase/validator";
@@ -25,7 +26,7 @@ export type GetBranchesCtx = BranchRefs & {
2526
};
2627
export type SimpleBranchAndCommit = {
2728
commitSHA: string | null;
28-
branchEndFullName: string;
29+
branchEndFullName: string[];
2930
// branchExistsYet: boolean; // TODO
3031
};
3132
export type GetBoundariesInclInitial = (
@@ -107,7 +108,7 @@ const getBoundariesInclInitialByParsingNotYetAppliedState: GetBoundariesInclInit
107108
.map(
108109
(cmd): SimpleBranchAndCommit => ({
109110
commitSHA: cmd.commitSHAThatBranchPointsTo,
110-
branchEndFullName: cmd.targets![0],
111+
branchEndFullName: [cmd.targets![0]],
111112
})
112113
);
113114
};
@@ -122,7 +123,7 @@ const getBoundariesInclInitialWithSipleBranchTraversal: GetBoundariesInclInitial
122123
.filter((b) => !!b.branchEnd)
123124
.map(
124125
(boundary): SimpleBranchAndCommit => ({
125-
branchEndFullName: boundary.branchEnd!.name(), // TS ok because of the filter
126+
branchEndFullName: boundary.branchEnd!.map((x) => x.name()), // TS ok because of the filter
126127
commitSHA: boundary.commit.sha(),
127128
})
128129
)
@@ -277,7 +278,7 @@ export const branchSequencer: BranchSequencer = async ({
277278
currentBranch,
278279
})
279280
).map((boundary) => {
280-
boundary.branchEndFullName = boundary.branchEndFullName.replace("refs/heads/", "");
281+
boundary.branchEndFullName = boundary.branchEndFullName.map((x) => x.replace("refs/heads/", ""));
281282
assert(boundary.branchEndFullName);
282283

283284
/**
@@ -289,7 +290,7 @@ export const branchSequencer: BranchSequencer = async ({
289290
// if (!Git.Branch.lookup(repo, targetBranch, Git.Branch.BRANCH.LOCAL)) {
290291
// execSyncInRepo();
291292
// }
292-
if (boundary.branchEndFullName.startsWith("refs/remotes/")) {
293+
if (boundary.branchEndFullName.some((x) => x.startsWith("refs/remotes/"))) {
293294
/**
294295
* TODO - probably should handle this "checkout remote branch locally" logic
295296
* in a better place than here,
@@ -327,7 +328,7 @@ export const branchSequencer: BranchSequencer = async ({
327328
* before doing the checkouts.
328329
*
329330
*/
330-
boundary.branchEndFullName = boundary.branchEndFullName.replace(/refs\/remotes\/[^/]+\//, "");
331+
boundary.branchEndFullName = boundary.branchEndFullName.map((x) => x.replace(/refs\/remotes\/[^/]+\//, ""));
331332
}
332333

333334
// console.log({ targetCommitSHA, target: targetBranch });
@@ -390,13 +391,17 @@ export const branchSequencer: BranchSequencer = async ({
390391
// await Git.Checkout.tree(repo, targetBranch as any); // TODO TS FIXME
391392
execSyncInRepo(`${gitCmd} checkout ${targetBranch}`); // f this
392393

393-
await actionInsideEachCheckedOutBranch({
394-
repo, //
395-
targetBranch,
396-
targetCommitSHA,
397-
isLatestBranch,
398-
execSyncInRepo,
399-
});
394+
await sequentialResolve(
395+
targetBranch.map((x) => async () =>
396+
await actionInsideEachCheckedOutBranch({
397+
repo, //
398+
targetBranch: x,
399+
targetCommitSHA,
400+
isLatestBranch,
401+
execSyncInRepo,
402+
})
403+
)
404+
);
400405

401406
return goNext();
402407
}

git-stacked-rebase.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -983,31 +983,34 @@ async function createInitialEditTodoOfGitStackedRebase(
983983
const rebaseTodo = commitsWithBranchBoundaries
984984
.map(({ commit, commitCommand, branchEnd }, i) => {
985985
if (i === 0) {
986-
assert(!!branchEnd, `very first commit has a branch (${commit.sha()}).`);
986+
assert(!!branchEnd?.length, `very first commit has a branch (${commit.sha()}).`);
987+
assert.strictEqual(branchEnd.length, 1, "must be only a single initial branch");
987988

988989
// return [];
989990
return [
990991
// `pick ${commit.sha()} ${commit.summary()}`,
991992
/**
992993
* TODO refs/REMOTES/* instead of refs/HEADS/*
993994
*/
994-
`branch-end-initial ${branchEnd.name()}`, //
995+
`branch-end-initial ${branchEnd[0].name()}`, //
995996
];
996997
}
997998

998999
if (i === commitsWithBranchBoundaries.length - 1) {
999-
assert(!!branchEnd, `very last commit has a branch. sha = ${commit.sha()}`);
1000+
assert(!!branchEnd?.length, `very last commit has a branch. sha = ${commit.sha()}`);
10001001

10011002
return [
10021003
`${commitCommand} ${commit.sha()} ${commit.summary()}`,
1003-
`branch-end-last ${branchEnd.name()}`, //
1004+
// `branch-end-last ${branchEnd.name()}`, //
1005+
`branch-end-last ${initialBranch.name()}`,
10041006
];
10051007
}
10061008

1007-
if (branchEnd) {
1009+
if (branchEnd?.length) {
10081010
return [
10091011
`${commitCommand} ${commit.sha()} ${commit.summary()}`,
1010-
`branch-end ${branchEnd.name()}`, //
1012+
// `branch-end ${branchEnd.name()}`, //
1013+
`branch-end ${currentBranch.name()}`, //
10111014
];
10121015
}
10131016

@@ -1092,7 +1095,7 @@ function callAll(keyToFunctionMap: KeyToFunctionMap) {
10921095
type CommitAndBranchBoundary = {
10931096
commit: Git.Commit;
10941097
commitCommand: RegularRebaseEitherCommandOrAlias;
1095-
branchEnd: Git.Reference | null;
1098+
branchEnd: Git.Reference[] | null;
10961099
};
10971100

10981101
export async function getWantedCommitsWithBranchBoundariesOurCustomImpl(
@@ -1447,7 +1450,7 @@ async function extendCommitsWithBranchEnds(
14471450
{
14481451
commit: c,
14491452
commitCommand: commandOrAliasNames[i] || "pick",
1450-
branchEnd: !matchedRefs.length ? null : matchedRefs[0],
1453+
branchEnd: !matchedRefs.length ? null : matchedRefs,
14511454
}
14521455
);
14531456

0 commit comments

Comments
 (0)