Skip to content

feat: close branch-list / push-delete / default-branch gaps (#171-#176)#174

Merged
MementoRC merged 2 commits into
developmentfrom
feat/issues-171-172-173
May 20, 2026
Merged

feat: close branch-list / push-delete / default-branch gaps (#171-#176)#174
MementoRC merged 2 commits into
developmentfrom
feat/issues-171-172-173

Conversation

@MementoRC
Copy link
Copy Markdown
Owner

@MementoRC MementoRC commented May 20, 2026

Summary

Six small missing-capability issues bundled into one change. Originally three (#171/#172/#173); #175 and #176 were rolled in during review to avoid staggering MCP server restarts.

Files changed

Area Files
Models git/models.py, github/models.py
Ops git/_branch_ops.py, git/_remote_ops.py, github/repos.py
Registry lean/registry_git.py (registers git_branch_list)
Tests tests/unit/git/test_git_branch_list.py (rewritten + sort suite, 31 tests), tests/unit/git/test_git_push_delete.py (new, +dry_run suite, 27 tests), tests/unit/github/test_github_repo_settings.py (+1 test)

Test plan

  • pixi run -e quality test-unit tests/unit/git/test_git_branch_list.py — 31 pass (21 original + 10 sort)
  • pixi run -e quality test-unit tests/unit/git/test_git_push_delete.py tests/unit/git/test_git_push_force_with_lease.py — 35 pass (8 force_with_lease + 16 delete + 11 dry_run)
  • pixi run -e quality test-unit tests/unit/github/test_github_repo_settings.py — 43 pass (1 new)
  • CI green on all platforms

Design notes

Three missing-capability issues addressed in one change.

Issue #171 — register git_branch_list as a lean MCP tool
  - Extend existing _branch_ops.git_branch_list with schema requested
    in the issue: branch_type (local|remote|all), pattern, contains,
    merged. Return structured records (name/sha/is_current/upstream).
  - Legacy remote=/all= bools kept as aliases for back-compat;
    explicit conflict with branch_type surfaces as error text.
  - Add GitBranchList pydantic model and register in lean/registry_git.
  - 21 tests (test_git_branch_list.py rewritten).

Issue #172 — default_branch passthrough on github_update_repo_settings
  - Add default_branch: str | None field to GitHubUpdateRepoSettings
    and forward to the PATCH /repos/{owner}/{name} payload.
  - Unblocks workflows that need to flip the repo's default branch
    (e.g. main -> development for sub-package conventions).
  - 1 new test verifies the payload entry.

Issue #173 — delete + raw refspec support on git_push
  - Add delete: bool and refspec: str | None fields to GitPush.
  - model_validator enforces five mutual-exclusion rules; same guards
    mirrored in the handler in case lean dispatch skips pydantic.
  - delete=True dispatches `git push <remote> --delete <branch>`;
    refspec dispatches `git push <remote> <refspec>`.
  - Closes the circular dead-end where shell-runner refused
    `git push --delete` and the MCP tool didn't support it.
  - 16 new tests in test_git_push_delete.py.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Claude finished @MementoRC's task —— View job


Code Review Complete ✅

Reviewing PR #174 that closes issues #171, #172, and #173. This PR adds missing capabilities for branch listing, push deletion, and default branch settings.

Review Tasks

  • Analyze core model changes (git/models.py, github/models.py)
  • Review branch operations implementation (git/_branch_ops.py)
  • Review remote operations implementation (git/_remote_ops.py)
  • Check GitHub repository settings changes (github/repos.py)
  • Examine lean registry updates (lean/registry_git.py)
  • Evaluate test coverage and quality
  • Assess code quality, security, and performance
  • Provide comprehensive feedback

🟢 Overall Assessment: APPROVE

This is a well-designed, thoroughly tested implementation that addresses three specific gaps in the MCP Git tooling. The code demonstrates excellent engineering practices with comprehensive validation, strong type safety, and extensive test coverage.


🚀 Strengths

Excellent Design & Architecture

  • Smart validation strategy: Dual validation (Pydantic model + handler entry) provides belt-and-suspenders protection for lean dispatch paths
  • Clean backward compatibility: Legacy remote/all boolean flags preserved as aliases while introducing the cleaner branch_type parameter
  • Consistent error handling: All operations return structured error messages with ❌ prefix following established patterns

Robust Implementation

  • Comprehensive mutual exclusion rules: The 5 validation rules for git_push properly prevent conflicting parameter combinations
  • Security consciousness: Input sanitization in git_merge_base against dangerous shell characters
  • Type safety: Excellent use of Literal types and Union types for better IDE/tooling support

Outstanding Test Coverage

  • 21 tests for git_branch_list: Covers all filtering scenarios, edge cases, and error conditions
  • 16 tests for git_push delete/refspec: Tests both happy paths and all validation scenarios
  • Comprehensive model validation tests: Ensures Pydantic validators match handler logic

📝 Code Quality Analysis

git/models.py:108-155 - GitPush Validation

EXCELLENT ✅ The @model_validator implementation is particularly well done:

  • Clear, descriptive error messages
  • Proper mutual exclusion logic
  • All edge cases covered in tests

git/_branch_ops.py:121-142 - Legacy Resolution

GOOD ✅ The _resolve_branch_type() function elegantly handles backward compatibility:

  • Clear conflict detection between new and legacy parameters
  • Maintains existing API while providing migration path

git/_remote_ops.py:103-118 - Validation Guards

EXCELLENT ✅ Handler-level validation mirrors Pydantic model validation:

  • Ensures consistency across different dispatch paths
  • Provides immediate feedback on invalid parameter combinations

🔒 Security Assessment

NO SECURITY CONCERNS

  • Input validation prevents shell injection in git_merge_base:311-314
  • No credential exposure risks
  • Safe parameter handling throughout

⚡ Performance Considerations

OPTIMAL

  • Efficient filtering using Python sets for contains/merged operations
  • Minimal Git command execution
  • No performance regressions introduced

🧪 Test Quality Assessment

Comprehensive Coverage

  • Branch listing: Tests all filter combinations, edge cases, error scenarios
  • Push operations: Tests all validation rules and success paths
  • GitHub settings: Integration test for new default_branch parameter

Test Design Excellence

  • Mock factories (_make_head, _make_repo) promote test maintainability
  • Clear test naming follows good patterns
  • Proper error condition testing

💡 Minor Suggestions

Code Style

  1. Consider extracting validation constants (git/models.py:134-154):

    # Could extract to improve maintainability
    FORCE_FLAGS = ["force", "force_with_lease", "force_if_includes"]
    INCOMPATIBLE_WITH_DELETE = FORCE_FLAGS + ["set_upstream", "refspec"]
  2. Documentation enhancement (git/_branch_ops.py:244):
    The function docstring could mention the backward compatibility aliasing more prominently.

Future Enhancements

  • Consider adding --sort option to git_branch_list for sorted output
  • Could add dry-run mode for git_push delete operations

✅ Specific Validations

Issue #171 - Branch List Enhancement

  • ✅ Properly registered in lean interface
  • ✅ Extended schema with all new filtering options
  • ✅ Backward compatibility maintained
  • ✅ Comprehensive test coverage (21 tests)

Issue #172 - GitHub Default Branch

  • default_branch parameter correctly added to model
  • ✅ Proper passthrough in handler function
  • ✅ Test coverage included

Issue #173 - Push Delete Support

  • ✅ All 5 mutual exclusion rules properly implemented
  • ✅ Both delete and refspec modes working
  • ✅ Comprehensive validation testing (16 tests)
  • ✅ Handler and model validation consistency

🎯 Recommendation

APPROVE AND MERGE - This PR represents high-quality engineering work that successfully addresses all three issues with excellent attention to detail, comprehensive testing, and thoughtful design decisions.

Bundled into PR #174 to avoid staggering MCP server restarts.

Issue #175 — git_branch_list sort
  - Add sort: str | None field to GitBranchList (e.g. '-committerdate',
    'refname', 'authordate'); mirrors `git for-each-ref --sort=<key>`.
  - When set, branches are collected via for_each_ref with NUL-separated
    format; existing pattern/contains/merged filters apply post-fetch.
  - sort=None preserves the legacy collection path (no perf regression).
  - 10 new tests in TestGitBranchListSort.

Issue #176 — git_push dry_run
  - Add dry_run: bool = False to GitPush; orthogonal to all existing
    mutual-exclusion rules (no validator changes).
  - Appends --dry-run to all four push paths: normal, force, delete,
    raw refspec. Return string carries a 'dry-run' marker.
  - 11 new tests in TestGitPushDryRun.
@MementoRC MementoRC changed the title feat: close branch-list / push-delete / default-branch gaps (#171, #172, #173) feat: close branch-list / push-delete / default-branch gaps (#171-#176) May 20, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Claude finished @MementoRC's task —— View job


Code Review for PR #174

Reviewed PR that closes issues #171, #172, #173, #175, and #176 - adding missing capabilities for branch listing, push deletion, and default branch settings.

Review Tasks

  • Analyze core model changes (git/models.py, github/models.py)
  • Review branch operations implementation (git/_branch_ops.py)
  • Review remote operations implementation (git/_remote_ops.py)
  • Check GitHub repository settings changes (github/repos.py)
  • Examine lean registry updates (lean/registry_git.py)
  • Evaluate test coverage and quality
  • Assess code quality, security, and performance
  • Provide comprehensive feedback

🟢 Overall Assessment: APPROVE

This is an excellent implementation that addresses six specific gaps in the MCP Git tooling. The code demonstrates strong engineering practices with comprehensive validation, excellent test coverage, and thoughtful design decisions.


🚀 Strengths

Excellent Design & Architecture

  • Smart validation strategy: Dual validation (Pydantic model + handler entry) at git/_remote_ops.py:108-123 provides robust protection for lean dispatch paths
  • Clean backward compatibility: Legacy remote/all boolean flags preserved as aliases at git/_branch_ops.py:121-142 while introducing cleaner branch_type parameter
  • Comprehensive mutual exclusion rules: The 5 validation rules in GitPush model at git/models.py:141-161 properly prevent conflicting parameter combinations
  • Consistent error handling: All operations return structured error messages with ❌ prefix following established patterns

Security & Input Validation

  • Input sanitization: git_merge_base at git/_branch_ops.py:358-362 validates against dangerous shell characters
  • No security concerns: Proper parameter validation throughout, no credential exposure risks
  • Safe parameter handling: Type safety with Literal types and Union types for better IDE/tooling support

Outstanding Test Coverage

  • Branch listing: 31+ tests covering all filtering scenarios, sort functionality, legacy compatibility
  • Push operations: 27+ tests for delete/refspec functionality with comprehensive validation testing
  • GitHub settings: Added tests for default_branch parameter integration
  • Quality test design: Mock factories promote maintainability, clear naming conventions

📋 Detailed Code Analysis

git/models.py:108-161 - GitPush Validation

EXCELLENT ✅ The @model_validator implementation is particularly well done:

@model_validator(mode="after")
def _validate_delete_and_refspec(self) -> "GitPush":
    if self.delete:
        if not self.branch:
            raise ValueError("delete=True requires branch to be set")
        # ... comprehensive mutual exclusion logic
  • Clear, descriptive error messages
  • All 5 mutual exclusion rules properly implemented
  • Comprehensive test coverage validates all edge cases

git/_branch_ops.py:121-142 - Legacy Resolution

EXCELLENT ✅ The _resolve_branch_type() function elegantly handles backward compatibility:

  • Detects conflicts between new branch_type and legacy remote/all parameters
  • Maintains existing API while providing clear migration path
  • Proper error messaging when conflicting parameters are used

git/_branch_ops.py:222-264 - Sorted Branch Collection

EXCELLENT ✅ The sorted branch implementation using git for-each-ref:

  • Only triggers when sort parameter is provided (zero performance impact for unsorted calls)
  • Proper format string with null separators for reliable parsing
  • Handles both local and remote branch patterns efficiently

git/_remote_ops.py:108-123 - Handler Validation Guards

EXCELLENT ✅ Dual validation approach:

  • Handler-level validation mirrors Pydantic model validation
  • Ensures consistency across different dispatch paths (lean vs full)
  • Belt-and-suspenders protection as documented in PR description

github/repos.py:139-140 - Default Branch Addition

SIMPLE & CORRECT ✅ Clean integration of default_branch parameter:

if default_branch is not None:
    payload["default_branch"] = default_branch

⚡ Performance Analysis

OPTIMAL PERFORMANCE

  • Zero regression: Sort functionality only activates when explicitly requested
  • Efficient filtering: Uses Python sets for contains/merged operations
  • Minimal Git commands: Optimized command construction and execution
  • Smart caching: No unnecessary repeated Git operations

🧪 Test Quality Assessment

Comprehensive & Well-Designed

  • Branch list tests: Cover all combinations of filters, sort modes, error conditions
  • Push validation tests: Test every mutual exclusion rule and success path
  • Integration tests: GitHub settings properly tested with new parameter
  • Mock design: Excellent use of factory functions for maintainable test setup

Test Coverage Highlights

  • test_git_branch_list.py: 31+ tests including sort functionality
  • test_git_push_delete.py: 27+ tests for delete/refspec with dry_run
  • test_github_repo_settings.py: Added coverage for default_branch

💡 Minor Enhancement Opportunities

Code Organization

  1. Consider extracting constants (git/models.py:146-153):

    FORCE_FLAGS = ["force", "force_with_lease", "force_if_includes"]
    INCOMPATIBLE_WITH_DELETE = FORCE_FLAGS + ["set_upstream", "refspec"]
  2. Documentation enhancement: Function docstrings could highlight backward compatibility more prominently

Future Considerations

  • Sort functionality could be extended to include more Git sort keys
  • Dry-run mode pattern could be applied to other destructive operations

✅ Issue Resolution Validation

Issue #171 - Branch List Enhancement

  • Properly registered in lean interface at lean/registry_git.py:452-458
  • Extended schema with filtering and sort options
  • Backward compatibility maintained via alias resolution
  • Comprehensive test coverage

Issue #172 - GitHub Default Branch

  • default_branch parameter added to model at github/models.py:422
  • Proper passthrough in handler at github/repos.py:139-140
  • Test coverage included

Issue #173 - Push Delete Support

  • Delete and refspec functionality fully implemented
  • All 5 mutual exclusion rules working correctly
  • Comprehensive validation at both model and handler levels
  • Extensive test coverage (27+ tests)

Issue #175 - Sort Support

  • Sort functionality implemented using git for-each-ref
  • Zero performance impact when not used
  • Proper integration with existing filters

Issue #176 - Dry Run Support

  • Dry-run flag orthogonal to all other options
  • Works with delete, refspec, and normal push modes
  • Clear feedback in return messages

🎯 Recommendation

APPROVE AND MERGE

This PR represents high-quality engineering work that successfully addresses all stated issues. The implementation demonstrates:

  • Excellent attention to validation and error handling
  • Comprehensive test coverage with quality test design
  • Thoughtful backward compatibility preservation
  • Clean, maintainable code structure
  • Zero security or performance concerns

The dual validation strategy, comprehensive test coverage, and careful attention to backward compatibility make this a exemplary contribution to the codebase.


@MementoRC MementoRC merged commit 170d186 into development May 20, 2026
16 checks passed
@MementoRC MementoRC deleted the feat/issues-171-172-173 branch May 20, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment