Repository navigation
fix: wt gives git no name that git reads as an option - #18
Merged
Merged
Conversation
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
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.
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.
luneta builds wt in as a library, and its agent can call
wt::cmd::add::runwith a branch name that it read in an issue (lorenzolfm/luneta#210).make()rangit 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, butwt add -- <name>and any other caller were still open.--: the fetches,worktree add,branch --set-upstream-toandremote addinadd.rs,branch -d/-Dandmerge-baseindelete.rsandprune.rs, andcloneandworktree addinclone.rs. The doc comment ofgit.rsgives the rule.add.rsare one function,fetch_branch.--is not enough in two places.git fetchreads the branch as a refspec, so<src>:<dst>writes<dst>.git worktree add -b <name>gives the name togit branchwith no--.make()therefore refuses the branch and its upstream branch first, with the rule ofgit check-ref-format --branch(git::is_branch_name). The check is inmake(), so it also holds for the branch of a fork that GitHub gives.wt clonerefuses a HEAD of origin that is not a valid branch name, for the same reason.wt addrefuses such a name.wt addnow fails with<name> is not a valid branch namebefore 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 testruns 64 tests.cmd::add::runwith--upload-pack=touch <marker>and withmaster:refs/heads/other, and origin is a path. Each call fails withis not a valid branch name, and the marker and the branchotherare absent. Without the check inmake(), the error is the one fromgit worktree add. Without the check and the--, the fetch makes the marker.A manual test with the binary in a
.barerepository whose origin is a path:wt add -- "--upload-pack=touch <marker>"with the binary from main<name> is not a valid branch name. The marker is absent.wt add lorenzo/featlorenzo-feattracksorigin/lorenzo/feat.wt add brand-neworigin/master.