Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

git_commit during a merge records one parent and leaves MERGE_HEAD in place

已关闭 适合新手
#5,012 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

该 bug 位于 src/git/src/mcp_server_git/server.py,原因是 git_commit 调用 repo.index.commit() 时未处理合并状态。首先检查该函数以及 GitPython 的 IndexFile.commit() 方法签名。当 MERGE_HEAD 存在时,读取其对应的提交并作为 parent_commits 传入,随后清除 MERGE_HEAD、MERGE_MSG 和 MERGE_MODE。在 git 测试套件中添加一个测试:执行带 --no-commit 参数的合并操作,调用 git_commit,并断言存在两个父提交且无剩余合并状态。

由索引模型根据 Issue 内容生成。

描述

bug server-git v2
Describe the bug

git_commit cannot conclude a merge. While a merge is in progress (MERGE_HEAD present, e.g. after git merge --no-commit or a resolved conflict), it writes a commit with one parent, HEAD, and leaves MERGE_HEAD (and MERGE_MSG) in place, so the repository stays in merge state and the merged branch's history is not recorded.

src/git/src/mcp_server_git/server.py, git_commit calls repo.index.commit(message). GitPython's IndexFile.commit() takes parent_commits=None, which means [repo.head.commit] only; it neither reads nor clears MERGE_HEAD.

Found in the Copilot review of #5007 (the fix for #4762), which keeps the empty-merge-commit case committable but, like the code before it, records it with one parent. This predates #5007: any merge resolved through git_commit has always been recorded this way.

To Reproduce
import git
# repo on main with a branch `side` that adds side.txt
repo.git.merge("side", "--no-commit", "--no-ff")
commit = repo.index.commit("merge side")   # what git_commit does
len(commit.parents)                        # 1, git commit would give 2
(Path(repo.git_dir) / "MERGE_HEAD").exists()  # True, merge still in progress
Expected behavior

While MERGE_HEAD is present, git_commit records HEAD plus every MERGE_HEAD commit as parents and clears the merge state, as git commit does (either by shelling out to git commit, or by passing parent_commits and removing MERGE_HEAD/MERGE_MSG/MERGE_MODE). A test asserts both parents and that MERGE_HEAD is gone.

Additional context

Related: #659 (a git_merge tool), which would make this path reachable from the server alone.

主要语言
TypeScript
星标
91k
派生
11.8k
平均合并
6 小时 33 分钟
30 天内合并 PR
79

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/servers 的其他 Issue

查看 modelcontextprotocol/servers 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。