execute_git_commit
Automate and safely execute git commits with user approval. Requires force_execute=True to perform actual commit, ensuring controlled and secure version control operations.
Instructions
Execute actual git commit with safety checks and user approval.
SAFETY: Requires force_execute=True to perform actual commit.
Args: message: Commit message to use repo_path: Path to git repository stage_all: Whether to stage all changes before commit (not implemented yet) sign_off: Whether to add sign-off to commit (default: True) force_execute: Must be True to execute actual commit (safety flag)
Returns: Dict containing: - success: Whether commit was successful - message: The commit message used - executed: Whether commit was actually executed - error: Error message (if failed) - dry_run: False if actually executed, True if preview only
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| force_execute | No | ||
| message | Yes | ||
| repo_path | Yes | ||
| sign_off | No | ||
| stage_all | No |
Implementation Reference
- The core handler function for the 'execute_git_commit' MCP tool. Decorated with @mcp.tool(), it performs the git commit operation with mandatory safety checks (force_execute=True required for actual execution). Delegates to CommitzenService.execute_commit_operation.@mcp.tool() def execute_git_commit( message: str, repo_path: str, stage_all: bool = False, sign_off: bool = True, force_execute: bool = False, ) -> Dict[str, Any]: """ Execute actual git commit with safety checks and user approval. SAFETY: Requires force_execute=True to perform actual commit. Args: message: Commit message to use repo_path: Path to git repository stage_all: Whether to stage all changes before commit (not implemented yet) sign_off: Whether to add sign-off to commit (default: True) force_execute: Must be True to execute actual commit (safety flag) Returns: Dict containing: - success: Whether commit was successful - message: The commit message used - executed: Whether commit was actually executed - error: Error message (if failed) - dry_run: False if actually executed, True if preview only """ try: # Initialize service for the specified repository try: target_service = CommitzenService(repo_path=repo_path) except Exception as e: return { "git_enabled": False, "error": f"Failed to initialize service for repository '{repo_path}': {e}", "success": False, "executed": False, "message": message, "repository_path": repo_path, } if not target_service.git_enabled: return { "git_enabled": False, "error": "Git operations not available - not in a git repository", "success": False, "executed": False, "message": message, "repository_path": repo_path, } # Execute commit with safety checks result = target_service.execute_commit_operation( message=message, force_execute=force_execute, sign_off=sign_off ) # Add dry_run flag based on execution result["dry_run"] = not result.get("executed", False) result["git_enabled"] = True result["repository_path"] = repo_path return result except Exception as e: logger.error(f"Failed to execute git commit: {e}") return { "git_enabled": False, "error": str(e), "success": False, "executed": False, "message": message, "dry_run": True, "repository_path": repo_path, }
- src/commit_helper_mcp/mcp_server.py:33-43 (registration)Import of git_tools module functions in the main MCP server file, which re-exports 'execute_git_commit' for compatibility and ensures module-level registration via prior import of git_tools module.# Git tools from .server.git_tools import ( get_git_implementation_info, get_enhanced_git_status, get_git_status, preview_git_commit, execute_git_commit, generate_and_commit, validate_commit_readiness, stage_files_and_commit, )
- Usage of execute_git_commit within the generate_and_commit tool as a helper function to perform the actual commit after message generation.commit_result = execute_git_commit( message=generated_message, repo_path=repo_path, sign_off=sign_off, force_execute=True, # Since user explicitly set preview_only=False )