Skip to content

fix(git): keep the merge parent when git_commit concludes a merge - #4942

Open
jayhemnani9910 wants to merge 2 commits into
modelcontextprotocol:mainfrom
jayhemnani9910:fix/git-commit-during-merge
Open

jayhemnani9910 wants to merge 2 commits into
modelcontextprotocol:mainfrom
jayhemnani9910:fix/git-commit-during-merge

Conversation

@jayhemnani9910

Copy link
Copy Markdown

Description

After a conflicted merge is resolved and staged, git_commit created a commit with only HEAD as its parent and left MERGE_HEAD behind. The merged branch's history was silently dropped from the result, and git_status still reported "All conflicts fixed but you are still merging". git_commit now uses MERGE_HEAD as an extra parent when it exists and clears the merge state, as git commit does.

Server Details

  • Server: git
  • Changes to: tools (git_commit)

Motivation and Context

repo.index.commit(message) ignores an in-progress merge. An agent that resolves a conflict and commits through the server ends up with a linear commit instead of a merge commit.

How Has This Been Tested?

  • New test_git_commit_concludes_a_merge creates a real conflict, resolves it and calls git_commit; it fails on main (one parent) and passes here.
  • Ran the server over stdio with an MCP client on a conflicted repo: the commit now has two parents and MERGE_HEAD is gone.
  • uv run pytest, ruff check and pyright pass.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • My code follows the repository's style guidelines
  • New and existing tests pass locally

After a conflicted merge was resolved and staged, git_commit created a
commit with only HEAD as its parent and left MERGE_HEAD behind, so the
merged branch's history was silently dropped and status still reported
an unfinished merge. When MERGE_HEAD exists, commit with it as an extra
parent and clear the merge state, as `git commit` does.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 19:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@changeset-bot

changeset-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1a64923

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

git merge needs user.name and user.email. CI has none, so the merge
stopped before writing MERGE_HEAD and the test never saw a merge.
Copilot AI balanced review requested due to automatic review settings October 2, 2026 13:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants