# TSK-0044: Create GitOperations Utility Module

**Type**: Task
**Status**: Open
**Priority**: Medium
**Assignee**: Engineer Agent
**Created**: 2025-07-24
**Epic**: Utility Module Integration Phase 3

## Description

Create a new GitOperations utility module that wraps common git commands using SubprocessRunner. This will centralize git operations, improve error handling, and provide a consistent interface for version control operations.

## Acceptance Criteria

- [ ] Create `src/claude_mpm/utils/git_operations.py` module
- [ ] Implement common git operations (status, add, commit, push, pull, etc.)
- [ ] Use SubprocessRunner for all git command execution
- [ ] Add proper error handling with meaningful error messages
- [ ] Support both synchronous and asynchronous operations
- [ ] Include branch management operations
- [ ] Add merge and rebase functionality with conflict detection

## Technical Details

### Core Operations to Implement:
```python
class GitOperations:
    def __init__(self, repo_path: str = "."):
        self.repo_path = repo_path
        self.runner = SubprocessRunner()
    
    # Basic operations
    def status(self) -> GitStatus
    def add(self, files: List[str])
    def commit(self, message: str, amend: bool = False)
    def push(self, remote: str = "origin", branch: str = None)
    def pull(self, remote: str = "origin", branch: str = None)
    
    # Branch operations
    def create_branch(self, branch_name: str, from_branch: str = None)
    def switch_branch(self, branch_name: str)
    def delete_branch(self, branch_name: str, force: bool = False)
    def list_branches(self, remote: bool = False)
    
    # Advanced operations
    def merge(self, branch: str, no_ff: bool = False)
    def rebase(self, onto: str, interactive: bool = False)
    def cherry_pick(self, commit_hash: str)
    def stash(self, message: str = None)
    def tag(self, tag_name: str, message: str = None)
```

### Error Handling:
```python
class GitError(Exception):
    """Base exception for git operations"""

class GitConflictError(GitError):
    """Raised when merge/rebase conflicts occur"""

class GitAuthError(GitError):
    """Raised when authentication fails"""
```

## Dependencies
- SubprocessRunner from `claude_mpm.utils.subprocess_runner`
- PathOperations for repository path validation

## Testing Requirements
- Unit tests for all git operations
- Integration tests with real git repositories
- Test error scenarios (conflicts, auth failures, etc.)
- Mock SubprocessRunner for unit tests
- Test both sync and async operations

## Implementation Notes
- Use structured output parsing for git commands
- Implement retry logic for network operations
- Add logging for all operations
- Consider git configuration validation
- Support for different git versions

## Success Metrics
- All git operations in codebase use GitOperations
- Improved error handling for git commands
- Reduced code duplication in version control modules
- Comprehensive test coverage (>90%)