rtk icon indicating copy to clipboard operation
rtk copied to clipboard

`yadm <subcommand>` is rewritten to `rtk git`, so yadm commands act on the current project repo instead of the dotfiles repo — and bare `git add` becomes `git add .`

Open HetCreep opened this issue 3 months ago • 5 comments

Two rewrite-layer defects that combine into a data-integrity problem: commands aimed at one repository are executed against another, and a no-op form of git add is turned into a whole-tree stage.

Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). Both behaviours below were reproduced by running the shipped rtk 0.44.2 binary — commands and outputs are verbatim.

1. yadm is rewritten to git

src/discover/rules.rs:40-42 has one rule whose rewrite_prefixes are ["git", "yadm"] while its rtk_cmd is "rtk git". rtk git then executes the literal git binary (src/cmds/git/git.rs:39, resolved_command("git")) in the current working directory.

Observed:

$ rtk rewrite yadm status        →  rtk git status
$ rtk rewrite yadm commit -m x   →  rtk git commit -m x
$ rtk rewrite yadm add .         →  rtk git add .
$ rtk rewrite yadm list          →  rtk yadm list      ← correct

The whole point of yadm is that it manages a separate dotfiles repository whose work-tree is $HOME, while git in the same shell manages whatever project you are standing in. Rewriting yadm commit to git commit silently redirects the operation to the wrong repository.

yadm list going to rtk yadm list shows the intended path exists — src/filters/yadm.toml (match_command = "^yadm\b") handles it. The rule at rules.rs:40 shadows that filter for exactly the subcommands it enumerates, which include commit, push, checkout and add.

2. Bare git add gains a .

src/cmds/git/git.rs:938-939:

if args.is_empty() {
    cmd.arg(".");
}

Reproduced in a scratch repository containing an untracked .env:

$ git add                      # real git
Nothing specified, nothing added.
$ git diff --cached --name-only
                               # (nothing staged)

$ rtk git add
$ git diff --cached --name-only
.env
tracked.txt

Real git add with no pathspec is a deliberate no-op that prints guidance. Through rtk it stages everything, including files the user had not tracked.

3. Together

yadm add → rtk git add → git add . in the current directory: the entire working tree of whatever project you are standing in gets staged into that project's index, from a command the user aimed at their dotfiles.

Suggested directions (untested — no programmer has reviewed these)

  • Give yadm its own rule with rtk_cmd: "rtk yadm" (the TOML filter already exists and already works for the unenumerated subcommands), or drop "yadm" from that rule's rewrite_prefixes so it falls through to the filter for every subcommand.
  • Remove the cmd.arg(".") default and let git add with no pathspec behave as git does. If the intent was convenience, it changes the meaning of the command rather than its output format, which seems outside what a token-reducing wrapper should do.

A regression test asserting rtk rewrite yadm commit does not produce rtk git …, and one asserting rtk git add with no arguments stages nothing, would lock both.

HetCreep avatar Aug 04 '26 18:08 HetCreep

wshm · Automated triage by AI

🔍 Automated Triage

🐛 Category bug
🟠 Priority high
🎯 Confidence 93%

Summary

A rewrite rule aliases yadm to rtk git (redirecting dotfiles commands to the current project's repo) and rtk git add with no args defaults to git add . (staging untracked files, e.g. secrets); fix by giving yadm its own rtk yadm rule and removing the implicit . arg.

This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

📁 Relevant files
  • src/discover/rules.rs
  • src/cmds/git/git.rs
  • src/filters/yadm.toml

Triaged automatically by wshm · This is an automated analysis, not a human review.

pszymkowiak avatar Aug 04 '26 18:08 pszymkowiak

Re-verified at develop@5e0f92c. Both defects are still fully present and unchanged in substance — this is a citation correction, not a status change (verified by reading the code at this commit, not by building or running it).

1. yadm still gets rewritten to rtk git (wrong repo). Same file, lines drifted from my original rules.rs:40-42 citation to src/discover/rules.rs:58-70 — unrelated rules were added above it since I filed this:

:59  pattern: r"^(?:git|yadm)\s+(?:-[Cc]\s+\S+\s+)*(status|log|diff|show|add|commit|checkout|push|pull|branch|fetch|stash|worktree)",
:60  rtk_cmd: "rtk git",
:62  rewrite_prefixes: &["git", "yadm"]

The consuming loop that turns this into a rewrite is unchanged at src/discover/registry.rs:1752-1759: it walks rewrite_prefixes and strips whichever one matched, so yadm commit -m x still becomes rtk git commit -m x. This is intentional, not an oversight — the project's own test pins it, registry.rs:2606-2610:

test_rewrite_yadm_status: assert_eq!(rewrite_command_no_prefixes("yadm status", &[]), Some("rtk git status".to_string()))

There's no yadm-specific carve-out anywhere in the tree.

2. Bare git add still silently defaults to .. The file I originally cited, src/cmds/git/git.rs, no longer exists — commit 70ec493 ("chore: list command modules explicitly instead of via automod") renamed it to src/cmds/git/git_cmd.rs with a zero-line diff. run_add is now at git_cmd.rs:2326, and at :2333-2334 it's byte-identical to what I originally cited at git.rs:938-939:

if args.is_empty() { cmd.arg("."); }

It only moved because an unrelated arg-tokenizer/flag-classification refactor landed above it in the same file — nothing in that refactor touches run_add.

Nothing here has been fixed or weakened; both issues reproduce identically to the original report. Correcting my citations for anyone following up: please use src/discover/rules.rs:58-70 and src/cmds/git/git_cmd.rs:2326-2339 going forward instead of the line numbers in the original report.

HetCreep avatar Sep 16 '26 07:09 HetCreep

Re-checked on v1.0.0 (stable, 2026-10-13): the official release binary plus the v1.0.0 source. Provenance: AI-assisted check, human-directed. "ran" = executed against rtk 1.0.0 with a control; "read" = verified from source only.

Both defects are unchanged at v1.0.0 (ran); this is a cite refresh.

  • rtk rewrite 'yadm status' / 'yadm commit -m x' / 'yadm add .' / 'yadm push' / 'yadm -C x add .' -> rtk git ... (exit 3); rtk rewrite 'yadm list' -> rtk yadm list.
  • In a scratch repo with an untracked .env: real git add -> Nothing specified, nothing added. and stages nothing; rtk git add -> ok 2 files changed and stages .env + tracked.txt.
  • Current locations: src/discover/rules.rs:61/64 (pattern ^(?:git|yadm)..., rewrite_prefixes ["git","yadm"]); src/cmds/git/git_cmd.rs:2384-2385 (if args.is_empty() { cmd.arg(".") }, was git.rs:938); src/filters/yadm.toml unchanged.

HetCreep avatar Oct 14 '26 12:10 HetCreep

Re-verified at v1.2.1 (Homebrew rtk 1.2.1, macOS arm64). Both defects are still present at this version; this post-dates the v1.0.0 check above.

Provenance: every command and output below was run against the shipped rtk 1.2.1 binary. Control: the same binary and shell with the workaround at the bottom of this comment removed (rtk config file moved aside and restored), so the difference is the config, not the build.

1. yadm still rewrites to rtk git

$ rtk rewrite 'yadm status --short'   ->  rtk git status --short   (exit 3)
$ rtk rewrite 'yadm commit -m x'      ->  rtk git commit -m x      (exit 3)
$ rtk rewrite 'yadm push'             ->  rtk git push             (exit 3)
$ rtk rewrite 'yadm list'             ->  rtk yadm list            (exit 3, correct)
$ rtk rewrite 'git status --short'    ->  rtk git status --short   (exit 3)

2. Bare rtk git add still gains a .

Scratch repo with one tracked file and an untracked .env:

$ git add
Nothing specified, nothing added.
hint: Maybe you wanted to say 'git add .'?
$ git diff --cached --name-only
                              # empty

$ rtk git add
ok 1 file changed, 1 insertion(+)
$ git diff --cached --name-only
.env

What it looks like from an editor/agent hook

Wiring rtk rewrite into a pre_tool_call hook makes the symptom look unrelated: with the cwd at $HOME and no project repo, the rewrite turns a dotfiles command into a plain git command and it fails —

$ yadm status --short
fatal: not a git repository (or any of the parent directories): .git   # exit 128

— while command yadm status --short, the absolute path, or the same command inside a for loop all succeed, because the rewrite applies to the command string and anything that changes its shape escapes it. That inconsistency is what makes this expensive to diagnose from the outside.

Workaround for hook users, no code change

rtk config --create prints the config path it uses (on macOS: ~/Library/Application Support/rtk/config.toml). Add:

[hooks]
exclude_commands = ["yadm"]

With that file in place every yadm form above returns exit 1 (run unchanged), while git, ls, grep and the rest keep rewriting. Verified by moving the config away and back on the same binary.

prismatic7 avatar Nov 24 '26 18:11 prismatic7

Confirmed the bare-add case on stable RTK 1.2.1 on Ubuntu 26.04.1 x86-64 (Git 2.55.0) and Windows x64 (Git for Windows 2.55.0.windows.5).

In disposable repositories with an empty index and two dirty paths, git add exited 0 and staged nothing. On Ubuntu it printed Nothing specified, nothing added. to stderr. With rtk git add, exit was also 0, but git diff --cached --name-only now listed both paths on both platforms. On Ubuntu the paths were new (untracked) and tracked (modified), and RTK printed ok 2 files changed, 2 insertions(+). I expected the wrapped command to leave the index empty, as native Git did.

SNComrade avatar Nov 26 '26 14:11 SNComrade