Skip to content

Commit 08ae30b

Browse files
committed
WIP multiple branches at commit
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
1 parent 198034c commit 08ae30b

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
@@ -887,31 +887,34 @@ async function createInitialEditTodoOfGitStackedRebase(
887887
const rebaseTodo = commitsWithBranchBoundaries
888888
.map(({ commit, commitCommand, branchEnd }, i) => {
889889
if (i === 0) {
890-
assert(!!branchEnd, `very first commit has a branch (${commit.sha()}).`);
890+
assert(!!branchEnd?.length, `very first commit has a branch (${commit.sha()}).`);
891+
assert.strictEqual(branchEnd.length, 1, "must be only a single initial branch");
891892

892893
// return [];
893894
return [
894895
// `pick ${commit.sha()} ${commit.summary()}`,
895896
/**
896897
* TODO refs/REMOTES/* instead of refs/HEADS/*
897898
*/
898-
`branch-end-initial ${branchEnd.name()}`, //
899+
`branch-end-initial ${branchEnd[0].name()}`, //
899900
];
900901
}
901902

902903
if (i === commitsWithBranchBoundaries.length - 1) {
903-
assert(!!branchEnd, `very last commit has a branch. sha = ${commit.sha()}`);
904+
assert(!!branchEnd?.length, `very last commit has a branch. sha = ${commit.sha()}`);
904905

905906
return [
906907
`${commitCommand} ${commit.sha()} ${commit.summary()}`,
907-
`branch-end-last ${branchEnd.name()}`, //
908+
// `branch-end-last ${branchEnd.name()}`, //
909+
`branch-end-last ${initialBranch.name()}`,
908910
];
909911
}
910912

911-
if (branchEnd) {
913+
if (branchEnd?.length) {
912914
return [
913915
`${commitCommand} ${commit.sha()} ${commit.summary()}`,
914-
`branch-end ${branchEnd.name()}`, //
916+
// `branch-end ${branchEnd.name()}`, //
917+
`branch-end ${currentBranch.name()}`, //
915918
];
916919
}
917920

@@ -996,7 +999,7 @@ function callAll(keyToFunctionMap: KeyToFunctionMap) {
996999
type CommitAndBranchBoundary = {
9971000
commit: Git.Commit;
9981001
commitCommand: RegularRebaseEitherCommandOrAlias;
999-
branchEnd: Git.Reference | null;
1002+
branchEnd: Git.Reference[] | null;
10001003
};
10011004

10021005
export async function getWantedCommitsWithBranchBoundariesOurCustomImpl(
@@ -1355,7 +1358,7 @@ async function extendCommitsWithBranchEnds(
13551358
{
13561359
commit: c,
13571360
commitCommand: commandOrAliasNames[i] || "pick",
1358-
branchEnd: !matchedRefs.length ? null : matchedRefs[0],
1361+
branchEnd: !matchedRefs.length ? null : matchedRefs,
13591362
}
13601363
);
13611364

0 commit comments

Comments
 (0)