Skip to content

fix: wt gives git no name that git reads as an option - #18

Merged
lorenzolfm merged 4 commits into
mainfrom
option-injection
Oct 30, 2026
Merged

lorenzolfm merged 4 commits into
mainfrom
option-injection

Conversation

@lorenzolfm

Copy link
Copy Markdown
Owner

luneta builds wt in as a library, and its agent can call wt::cmd::add::run with a branch name that it read in an issue (lorenzolfm/luneta#210). make() ran git fetch <remote> <branch> with no --, so the name --upload-pack=<command> ran the command: on this machine when origin is a path, and on the server when the remote is reached by ssh. luneta refuses such a name on its side now, but wt add -- <name> and any other caller were still open.

  • Each git call that gets a name from the caller, from GitHub or from origin puts it after --: the fetches, worktree add, branch --set-upstream-to and remote add in add.rs, branch -d/-D and merge-base in delete.rs and prune.rs, and clone and worktree add in clone.rs. The doc comment of git.rs gives the rule.
  • The three fetches in add.rs are one function, fetch_branch.
  • -- is not enough in two places. git fetch reads the branch as a refspec, so <src>:<dst> writes <dst>. git worktree add -b <name> gives the name to git branch with no --. make() therefore refuses the branch and its upstream branch first, with the rule of git check-ref-format --branch (git::is_branch_name). The check is in make(), so it also holds for the branch of a fork that GitHub gives.
  • wt clone refuses a HEAD of origin that is not a valid branch name, for the same reason.
  • The README says that wt add refuses such a name.

wt add now fails with <name> is not a valid branch name before it runs git with the name. Before, git refused most of these names later with its own error, after the fetch had run.

This conflicts with #17 in make(). Whichever lands second gets a rebase.

Test

The four CI gates (nix build .#wt .#wt-clippy .#wt-test .#wt-fmt) pass. cargo test runs 64 tests.

  • One test calls cmd::add::run with --upload-pack=touch <marker> and with master:refs/heads/other, and origin is a path. Each call fails with is not a valid branch name, and the marker and the branch other are absent. Without the check in make(), the error is the one from git worktree add. Without the check and the --, the fetch makes the marker.

A manual test with the binary in a .bare repository whose origin is a path:

Case Result
wt add -- "--upload-pack=touch <marker>" with the binary from main The marker is present.
The same with this branch Exit 1, <name> is not a valid branch name. The marker is absent.
wt add lorenzo/feat Exit 0. lorenzo-feat tracks origin/lorenzo/feat.
wt add brand-new Exit 0. A new branch from origin/master.

Git reads an argument with '-' first as an option, also after a
positional argument. wt add ran `git fetch <remote> <branch>`, so the
branch `--upload-pack=<command>` ran the command: on this machine when
the remote is a path, and on the server when the remote is reached by
ssh. The branch comes from the caller, or from GitHub for the pull
request of a fork. A program that uses the library can pass a name that
it did not write.

Each git call that gets a name from the caller, from GitHub or from
origin now puts it after `--`. The three fetches in add.rs are one
function now.
`--` stops git from reading a name as an option, but git still reads
more than a name in two places. `git fetch` reads the branch as a
refspec, so `<src>:<dst>` writes `<dst>` in the repository. `git
worktree add -b <name>` gives the name to `git branch` with no `--`, so
a name with '-' first is again an option.

wt add now refuses the branch and its upstream branch before it runs
git with them, with the rule of `git check-ref-format --branch`. The
branch of a pull request from a fork comes from GitHub, so the rule
holds for it too. wt clone refuses a HEAD of origin that is not a valid
branch name, for the same reason.
`git check-ref-format --branch` refuses HEAD, but `refs/heads/HEAD` is a
valid ref, so `git::is_branch_name` accepted it. wt add then ran `git
worktree add -b HEAD`, and git refused the name with its own error.

The function now refuses HEAD itself, as the README and its doc comment
say.
@lorenzolfm
lorenzolfm merged commit b6b4887 into main Oct 30, 2026
4 checks passed
lorenzolfm added a commit to lorenzolfm/luneta that referenced this pull request Oct 30, 2026
…uld read as an option, in the place of luneta's own check

wt 820bc0e handed a branch's name to `git fetch` with no `--` before
it. #18 puts one before each name wt hands git, and refuses a name
`git check-ref-format` takes for no branch's: one with a `-` first, a
refspec as `master:refs/heads/other`, and `HEAD`. `Of::parse`'s own
refusal of a `-` first refused less, and is gone.
`a_name_with_a_dash_first_is_no_branch_s_and_runs_nothing` reads wt's
refusal last on stderr, and fails with a wt older than #18.

Cargo.lock changes in wt's source alone: `cargo update -p wt` moved
windows-sys back too, for the crates that build on Windows.
lorenzolfm added a commit to lorenzolfm/luneta that referenced this pull request Oct 30, 2026
… the PATH (#210)

* Make a pasted link's worktree with wt as a library, rather than wt on the PATH

The paste ran `wt add` by name, from the zellij server's PATH, and read
its last stdout line and its last `wt: ` stderr line as a contract. Now
lunetad depends on wt by a pinned git commit, and a hidden `luneta
worktree --repo <dir> <branch>` calls wt's `cmd::add::run` and prints
the path. pull.rs runs it as `current_exe()` through `run_alone`, as
before, so wt's and git's stderr stays off luneta's terminal and ssh
can't prompt there. It refuses a clone git made, as the paste already
did, since the ask box's agent can now run it too.

The ask box allows `luneta worktree` in place of `wt add`, and the
skill and the README say so. wt stays in the requirements: luneta only
makes a worktree in a clone `wt clone` made, and wt's post-checkout
hook makes the links of the ignored files.

Closes #199

* Take a pull request's link with no https:// for one, and make no worktree where git is told of another repository

`luneta worktree` took any text for its branch and handed it to wt,
which tells a link by its `://`: `github.com/o/n/pull/5`, which
`Link::parse` takes for a link, made a new branch of that name from
origin's default branch, with none of the pull request's commits. Its
argument is now an `Of`, a pull request or a branch, parsed by clap
with `Link::parse`, and handed to wt in full. An issue's link, or
another address on GitHub, is refused: the paste makes an issue's
branch before it has the worktree made.

`made` read the clone's layout with `local_git`, and wt's git read the
repository `GIT_DIR` named: with it set, the worktree went in the
`.git` of a clone git made. It now refuses where any variable of
`GIT_REPOSITORY_VARS` is set, and the ask box's `claude` has none of
them, so the agent's git and `luneta worktree` find the repository by
the directory.

A clone's layout is `Layout::Wt`, `Git` or `Unsaid`, where it was a
bool that took git not answering for a clone git made, and said so.

* Refuse a branch's name with a - first, which wt would hand git fetch for an option

`luneta worktree` took any text that was no link for a branch's name,
and wt hands the name to `git fetch origin <branch>` with no `--`
before it: after a `--` of its own, `--upload-pack=<command>` ran the
command where origin is a path, and on the server where it is reached
by ssh. The ask box's agent may run `luneta worktree`, and reads issues
anyone can write. git gives no branch a name with a `-` first, so
`Of::parse` refuses one, and nothing reaches wt.

* Build with wt's main of lorenzolfm/wt#18, which refuses a name git would read as an option, in the place of luneta's own check

wt 820bc0e handed a branch's name to `git fetch` with no `--` before
it. #18 puts one before each name wt hands git, and refuses a name
`git check-ref-format` takes for no branch's: one with a `-` first, a
refspec as `master:refs/heads/other`, and `HEAD`. `Of::parse`'s own
refusal of a `-` first refused less, and is gone.
`a_name_with_a_dash_first_is_no_branch_s_and_runs_nothing` reads wt's
refusal last on stderr, and fails with a wt older than #18.

Cargo.lock changes in wt's source alone: `cargo update -p wt` moved
windows-sys back too, for the crates that build on Windows.
@lorenzolfm
lorenzolfm deleted the option-injection branch November 9, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant