fix(diff): bare path scopes the diff instead of failing as an unknown commit (muse#36)
`muse diff <path>` previously always treated its single positional as a commit ref, failing with "Commit '<path>' not found" for any ordinary file path -- a surprising divergence from `git diff <path>`.
- `commit_a` with no `commit_b`: try resolving as a commit ref first (100% unchanged behavior for every existing script/ref). Only when that fails, AND the token matches a tracked file or directory (HEAD manifest or working tree), fall back to treating it as a path filter -- folded into the existing --path/-p _filter_manifest machinery, not a parallel code path. - This transparently covers `muse diff -- <path>` too: argparse consumes the literal "--" before run() ever sees args, so an unresolvable commit_a from "-- <path>" is indistinguishable from the bare "<path>" case by the time this code runs -- same fallback, same fix. - Ref/path ambiguity (a token that is BOTH a valid ref and a tracked path): muse always prefers the ref, deterministically. True forced-path disambiguation via a literal "--" isn't observable after argparse finishes parsing without deeper parser-pipeline changes; this is the alternative the ticket explicitly sanctioned when "--" can't be detected. Documented in --help and the Gitism Glossary. - Exit-code consistency (ticket problem 3): verified already fixed on current code -- both the bare-path and "--"-prefixed forms of an unresolvable token already exit 1 identically; added a regression test so this can't silently regress.
Found and fixed a real, independent bug while building this: resolve_commit_ref (and thus every ref-taking command) crashed with an uncaught ValueError instead of returning "not found" whenever a ref-like candidate string contained '/' and wasn't a branch or remote-tracking ref -- read_version_tag called version_tag_path unconditionally, which raises for path-traversal- looking names (by design, for its own normal callers) but was never meant to be exposed to callers like resolve_commit_ref that probe arbitrary strings and need a clean None for "not a tag" rather than a crash. This blocked bare-path scoping for every path under a subdirectory (e.g. `muse diff sub/file.py`) -- not something this ticket introduced, but something it newly exercised and needed fixed to meet its own acceptance criteria. Fixed in read_version_tag() itself so every caller benefits, not just diff.
14 new tests in tests/test_diff_pathspec.py covering bare-path scoping (file and directory), the "--" separator, ref-vs-path ambiguity, exit-code consistency, and regression guards for --path/-p and the two-ref/no-args forms staying unaffected. 1 new regression test in test_core_version_tags.py for the read_version_tag fix. Confirmed via genuine RED (reverted both fixes) -> 7 of 15 failed as expected -> GREEN. 672-test regression sweep across every diff/version-tag/checkout-relevant suite passes with zero regressions.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Semantic Changes
39 symbols
Files Changed
+1
~4
1252 in snapshot
0 comments
muse hub commit comment sha256:0d3de0ee53b63667de053f3ad712184124142df86473b80939347b487a65d6af --body "your comment"
No comments yet. Be the first to start the discussion.