preview_git_commit
Preview git commit operation in dry-run mode to validate messages, check files to commit, and review repository status without executing the commit. Ensures accurate and compliant commits.
Instructions
Preview git commit operation without executing (dry-run mode).
Args: message: Commit message to preview 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)
Returns: Dict containing: - message: The commit message - is_valid: Whether message passes validation - files_to_commit: List of files that would be committed - dry_run: Always True for this tool - repository_status: Current repository state
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | ||
| repo_path | Yes | ||
| sign_off | No | ||
| stage_all | No |
Implementation Reference
- The core MCP tool handler for 'preview_git_commit'. Decorated with @mcp.tool(), it handles input parameters, initializes CommitzenService for the given repo_path, performs a dry-run preview of the git commit using the service's preview_commit_operation method, handles errors, and returns a formatted response dictionary with preview details including staged files, validation status, and repository status.@mcp.tool() @handle_errors(log_errors=True) def preview_git_commit( message: str, repo_path: str, stage_all: bool = False, sign_off: bool = True ) -> Dict[str, Any]: """ Preview git commit operation without executing (dry-run mode). Args: message: Commit message to preview 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) Returns: Dict containing: - message: The commit message - is_valid: Whether message passes validation - files_to_commit: List of files that would be committed - dry_run: Always True for this tool - repository_status: Current repository state """ # For backward compatibility with tests expecting git_enabled field 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}", "message": message, "dry_run": True, "repository_path": repo_path, } if not target_service.git_enabled: return { "git_enabled": False, "error": "Git operations not available - not in a git repository", "message": message, "dry_run": True, "repository_path": repo_path, } # Get preview from service preview_result = target_service.preview_commit_operation( message, sign_off=sign_off ) if "error" in preview_result: return { "git_enabled": True, "error": preview_result["error"], "message": message, "dry_run": True, "repository_path": repo_path, } git_preview = preview_result.get("git_preview", {}) return { "git_enabled": True, "message": message, "is_valid": preview_result.get("is_valid", False), "files_to_commit": git_preview.get("staged_files", []), "staged_files_count": git_preview.get("staged_files_count", 0), "would_execute": git_preview.get("would_execute", False), "dry_run": True, "repository_status": git_preview, "repository_path": git_preview.get("repository_path"), "success": True, } except Exception as e: logger.error(f"Failed to preview git commit: {e}") return { "git_enabled": False, "error": str(e), "message": message, "dry_run": True, "repository_path": repo_path, "success": False, }
- src/commit_helper_mcp/mcp_server.py:14-14 (registration)Import of the git_tools module in the main MCP server file, which triggers the registration of all @mcp.tool() decorated functions including preview_git_commit via module import.from .server import git_tools
- Supporting method in CommitzenService that delegates the preview logic to the orchestrator. Called by the tool handler.def preview_commit_operation( self, message: str, sign_off: bool = True, **kwargs ) -> Dict[str, Any]: """ Preview git commit operation with message validation. Delegates to orchestrator for coordinated preview. Args: message: Commit message to preview sign_off: Whether to add sign-off to commit (default: True) **kwargs: Additional commit options Returns: Dict containing preview results and validation status """ if self.orchestrator: return self.orchestrator.preview_commit_operation(