Skip to content

feat: Add interactive branch switch command #32

@mark-pro

Description

@mark-pro

Summary

Add a new command dgr switch that provides both direct branch switching and an interactive tree-based branch selection UI.

User Stories

  • As a developer, I want to quickly switch between branches in my stack so that I can work on different parts of a feature without typing long branch names.
  • As a developer, I want to see a visual tree of my branches when switching so that I understand the context of the branch I am switching to.

Acceptance Criteria

  • dgr switch enters interactive mode if no branch is specified.
  • Interactive mode displays an indented tree of tracked branches.
  • Current selection is marked with ->.
  • Arrow keys and hjkl navigate the selection.
  • Enter switches to the selected branch and prints a confirmation message.
  • Esc or q exits interactive mode without switching.
  • dgr switch <branch> switches directly to <branch> if it exists.
  • The UI includes a footer listing available shortcuts.

Implementation Notes

  • UI Framework: Use ratatui for the interactive TUI.
  • Branch Data: Leverage crate::core::tree::run(&TreeOptions::default()) to get the TreeView.
  • Tree Rendering: Flatten the TreeView into a list for easier selection management while maintaining indentation levels.
  • Git Integration: Use crate::core::git::switch_branch(branch_name) for the actual switch.
  • CLI Structure:
    • Add switch to src/cli/mod.rs.
    • Create src/cli/switch/mod.rs for command handling.
    • Create src/cli/switch/interactive.rs for TUI logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions