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

Fermée Adaptée aux débutants
#5,012 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
75/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
backend

Piste de recherche

Le bug se trouve dans src/git/src/mcp_server_git/server.py, où git_commit appelle repo.index.commit() sans gérer l'état de fusion. Commencez par examiner cette fonction et la signature de IndexFile.commit() de GitPython. Lorsque MERGE_HEAD existe, lisez ses commits et passez-les en tant que parent_commits, puis supprimez MERGE_HEAD, MERGE_MSG et MERGE_MODE. Ajoutez un test dans la suite de tests git qui effectue une fusion avec --no-commit, appelle git_commit et vérifie qu'il y a deux parents et qu'aucun état de fusion ne reste.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
TypeScript
Étoiles
91.7k
Forks
11.9k
Merge moyen
3 h 48 min
PR mergées (30 j)
180

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/servers

Toutes les issues de modelcontextprotocol/servers

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.