Skip to content

docs(git): document setting the commit identity via env vars or gitconfig - #5354

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/docs/619-git-commit-identity
Oct 29, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/docs/619-git-commit-identity

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #619

Description

git_commit already honors a commit identity from the environment and from Git config; it was just undocumented. It goes through GitPython's IndexFile.commit, whose Actor reads GIT_AUTHOR_NAME/GIT_AUTHOR_EMAIL and GIT_COMMITTER_NAME/GIT_COMMITTER_EMAIL first, then user.name/user.email from the repository config, ~/.gitconfig, $XDG_CONFIG_HOME/git/config and /etc/gitconfig. With none of them set it does not refuse (unlike git commit): it records root <root@<container id>> in Docker, which is the problem #619 describes.

So no code changes. This PR:

  • adds a Commit identity subsection to the git README (just before "Usage with Claude Desktop"): the lookup order, the silent fallback, an env block for local commands, and a read-only gitconfig mount for Docker (the image runs as root, so /root/.gitconfig);
  • adds the four -e GIT_* pairs to the two Docker examples (Usage with Claude Desktop, and Development);
  • adds tests/test_identity.py, which pins each route through the protocol: the env vars override repo config, author and committer are resolved separately, and a ~/.gitconfig under HOME is used when no env var is set.

Server Details

  • Server: git (mcp-server-git)
  • Changes to: README and tests only. No change to tools, resources, prompts or behavior.

Motivation and Context

#619: users running the server in Docker could not see how to commit under their own name. The triage comment on the issue noted that Git and GitPython already read the standard variables, so the work is documentation. This PR confirms that by test before documenting it.

How Has This Been Tested?

  • uv run pytest tests/test_identity.py: 3 passed; npm run local:gate exits 0.
  • Inspector CLI 2.12.0 against the Docker image built from this branch (docker build -t mcp-git-619 src/git), committing a staged file in a scratch repo, in both eras (--protocol-era legacy and modern; both returned Changes committed successfully with hash …, exit 0). Then git log --format='%s | %an <%ae> / %cn <%ce>':
    docker no identity | root <root@9d8ff20c5269> / root <root@9d8ff20c5269>
    docker gitconfig modern | Gita Config <gita@example.com> / Gita Config <gita@example.com>
    docker gitconfig legacy | Gita Config <gita@example.com> / Gita Config <gita@example.com>
    docker -e modern | Ada Author <ada@example.com> / Cy Committer <cy@example.com>
    docker -e legacy | Ada Author <ada@example.com> / Cy Committer <cy@example.com>
    
    The -e rows used docker run --rm -i -e "GIT_AUTHOR_NAME=Ada Author" -e GIT_AUTHOR_EMAIL=ada@example.com -e "GIT_COMMITTER_NAME=Cy Committer" -e GIT_COMMITTER_EMAIL=cy@example.com --mount … mcp-git-619. The gitconfig rows used --mount type=bind,src=<dir>/.gitconfig,dst=/root/.gitconfig,readonly. The last row (no identity at all) shows the fallback the README warns about.
  • LLM client: Claude Code 2.1.312, headless (claude -p --strict-mcp-config), with a config running this branch through uv --directory src/git run mcp-server-git --repository <scratch repo> and the README's env block (author Ada Author, committer Cy Committer). Prompt: "Using the git server, commit the already-staged changes in the repository at with the message 'llm env identity', then reply with exactly the text the tool returned." It called git_commit and replied Changes committed successfully with hash 09434b6b…; git log -1 shows llm env identity | Ada Author <ada@example.com> / Cy Committer <cy@example.com>. Claude Code has no era switch, so the era it negotiated could not be chosen; the Inspector runs above cover both eras.

Breaking Changes

None. Existing configurations behave as before.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices (the gitconfig mount is read-only and only the one file is mounted)
  • I have updated the server's README accordingly
  • I have added a changeset (npm run changeset) if this changes what a TypeScript server publishes (not applicable: a Python server, and docs/tests only)
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling (not applicable: no code change)
  • I have documented all environment variables and configuration options

Additional context

This is lane E of the #5270 (Git v2.3.0) fan-out. It touches only the new README subsection, the two Docker examples and a new test file, so it merges cleanly beside the other lanes' PRs.

🤖 Generated with Claude Code

…nfig

git_commit already takes the author and committer from GIT_AUTHOR_* and
GIT_COMMITTER_* in the server's environment, then from user.name/user.email
in Git config (GitPython's Actor). Document both routes in a new Commit
identity section, add -e lines to the Docker examples, and pin each route
with protocol-level tests.

Closes #619

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall cliffhall added the v2 label Oct 28, 2026
@changeset-bot

changeset-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9863a10

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

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.

🟢 Approval recommended

No active review issues remain for the commit-identity documentation and test additions.

No open issues 🎉

What changed in this PR

Documents how the Git server’s existing commit-identity handling addresses #619, without changing server behavior.

Changes:

  • Explains identity lookup order and the fallback when no identity is configured.
  • Adds local environment-variable and Docker configuration examples.
  • Adds protocol-level tests for environment precedence, separate author/committer resolution, and home gitconfig lookup.
File Description
src/​git/​tests/​test_identity.py Adds three tests covering commit-identity configuration routes.
src/​git/​README.md Documents commit identity and updates Docker examples with identity variables.

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: clean (no findings, no suppressed comments). The review loop stops on this first clean round, with nothing pushed since. Head: 9863a10.

@cliffhall
cliffhall merged commit 39af108 into v2/main Oct 29, 2026
41 checks passed
@cliffhall
cliffhall deleted the v2/docs/619-git-commit-identity branch October 29, 2026 01:15
@cliffhall cliffhall mentioned this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Git] add ability to set user name and email via env variable

2 participants