Skip to content

rtk git diff produces empty output when branch name contains / #1431

Description

@binsee

Summary

rtk git diff <branch> silently produces no output when the branch name contains a forward slash (e.g. feature/user-auth, main...feature/user-auth). Native git diff works correctly. Exit code is 0, so there is no error signal.

Root Cause

normalize_diff_args uses a string heuristic to decide whether to inject -- before positional arguments:

fn looks_like_path(arg: &str) -> bool {
    arg.contains('/') || arg.contains('\\') || arg.starts_with('.') || arg.starts_with('~')
}

Any argument containing / is treated as a file path. This causes rtk git diff feature/user-auth to be silently rewritten as git diff -- feature/user-auth, which tells git to treat the branch name as a pathspec — no matching file exists, so output is empty.

Reproduction

# Setup a fresh repo
mkdir /tmp/rtk-repro && cd /tmp/rtk-repro
git init
git commit --allow-empty -m "initial commit"
git checkout -b feature/user-auth
echo 'export function login(user, pass) { return auth(user, pass); }' > auth.js
echo 'export function logout() { clearSession(); }' >> auth.js
git add auth.js && git commit -m "add user auth module"
git checkout main
# Branch name with slash — native works, rtk empty
$ git diff feature/user-auth
diff --git a/auth.js b/auth.js
deleted file mode 100644
index 3f362f7..0000000
--- a/auth.js
+++ /dev/null
@@ -1,2 +0,0 @@
-export function login(user, pass) { return auth(user, pass); }
-export function logout() { clearSession(); }

$ rtk git diff feature/user-auth
(no output, exit code 0)

# Range syntax with slash — native works, rtk empty
$ git diff main...feature/user-auth
diff --git a/auth.js b/auth.js
new file mode 100644
index 0000000..3f362f7
--- /dev/null
+++ b/auth.js
@@ -0,0 +1,2 @@
+export function login(user, pass) { return auth(user, pass); }
+export function logout() { clearSession(); }

$ rtk git diff main...feature/user-auth
(no output, exit code 0)

Expected Behavior

rtk git diff feature/user-auth and rtk git diff main...feature/user-auth should produce the same output as their native git diff equivalents.

Workaround

Use a commit hash instead of a branch name:

rtk git diff $(git rev-parse feature/user-auth)

Environment

  • rtk: 0.37.1
  • OS: macOS (Apple Silicon)
  • Shell: zsh

Investigated and reproduced with the assistance of Claude (claude-sonnet-4-6).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Critical: causes LLM loops, worse than raw commandbugSomething isn't workingeffort-smallQuelques heures, 1 fichierfilter-qualityFilter produces incorrect/truncated signalgood first issueGood for newcomersresolved-pending-closeAnswered/resolved — will close if no response

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions