Skip to content

Allow to check out branches - #166

Merged
dsp-ant merged 3 commits into
modelcontextprotocol:mainfrom
mikegehard:feature/git-checkout-command
Dec 10, 2024
Merged

Allow to check out branches#166
dsp-ant merged 3 commits into
modelcontextprotocol:mainfrom
mikegehard:feature/git-checkout-command

Conversation

@mikegehard

Copy link
Copy Markdown
Contributor

Description

The git server currently lacks branch switching capabilities, limiting both LLMs and developers. This adds branch checkout so LLMs can help developers add new functionality in a new feature branch.

Server Details

  • Server: git
  • Changes to: tools

Motivation and Context

See #147

How Has This Been Tested?

Tested via the Claude macOS app.

Breaking Changes

No

Types of changes

  • New MCP Server
  • Bug fix (non-breaking change which fixes an issue)
  • [ X] 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 server follows MCP security best practices
  • [ X] I have updated the server's README accordingly
  • [ X] I have tested this with an LLM client
  • [ X] My code follows the repository's style guidelines
  • [ X] New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Comment threadsrc/git/tests/test_server.py Outdated
Comment on lines +1 to +24
import pytest
from pathlib import Path
import git
from mcp_server_git.server import git_checkout

def test_git_checkout_existing_branch(tmp_path: Path):
# Setup test repo
repo = git.Repo.init(tmp_path)
Path(tmp_path / "test.txt").write_text("test")
repo.index.add(["test.txt"])
repo.index.commit("initial commit")

# Create and test branch
repo.git.branch("test-branch")
result = git_checkout(repo, "test-branch")

assert "Switched to branch 'test-branch'" in result
assert repo.active_branch.name == "test-branch"

def test_git_checkout_nonexistent_branch(tmp_path: Path):
repo = git.Repo.init(tmp_path)

with pytest.raises(git.GitCommandError):
git_checkout(repo, "nonexistent-branch") No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure we should add this test. It feels straight forward enough.

If we do add tests, we should use a proper fixture:

@pytest.fixturedeftest_repository():
# Setuptemp_path=Path("temp_test_repo")
temp_path.mkdir(exist_ok=True)
# Initialize your repository here# ...yieldtemp_path# Cleanupshutil.rmtree(temp_path)
deftest_git_checkout_existing_branch(test_repository):
...

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dsp-ant I think I've addressed your concern? Let me know what you think.

@dsp-ant

Copy link
Copy Markdown
Member

Overall this looks good. There are some changes I'd love to see to the test file. We either use a fixture or delete the tests.

@mikegehard
mikegehardforce-pushed the feature/git-checkout-command branch 2 times, most recently from 91039e3 to cc4e29eCompareDecember 3, 2024 17:35
The git server currently lacks branch switching capabilities, limiting both
LLMs and developers. This adds branch checkout so LLMs can
help developers add new functionality in a new feature branch.
@mikegehard
mikegehardforce-pushed the feature/git-checkout-command branch from cc4e29e to 98e78c3CompareDecember 8, 2024 21:27

@dsp-antdsp-ant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good. Thank you

@dsp-ant
dsp-ant merged commit 79794fe into modelcontextprotocol:mainDec 10, 2024
@mikegehard
mikegehard deleted the feature/git-checkout-command branch December 10, 2024 15:10
laith-abood pushed a commit to laith-abood/mcp-claude that referenced this pull request Jan 13, 2025
…it-checkout-command
Allow to check out branches
PazerOP referenced this pull request in PazerOP/mcp-template Jul 15, 2025
Sign up for freeto 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

@mikegehard@dsp-ant