gabriel / muse public
feat patch feat/54-worktree-reflog #1 / 1
AI Agent gabriel · 13 hours ago · Oct 21, 2026 · Diff

feat: reflog entries for worktree add/remove (muse#54 item 9)

Creating a worktree with -b (a new branch) wrote the branch ref directly via write_branch_ref() with no reflog trace -- a genuine untracked ref move, unlike every other branch-creation path in this codebase. Fixed by appending a "branch: created from <base> via worktree add" entry immediately after.

Plain `worktree add` (reusing an existing branch) and `worktree remove` don't move any ref at all -- the branch itself is untouched either way -- so there's no ref transition to log in the strict sense. Logged same-value audit entries (old_id == new_id) on the worktree's branch instead, noting the worktree lifecycle event, matching this codebase's existing convention of logging non-moving events too (e.g. checkout's "already_on" case).

`worktree remove` captures the worktree's branch via list_worktrees() before remove_worktree() deletes its metadata, since there'd be nothing left to look up afterward.

New tests/test_worktree_reflog.py (4): add on an existing branch logs the worktree-created entry, add with -b logs both the branch-creation entry and the worktree-created entry (correctly ordered oldest-to-newest since both land on the same new branch's log), remove logs the removed entry, and removing a nonexistent worktree still fails cleanly (unaffected). Confirmed genuine RED (3/4 failed) before GREEN with the fix restored.

Targeted regression suite -- the new file plus test_cmd_worktree.py, test_cmd_worktree_hardening.py, test_worktree_supercharge.py, test_core_worktree.py -- all pass (306 passed), zero regressions.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

sha256:2b0e51e0e3e2002ffcf41dc5a1349af31d3eee4751d379cc6a8f100a20f9bd9c sha
+21 ~2 symbols
2 changed · 1222 in snapshot files
sha256:150fcb9bb1b5b63413c022b361c5f5b5860651c43fffd4fcd1adf7cca3e6a318 snapshot
+21
symbols added
~2
symbols modified
2
files changed
1222
files in snapshot
0
dead code introduced
Semantic Changes 23 symbols
~ tests/test_worktree_reflog.py .py 20 symbols added
+ TestWorktreeAddReflog class class TestWorktreeAddReflog L64–96
+ test_add_on_existing_branch_appends_entry method method test_add_on_existing_branch_appends_entry L65–76
+ test_add_with_new_branch_logs_branch_creation method method test_add_with_new_branch_logs_branch_creation L78–96
+ TestWorktreeRemoveReflog class class TestWorktreeRemoveReflog L99–125
+ test_remove_appends_entry_to_branch_log method method test_remove_appends_entry_to_branch_log L100–115
+ test_remove_nonexistent_worktree_does_not_crash method method test_remove_nonexistent_worktree_does_not_crash L117–125
+ _env function function _env L19–20
+ _init_repo function function _init_repo L23–36
+ _make_commit function function _make_commit L39–61
+ cli variable variable cli L15–15
+ CliRunner import import CliRunner L11–11
+ Manifest import import Manifest L12–12
+ annotations import import annotations L5–5
+ datetime import import datetime L7–7
+ fake_id import import fake_id L12–12
+ heads_dir import import heads_dir L13–13
+ json import import json L8–8
+ muse_dir import import muse_dir L13–13
+ pathlib import import pathlib L9–9
+ runner variable variable runner L16–16
~ muse/cli/commands/worktree.py .py 1 symbol added, 2 symbols modified
+ append_reflog import import append_reflog L45–45
Files Changed
+1 ~1
1222 in snapshot
← Older Oldest on feat/54-worktree-reflog
All commits
Newer → Latest on feat/54-worktree-reflog

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:2b0e51e0e3e2002ffcf41dc5a1349af31d3eee4751d379cc6a8f100a20f9bd9c --body "your comment"