fix: harden diff ref parsing in git worktree flow#46
Closed
bhattaraiprayag wants to merge 2 commits intoharshkedia177:mainfrom
Closed
fix: harden diff ref parsing in git worktree flow#46bhattaraiprayag wants to merge 2 commits intoharshkedia177:mainfrom
bhattaraiprayag wants to merge 2 commits intoharshkedia177:mainfrom
Conversation
- Reject refs that begin with '-' and verify refs with git rev-parse before running structural diff worktree operations. Pass refs to git worktree add after '--' so user-supplied refs cannot be parsed as git command options. - Add regression coverage for dash-prefixed refs, literal $(...) refs, and command argument construction with end-of-options separation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
This PR contains one focused bug fix for branch-diff ref handling, plus regression tests for that same behavior.
Why
axon diffpassed user-provided refs directly togit worktree add, so refs starting with-could be parsed as git options.What changed
_validate_ref(repo_path, ref)insrc/axon/core/diff.py:-git rev-parse --verify --quiet --end-of-options <ref>^{commit}diff_branches()now validatesbase_refand optionalcurrent_refbefore graph build/worktree operations._build_graph_for_ref()now calls:git worktree add <path> -- <ref>so user refs are always passed after end-of-options.
tests/core/test_diff.pyfor:main,feature/x,HEAD~1)$(id)refs (treated as plain ref text)diff_branches--separator presence in worktree command argsValidation
uv run pytest -q tests/core/test_diff.py->23 passeduv run pytest -q->591 passeduv run ruff check src/axon/core/diff.py tests/core/test_diff.py-> passuv run ruff format --check src/axon/core/diff.py tests/core/test_diff.py-> passaxon diff -- '--detach'-> rejectedaxon diff -- '$(id)'-> rejected as invalid refaxon diff 'HEAD~1..HEAD'-> succeeds for valid refsCloses #35
Closes #38
Checklist
pytestpasses locallyruff check src/ tests/passes