Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to check out branches #166

Merged

Conversation

mikegehard
Copy link
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 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")
Copy link
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.fixture
def test_repository():
    # Setup
    temp_path = Path("temp_test_repo")
    temp_path.mkdir(exist_ok=True)
    
    # Initialize your repository here
    # ...
    
    yield temp_path
    
    # Cleanup
    shutil.rmtree(temp_path)

def test_git_checkout_existing_branch(test_repository):
   ...

Copy link
Contributor Author

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
Member

dsp-ant commented Dec 3, 2024

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 mikegehard force-pushed the feature/git-checkout-command branch 2 times, most recently from 91039e3 to cc4e29e Compare December 3, 2024 17:35
@jspahrsummers jspahrsummers requested a review from dsp-ant December 5, 2024 23:12
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 mikegehard force-pushed the feature/git-checkout-command branch from cc4e29e to 98e78c3 Compare December 8, 2024 21:27
Copy link
Member

@dsp-ant dsp-ant left a comment

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:main Dec 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
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