Skip to content

fix: wt add makes no worktree inside the .git of a clone with a work tree - #17

Merged
lorenzolfm merged 2 commits into
mainfrom
plain-clone
Nov 9, 2026
Merged

lorenzolfm merged 2 commits into
mainfrom
plain-clone

Conversation

@lorenzolfm

@lorenzolfm lorenzolfm commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Repo::container gave the common directory of a clone that git clone made, which is its .git. wt add then made the new worktree inside it, for example project/.git/feature. luneta checks core.bare with its own git call before it calls the library (lorenzolfm/luneta#210). With GIT_DIR set, that call and the library read two different repositories, and the worktree went inside the .git of a clone anyway.

  • Repo reads core.bare when it is made, from the common directory that each later call uses, and it keeps the container only for a bare repository. git rev-parse --is-bare-repository gives false in a worktree of a bare repository, so it cannot tell.
  • Repo::container returns Result<&Path>. It gives an error for a clone with a work tree.
  • cmd::add::run gets the container first, so it refuses before it uses the network, adds a remote or changes an upstream branch.
  • Repo::at makes a Repo from a common directory inside the crate. discover, wt clone and the test fixtures use it.
  • wt delete still goes to the git directory when the repository has no container and no worktree of the base branch.
  • The README says that wt add refuses a clone that git clone made.

wt add in a clone that git clone made now fails. Before, it made the worktree inside .git. I think a refusal is right. A different choice is to make the worktree beside the work tree.

Test

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

  • One test clones origin with git clone and calls cmd::add::run. It fails with is the .git of a clone with a work tree, and .git/feature and the branch feature are absent.
  • One test makes a worktree of the bare repository and calls Repo::discover from it. Its container is the container of the bare repository.

A manual test with the binary:

Case Result
wt --repo plain add --no-fetch feat2 in a clone that git clone made Exit 1, the error above. plain/.git/feat2 is absent.
GIT_DIR=plain/.git wt --repo clone/main add --no-fetch feat3, with clone in the .bare layout Exit 1, the same error for plain/.git. No worktree in either.
wt --repo clone/main add --no-fetch feat4 Exit 0. stdout is the path of clone/feat4.

…tree

Repo::container gave the common directory of a clone that git clone
made, which is its .git. wt add then made the new worktree inside it.
luneta checked core.bare with its own git call before it called the
library. With GIT_DIR set, that call and the library read two different
repositories, and the worktree went inside the .git of a clone anyway.

Now Repo reads core.bare when it is made, from the common directory that
each later call uses, and holds the container only for a bare
repository. container() gives an error for a clone with a work tree, and
wt add refuses it before it uses the network or changes the config.
@lorenzolfm
lorenzolfm merged commit 0ad5e2f into main Nov 9, 2026
4 checks passed
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