diff --git a/src/cli.ts b/src/cli.ts index 3b02d62..d2d034b 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -128,14 +128,16 @@ program program .command("merge") .argument("", "branch name") + .option("-f, --force", "allow merging into a non-main branch") .description("Merge a branch into main and close the session") - .action(mergeAction) + .action((branch: string, opts: { force?: boolean }) => mergeAction(branch, opts)) program .command("squash") .argument("", "branch name") + .option("-f, --force", "allow merging into a non-main branch") .description("Squash-merge a branch into main and close the session") - .action(squashAction) + .action((branch: string, opts: { force?: boolean }) => squashAction(branch, opts)) program .command("rebase") diff --git a/src/commands/helpers.ts b/src/commands/helpers.ts index 9c50920..0172329 100644 --- a/src/commands/helpers.ts +++ b/src/commands/helpers.ts @@ -91,12 +91,12 @@ export async function resolveConflicts( } /** Merge (or squash-merge) a branch into main, resolve conflicts if needed, and close the session. */ -export async function mergeAndClose(branch: string, opts?: { squash?: boolean }): Promise { +export async function mergeAndClose(branch: string, opts?: { squash?: boolean; force?: boolean }): Promise { const root = await git.repoRoot() const main = await git.mainBranch(root) const current = await git.currentBranch(root) - if (current !== main) { - die(`You must be on "${main}" to merge. Currently on "${current}".`) + if (current !== main && !opts?.force) { + die(`You must be on "${main}" to merge. Currently on "${current}". Use --force to merge into "${current}" anyway.`) } const session = await state.getSession(root, branch) diff --git a/src/commands/merge.ts b/src/commands/merge.ts index 1f4d05e..f20a6ec 100644 --- a/src/commands/merge.ts +++ b/src/commands/merge.ts @@ -1,5 +1,5 @@ import { mergeAndClose } from "./helpers.ts" -export async function action(branch: string) { - await mergeAndClose(branch) +export async function action(branch: string, opts?: { force?: boolean }) { + await mergeAndClose(branch, { force: opts?.force }) } diff --git a/src/commands/squash.ts b/src/commands/squash.ts index 2f0d341..32efca3 100644 --- a/src/commands/squash.ts +++ b/src/commands/squash.ts @@ -1,5 +1,5 @@ import { mergeAndClose } from "./helpers.ts" -export async function action(branch: string) { - await mergeAndClose(branch, { squash: true }) +export async function action(branch: string, opts?: { force?: boolean }) { + await mergeAndClose(branch, { squash: true, force: opts?.force }) }