From 235d759b0f6c8e39b4f1fc0758e6677f3dd1452f Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Sun, 16 Jan 2022 00:31:59 +0200 Subject: [PATCH] WIP get rid of the .applied stuff; needs more verification though Signed-off-by: Kipras Melnikovas --- branchSequencer.ts | 16 ++++++---------- forcePush.ts | 1 - git-stacked-rebase.ts | 2 +- .../parseNewGoodCommands.ts | 7 +++---- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/branchSequencer.ts b/branchSequencer.ts index f673dffb..cc0d1d34 100644 --- a/branchSequencer.ts +++ b/branchSequencer.ts @@ -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"; @@ -54,7 +52,6 @@ export type BranchSequencerArgs = BranchSequencerArgsBase & { actionInsideEachCheckedOutBranch: ActionInsideEachCheckedOutBranch; delayMsBetweenCheckouts?: number; callbackAfterDone?: CallbackAfterDone; - rewrittenListFile?: typeof filenames.rewrittenList; }; export type BranchSequencerBase = (args: BranchSequencerArgsBase) => Promise; @@ -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) => @@ -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, // diff --git a/forcePush.ts b/forcePush.ts index 171e3720..a7c0befa 100644 --- a/forcePush.ts +++ b/forcePush.ts @@ -38,5 +38,4 @@ export const forcePush: BranchSequencerBase = (argsBase) => execSyncInRepo(`${argsBase.gitCmd} push --force`); }, delayMsBetweenCheckouts: 0, - rewrittenListFile: "rewritten-list.applied", }); diff --git a/git-stacked-rebase.ts b/git-stacked-rebase.ts index f63e530a..df7b85d6 100755 --- a/git-stacked-rebase.ts +++ b/git-stacked-rebase.ts @@ -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"; diff --git a/parse-todo-of-stacked-rebase/parseNewGoodCommands.ts b/parse-todo-of-stacked-rebase/parseNewGoodCommands.ts index c15087c4..0d3913be 100644 --- a/parse-todo-of-stacked-rebase/parseNewGoodCommands.ts +++ b/parse-todo-of-stacked-rebase/parseNewGoodCommands.ts @@ -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); @@ -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;