diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json new file mode 100644 index 0000000..92d8f2a --- /dev/null +++ b/.claude-plugin/marketplace.json @@ -0,0 +1,16 @@ +{ + "name": "magic-merge-commit", + "owner": { + "name": "koppor" + }, + "metadata": { + "description": "Marketplace hosting the magic-merge-commit Claude Code plugin." + }, + "plugins": [ + { + "name": "magic-merge-commit", + "source": "./", + "description": "Fix Git merge conflicts caused by a squash-merged base branch." + } + ] +} diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..c599c24 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,11 @@ +{ + "name": "magic-merge-commit", + "description": "Fix a Git merge conflict caused by a squash-merged base branch. Wraps the jbang-based magic-merge-commit tool.", + "version": "1.0.0", + "author": { + "name": "Oliver Kopp" + }, + "homepage": "https://github.com/koppor/magic-merge-commit", + "repository": "https://github.com/koppor/magic-merge-commit", + "keywords": ["git", "merge", "squash", "conflict", "pull-request"] +} diff --git a/.gitignore b/.gitignore index 19a59e5..9f11b75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ .idea/ - -gg.cmd diff --git a/README.md b/README.md index 6703aa8..eb61d4b 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,25 @@ You need to be on the branch which is base on the pull request indicated by `` - Windows: `.\gg.cmd jbang do@koppor/magic-merge-commit ` +## Use as a Claude Code skill + +This repository is also a [Claude Code plugin](https://docs.claude.com/en/docs/claude-code/plugins). +Install it so Claude runs the tool for you when it detects a squash-merge conflict: + +```terminal +/plugin marketplace add koppor/magic-merge-commit +/plugin install magic-merge-commit@magic-merge-commit +``` + +The skill still requires `jbang` (or `gg.cmd`) and a `GITHUB_TOKEN` environment +variable on your machine — it tells Claude *when* and *how* to invoke the tool, +it does not bundle the tool itself. + ## Step-by-step description of the scenario ### 1. First pull request is created diff --git a/gg.cmd b/gg.cmd new file mode 100755 index 0000000..951a196 Binary files /dev/null and b/gg.cmd differ diff --git a/skills/magic-merge-commit/SKILL.md b/skills/magic-merge-commit/SKILL.md new file mode 100644 index 0000000..74ad106 --- /dev/null +++ b/skills/magic-merge-commit/SKILL.md @@ -0,0 +1,53 @@ +--- +name: magic-merge-commit +description: Fix a Git merge conflict caused by a squash-merged base branch. Use + when a PR can't merge `main` cleanly because its base branch was squash-merged, + and Git sees the old commits as conflicting with the squashed commit in `main`. + Creates a "magic" merge commit linking the branch to the squashed history. +--- + +# Magic Merge Commit + +Resolves conflicts where a pull request's base branch was squash-merged into +`main`. After the squash-merge, Git no longer connects the branch to its +history, so merging `main` produces spurious conflicts. This skill runs a tool +that creates a merge commit with two parents (`main` + branch tip), wiring the +histories back together so `main` merges cleanly. + +## When to use + +All of the following are true: + +- The user is on a branch that was based on another PR's branch. +- That other PR was **squash-merged** into `main`. +- Merging `main` into the current branch now conflicts. + +## Prerequisites (verify before running) + +1. `jbang` is on `PATH`. If not, a `gg.cmd` file in the repository root works + as a fallback (see https://github.com/eirikb/gg#ggcmd). +2. The `GITHUB_TOKEN` environment variable is set with read access to the + repository. The tool authenticates via `GitHubBuilder().fromEnvironment()`. +3. The current Git branch is the one based on the squashed PR — not `main`. + +If a prerequisite is missing, tell the user how to fix it and stop. + +## Run + +Ask the user for `` — the number of the PR that was squash-merged +into `main`. Then run: + +``` +jbang do@koppor/magic-merge-commit +``` + +Fallback when `jbang` is not installed (`gg.cmd` in repo root): + +- Linux/macOS: `sh ./gg.cmd jbang do@koppor/magic-merge-commit ` +- Windows: `.\gg.cmd jbang do@koppor/magic-merge-commit ` + +## After running + +The tool creates a merge commit with `main` and the branch tip as parents. +Confirm with `git log --graph --oneline -5` that the magic commit exists, then +the user can merge `main` without conflicts.