Skip to content

Commit

Permalink
WIP get rid of the .applied stuff; needs more verification though
Browse files Browse the repository at this point in the history
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
  • Loading branch information
kiprasmel committed Mar 23, 2022
1 parent 0331bb5 commit 235d759
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
16 changes: 6 additions & 10 deletions branchSequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import assert from "assert";

import Git from "nodegit";

import { filenames } from "./filenames";

import { createExecSyncInRepo } from "./util/execSyncInRepo";
import { Termination } from "./util/error";

Expand Down Expand Up @@ -54,7 +52,6 @@ export type BranchSequencerArgs = BranchSequencerArgsBase & {
actionInsideEachCheckedOutBranch: ActionInsideEachCheckedOutBranch;
delayMsBetweenCheckouts?: number;
callbackAfterDone?: CallbackAfterDone;
rewrittenListFile?: typeof filenames.rewrittenList;
};

export type BranchSequencerBase = (args: BranchSequencerArgsBase) => Promise<void>;
Expand All @@ -70,17 +67,13 @@ export const branchSequencer: BranchSequencer = async ({
// callbackBeforeBegin,
actionInsideEachCheckedOutBranch,
callbackAfterDone = (): void => {},
rewrittenListFile = filenames.rewrittenList,
gitCmd,
}) => {
if (!fs.existsSync(pathToStackedRebaseDirInsideDotGit)) {
throw new Termination(`\n\nno stacked-rebase in progress? (nothing to ${rootLevelCommandName})\n\n`);
}

const stackedRebaseCommandsNew: GoodCommand[] = parseNewGoodCommands(
repo,
pathToStackedRebaseTodoFile,
rewrittenListFile
);
const stackedRebaseCommandsNew: GoodCommand[] = parseNewGoodCommands(repo, pathToStackedRebaseTodoFile);

// const remotes: Git.Remote[] = await repo.getRemotes();
// const remote: Git.Remote | undefined = remotes.find((r) =>
Expand Down Expand Up @@ -157,8 +150,11 @@ export const branchSequencer: BranchSequencer = async ({
*/
const isFinalCheckout: boolean = cmds.length === 1;

/**
* https://libgit2.org/libgit2/#HEAD/group/checkout/git_checkout_head
*/
// await Git.Checkout.tree(repo, targetBranch as any); // TODO TS FIXME
execSyncInRepo(`git checkout ${targetBranch}`); // f this
execSyncInRepo(`${gitCmd} checkout ${targetBranch}`); // f this

await actionInsideEachCheckedOutBranch({
repo, //
Expand Down
1 change: 0 additions & 1 deletion forcePush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ export const forcePush: BranchSequencerBase = (argsBase) =>
execSyncInRepo(`${argsBase.gitCmd} push --force`);
},
delayMsBetweenCheckouts: 0,
rewrittenListFile: "rewritten-list.applied",
});
2 changes: 1 addition & 1 deletion git-stacked-rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export const gitStackedRebase = async (

console.log({ commitShaOfInitialBranch });

await repo.checkoutRef(initialBranch);
await repo.checkoutRef(initialBranch); /** TODO wtf */
// repo.rebaseBranches()

// const headName: string = (await (await repo.getHeadCommit()).sha()) + "\n";
Expand Down
7 changes: 3 additions & 4 deletions parse-todo-of-stacked-rebase/parseNewGoodCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import { GoodCommand, stackedRebaseCommands } from "./validator";

export function parseNewGoodCommands(
repo: Git.Repository,
pathToStackedRebaseTodoFile: string, //
rewrittenListFile: typeof filenames.rewrittenList | typeof filenames.rewrittenListApplied
pathToStackedRebaseTodoFile: string //
): GoodCommand[] {
const goodCommands: GoodCommand[] = parseTodoOfStackedRebase(pathToStackedRebaseTodoFile);

logGoodCmds(goodCommands);

const pathOfRewrittenList: string = path.join(repo.workdir(), ".git", "stacked-rebase", rewrittenListFile);
const pathOfRewrittenList: string = path.join(repo.workdir(), ".git", "stacked-rebase", filenames.rewrittenList);
const rewrittenList: string = fs.readFileSync(pathOfRewrittenList, { encoding: "utf-8" });
const rewrittenListLines: string[] = rewrittenList.split("\n").filter((line) => !!line);

Expand All @@ -36,7 +35,7 @@ export function parseNewGoodCommands(
const fromToSHA = line.split(" ");
assert(
fromToSHA.length === 2,
`from and to SHAs, coming from ${rewrittenListFile}, are written properly (1 space total).`
`from and to SHAs, coming from ${filenames.rewrittenList}, are written properly (1 space total).`
);

const [oldSHA, newSHA] = fromToSHA;
Expand Down

0 comments on commit 235d759

Please sign in to comment.