fix(git): fix empty output when branch name contains '/' in git diff#1437
Merged
pszymkowiak merged 1 commit intortk-ai:developfrom Apr 22, 2026
Merged
Conversation
Branch names containing '/' (e.g. feature/user-auth, main...feature/auth) were incorrectly treated as file paths by the string heuristic in normalize_diff_args, causing '--' to be injected before them and making git treat them as pathspecs — resulting in silent empty output (exit 0). Replace looks_like_path() with a three-tier detection strategy: - Explicit path prefixes (. ~) → always a path, no filesystem check needed - Contains path separator (/ \) → use filesystem existence to distinguish branch names (feature/auth, not on disk) from real paths (src/main.rs) - Bare word with no separator → never inject '--', regardless of filesystem state (avoids misfire when a file shares a name with a branch/ref) Introduce normalize_diff_args_impl with injectable path-checker for testability. Update all existing tests to use mock existence checks. Add three regression tests: branch-with-slash, range-with-slash, and bare-word-that-exists-on-disk. Fixes: rtk-ai#1431 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b92ed32 to
13188a8
Compare
Collaborator
Real-binary test results ✅Tested with binary built from this branch (): # Test 1: branch name with / — was empty before fix
$ rtk git diff feature/user-auth
file.txt | 1 -
1 file changed, 1 deletion(-)
--- Changes ---
file.txt
@@ -1,2 +1 @@
-auth feature change
# Test 2: real file path still works
$ rtk git diff file.txt
file.txt | 1 +
1 file changed, 1 insertion(+)
--- Changes ---
# Test 3: 3-dot branch syntax feature/user-auth
$ rtk git diff HEAD...feature/user-auth → works correctlyAll cases pass. The filesystem-existence check correctly distinguishes |
pszymkowiak
approved these changes
Apr 22, 2026
Collaborator
pszymkowiak
left a comment
There was a problem hiding this comment.
Tested with real binary built from this branch. All cases confirmed working:
rtk git diff feature/user-authnow shows diff (was silent empty before)rtk git diff file.txtstill works (real path detection intact)rtk git diff HEAD...feature/user-auth(3-dot syntax) works- 1609 tests pass, no regressions
aeppling
approved these changes
Apr 22, 2026
Contributor
|
Hey, checking if path exist to differentiate branch / path is correct |
This was referenced Apr 25, 2026
Merged
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.
Summary
rtk git diff feature/user-authproduced silent empty output (exit 0) becausenormalize_diff_argstreated any arg containing/as a file path and injected--before it, causing git to interpret the branch name as a pathspec with no match.looks_like_path()with a three-tier detection strategy:.,~) → always a path/,\) → filesystem existence check to distinguishbranch names (
feature/auth, not on disk) from real paths (src/main.rs)--(avoids misfiring when a fileshares a name with a branch/ref, e.g. a file named
main)normalize_diff_args_implwith injectable path-checker for testability;update all existing tests to use mock existence checks; add three regression tests.
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test— 1609 passedgit diff HEAD~ src/deleted.rs(deleted file with/) stillworks correctly without
--injectionrtk git diffproduces empty output when branch name contains/#1431Investigated, implemented, and tested with the assistance of Claude Code (claude-sonnet-4-6).