Skip to content

[Refactoring] Break up WorktreeCreator god class #12

@renekris

Description

@renekris

Problem Statement

WorktreeCreator violates Single Responsibility Principle with 9 private methods handling URL parsing, git operations, external tools, file I/O, and user interaction. 490 lines makes it difficult to test, maintain, and extend.

Current Responsibilities

  • URL parsing and validation (_parse_github_url)
  • Git remote detection (_detect_git_remote)
  • Branch name generation (_generate_branch_name, _sanitize_title)
  • Branch conflict handling (_check_branch_conflict)
  • Worktree creation (_create_worktree)
  • File writing (_write_task_file)
  • Editor opening (_open_shuvcode)
  • Orchestration (create_from_github_url)

Proposed Solution

Split into focused classes with single responsibilities using dependency injection.

Implementation Steps:

  • Create url_parser.py with URL parsing logic
  • Create branch_namer.py with branch name generation
  • Create worktree_manager.py with worktree management interface
  • Create workmux_manager.py implementing worktree manager
  • Refactor WorktreeCreator to pure orchestrator (~150 lines)
  • Implement dependency injection for all services
  • Add unit tests for each new class
  • Update integration tests for refactored structure

Alternative Approaches

  • Use dependency injection container (e.g., dependency-injector)
  • Implement builder pattern for complex initialization
  • Use composition over inheritance for flexibility

Area

  • Refactoring

Estimated Effort

  • Medium (1-2d)

Acceptance Criteria

  • WorktreeCreator reduced to < 200 lines (from 490)
  • Each new class has single responsibility (< 150 lines)
  • All existing tests pass after refactoring
  • New classes have proper unit tests
  • Dependency injection allows easy testing
  • Interfaces/protocols enable alternative implementations

Related Issues

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions