gabriel / muse public
feat patch task/switch-command #1 / 1
gabriel · 166 days ago · Apr 14, 2026 · Diff

feat: implement muse switch — focused branch switcher

Cleaner alternative to checkout for branch operations. Delegates to checkout's internal machinery; adds: -c (create), -C (force-create / reset existing branch to HEAD), 'switch -' (previous branch via .muse/PREV_BRANCH), --discard-changes, --detach, --merge, --autostash, --dry-run, --json. 37 TDD tests: flag parsing, PREV_BRANCH helpers, all switch modes, security, stress.

sha256:6a15592f734c7b6517f7d77a04141c438f4f200f05973e4327912f04f65ad299 sha
+78 ~109 symbols
sha256:a54049666c63009120a14110aea87ea94bbb169ea48e5c11e5764629f6dd32dc snapshot
+78
symbols added
~109
symbols modified
0
dead code introduced
Semantic Changes 187 symbols
~ muse/cli/commands/switch.py .py 23 symbols added
+ _PREV_BRANCH_FILE variable variable _PREV_BRANCH_FILE L71–71
+ _prev_branch_path function function _prev_branch_path L79–80
+ _read_prev_branch function function _read_prev_branch L83–89
+ _run_force_create function function _run_force_create L323–411
+ _write_prev_branch function function _write_prev_branch L92–94
+ ExitCode import import ExitCode L56–56
+ annotations import import annotations L49–49
+ append_reflog import import append_reflog L57–57
+ argparse import import argparse L51–51
+ get_head_commit_id import import get_head_commit_id L59–59
+ logging import import logging L52–52
+ pathlib import import pathlib L53–53
+ read_current_branch import import read_current_branch L59–59
+ require_repo import import require_repo L58–58
+ sanitize_display import import sanitize_display L66–66
+ sys import import sys L54–54
+ validate_branch_name import import validate_branch_name L66–66
+ write_branch_ref import import write_branch_ref L59–59
+ write_head_branch import import write_head_branch L59–59
+ write_text_atomic import import write_text_atomic L59–59
+ logger variable variable logger L68–68
+ register function function register L102–188
+ run function function run L196–315
~ tests/test_cmd_switch.py .py 54 symbols added
+ TestRegisterFlags class class TestRegisterFlags L80–120
+ _parse method method _parse L81–87
+ test_autostash_flag method method test_autostash_flag L114–116
+ test_create_flag method method test_create_flag L89–92
+ test_detach_flag method method test_detach_flag L118–120
+ test_discard_changes_flag method method test_discard_changes_flag L98–100
+ test_dry_run_short method method test_dry_run_short L102–104
+ test_force_create_flag method method test_force_create_flag L94–96
+ test_json_flag method method test_json_flag L106–108
+ test_merge_flag method method test_merge_flag L110–112
+ _invoke function function _invoke L32–38
+ _prev_branch_path function function _prev_branch_path L71–72
+ _run function function _run L41–48
+ CliRunner import import CliRunner L21–21
+ InvokeResult import import InvokeResult L21–21
+ annotations import import annotations L13–13
+ get_head_commit_id import import get_head_commit_id L22–22
+ json import import json L15–15
+ os import import os L16–16
+ pathlib import import pathlib L17–17
+ pytest import import pytest L19–19
+ read_current_branch import import read_current_branch L22–22
+ repo function function repo L52–57
+ runner variable variable runner L24–24
+ test_read_prev_branch_missing_returns_none function function test_read_prev_branch_missing_returns_none L128–133
+ test_switch_C_creates_when_not_exists function function test_switch_C_creates_when_not_exists L209–212
+ test_switch_C_overwrites_existing_branch function function test_switch_C_overwrites_existing_branch L215–221
+ test_switch_already_on_branch function function test_switch_already_on_branch L168–172
+ test_switch_ansi_in_branch_name_rejected function function test_switch_ansi_in_branch_name_rejected L359–361
+ test_switch_c_creates_and_switches function function test_switch_c_creates_and_switches L185–189
+ test_switch_c_fails_if_branch_exists function function test_switch_c_fails_if_branch_exists L192–194
+ test_switch_c_points_to_current_head function function test_switch_c_points_to_current_head L197–201
+ test_switch_dash_returns_to_previous function function test_switch_dash_returns_to_previous L229–234
+ test_switch_dash_then_dash_bounces function function test_switch_dash_then_dash_bounces L250–256
+ test_switch_dash_without_history_exits_nonzero function function test_switch_dash_without_history_exits_nonzero L237–240
+ test_switch_detach_json function function test_switch_detach_json L344–351
+ test_switch_detach_moves_to_commit function function test_switch_detach_moves_to_commit L335–341
+ test_switch_dirty_tree_blocked_without_flag function function test_switch_dirty_tree_blocked_without_flag L264–268
+ test_switch_discard_changes_allows_dirty_switch function function test_switch_discard_changes_allows_dirty_switch L271–275
+ test_switch_dry_run_c_does_not_create_branch function function test_switch_dry_run_c_does_not_create_branch L294–296
+ test_switch_dry_run_does_not_change_branch function function test_switch_dry_run_does_not_change_branch L283–286
+ test_switch_dry_run_no_prev_branch_written function function test_switch_dry_run_no_prev_branch_written L289–291
+ test_switch_error_goes_to_stderr function function test_switch_error_goes_to_stderr L364–366
+ test_switch_json_action_created function function test_switch_json_action_created L314–319
+ test_switch_json_action_switched function function test_switch_json_action_switched L304–311
+ test_switch_json_dry_run function function test_switch_json_dry_run L322–327
+ test_switch_nonexistent_branch_exits_nonzero function function test_switch_nonexistent_branch_exits_nonzero L175–177
+ test_switch_rapid_toggle function function test_switch_rapid_toggle L374–382
+ test_switch_text_output function function test_switch_text_output L162–165
+ test_switch_to_existing_branch function function test_switch_to_existing_branch L150–153
+ test_switch_updates_head_file function function test_switch_updates_head_file L156–159
+ test_switch_writes_prev_branch_on_switch function function test_switch_writes_prev_branch_on_switch L243–247
+ test_write_then_read_prev_branch function function test_write_then_read_prev_branch L136–142
+ two_branch_repo function function two_branch_repo L61–68
← Older Oldest on task/switch-command
All commits
Newer → Latest on task/switch-command

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:6a15592f734c7b6517f7d77a04141c438f4f200f05973e4327912f04f65ad299 --body "your comment"