diff --git a/src/cli.ts b/src/cli.ts index 7494a02..6ef7db8 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -115,6 +115,21 @@ const closeAction = async (branch: string) => { } } +// ── sandlot merge ────────────────────────────────────────── + +program + .command("merge") + .argument("", "branch name") + .description("Merge a branch into main and close the session") + .action(async (branch: string) => { + const root = await git.repoRoot() + + await git.merge(branch, root) + console.log(`Merged ${branch} into current branch`) + + await closeAction(branch) + }) + program .command("close") .argument("", "branch name") diff --git a/src/git.ts b/src/git.ts index 48b1634..f2f04ae 100644 --- a/src/git.ts +++ b/src/git.ts @@ -80,3 +80,11 @@ export async function checkout(branch: string, cwd: string): Promise { throw new Error(`Failed to checkout branch "${branch}": ${result.stderr.toString().trim()}`) } } + +/** Merge a branch into the current branch. */ +export async function merge(branch: string, cwd: string): Promise { + const result = await $`git merge ${branch}`.cwd(cwd).nothrow().quiet() + if (result.exitCode !== 0) { + throw new Error(`Failed to merge branch "${branch}": ${result.stderr.toString().trim()}`) + } +}