gabriel / muse public
Closed #21 Bug
filed by gabriel human · 46 days ago

muse branch --merged and --no-merged should accept commit IDs

0 Anchors
Blast radius
Churn 30d
0 Proposals

Bug

muse branch --merged <sha256:...> crashes with a ValueError from validate_branch_name because the argument is treated as a branch name unconditionally, not as a commit ID.

muse branch --merged sha256:c5131d76c6eada02939111fda4aa8e51b0c1456b9983727cfd6be101916de14e
ValueError: Branch name 'sha256:c5131d76...' contains forbidden characters

The same applies to --no-merged. Both flags should accept either a branch name or a sha256:-prefixed commit ID as their argument, since the use case of checking against a specific commit (not a named branch) is legitimate — e.g. checking against the tip of a remote tracking ref.

Root cause

In muse/cli/commands/branch.py around line 800, run() calls:

_into_tip = get_head_commit_id(root, _into)

get_head_commit_id calls validate_branch_name on its input unconditionally, before checking whether it might already be a commit ID.

Fix

Before calling get_head_commit_id, check whether the argument starts with sha256:. If so, validate it as a commit ID (64 hex chars after prefix) and use it directly. Only call get_head_commit_id for non-prefixed inputs.

if _into.startswith("sha256:"):
    _into_tip = _into   # already a commit ID — validate format, skip branch lookup
else:
    _into_tip = get_head_commit_id(root, _into)

Affected flags

  • muse branch --merged <ref>
  • muse branch --no-merged <ref>

Any other flags that resolve a ref via get_head_commit_id should get the same treatment.

Activity1
gabriel opened this issue 46 days ago
gabriel 18 days ago

Fixed on dev (sha256:fcdc40f3). Added _resolve_into_tip() in muse/cli/commands/branch.py: recognizes a well-formed sha256:-prefixed commit ID and uses it directly, falling back to the existing branch-name lookup (get_head_commit_id) otherwise — matches the fix sketch in the issue exactly. 4 new regression tests in tests/test_branch_merged_commit_id.py (commit-ID for --merged, commit-ID for --no-merged, existing branch-name path unchanged, diverged-branch-excluded-by-commit-ID). All 70 existing test_branch_supercharge.py tests still pass — no regressions.

closed this issue 18 days ago