Repository navigation
feat: wt follow brings a worktree to its upstream branch - #28
Merged
Merged
Conversation
`wt add` goes to the worktree that has the branch, and does not change it. A second look at a pull request therefore reads the commits of the first look, and nothing says so. `--fetch` does not help: it runs after the return for a worktree that exists, and a local branch wins over the ref it fetched. `wt follow` fetches the upstream branch, and moves the local branch when the move cannot lose work: the branch is behind, or the upstream branch was rewritten and the local branch is where the remote-tracking ref was before the fetch. It refuses a change that is not committed, commits that the remote does not have, and an untracked file in the way. A branch that is at the upstream branch needs no move, so a change there does not stop it. The fetch moves the remote-tracking ref itself, so the next rewrite also finds the branch where the ref was.
lorenzolfm
force-pushed
the
follow-upstream
branch
from
November 5, 2026 19:11
906e6ae to
4bbe91f
Compare
lorenzolfm
added a commit
to lorenzolfm/luneta
that referenced
this pull request
Nov 5, 2026
The moves had nothing of luneta's in them, and two parts of them were there only because luneta cannot see what wt knows: setting the upstream by hand after fetching `refs/pull/N/head`, and rebuilding the pull request's branch from git's config. wt fetches the upstream branch itself, which moves the ref, and `wt add <link>` already makes that the pull request's. luneta keeps what is about a pull request: `gh` for the base and the head, the base's fetch, and a check that the worktree came to the head, which stands in for the check of its branch. It runs wt as `luneta follow`, a program of its own and alone, as `luneta worktree` is: wt talks on stderr, and git may ask for a passphrase. Pins wt to lorenzolfm/wt#28's head, to pin again once that merges.
`git reset --keep` refuses to overwrite an untracked file only when git does not ignore it. Each link that wt makes is an ignored file. A path that the upstream branch started to track therefore replaced the link, and it deleted an ignored directory in its way, with no message. The command now moves with `git switch --no-overwrite-ignore`. That also refuses to move the branch under a paused `git am` or cherry-pick. The fetch moved the remote-tracking ref before the checks, and that ref is the only record of a rewrite. After one refusal, each later run refused the branch. The fetch now uses an empty refmap, and the ref moves after the move. A different fetch still removes the record. The README says so, and the refusal gives the command that moves the branch. The short form `wt f` hid the jump to the only worktree whose name starts with f, so remove it. The command also refuses a directory that is not in a worktree, before the fetch.
lorenzolfm
added a commit
to lorenzolfm/luneta
that referenced
this pull request
Nov 5, 2026
lorenzolfm/wt#28 merged as fc6bcd4, with a fix on top of the commit this pinned. A move no longer overwrites an ignored file, which each of wt's links is. A refusal keeps the record of a rewrite, so `r` goes on once the cause is gone. A rewrite another fetch saw first is still refused, and the refusal now gives the command that moves the branch. Two of these are tested here as well as in wt. luneta fetches the base just before wt reads that record, and the command has to reach the note whole, as the last of the three lines wt says. That fix moves the remote-tracking ref after the move, from the directory it is given. A pane in a directory the head leaves out gave it one the move had just deleted, so wt moved the branch, failed, and left the ref behind, which loses the record for the next rewrite. luneta now gives wt the worktree's top, which no move deletes, and says that the pane's directory has gone.
lorenzolfm
added a commit
to lorenzolfm/luneta
that referenced
this pull request
Nov 6, 2026
The moves had nothing of luneta's in them, and two parts of them were there only because luneta cannot see what wt knows: setting the upstream by hand after fetching `refs/pull/N/head`, and rebuilding the pull request's branch from git's config. wt fetches the upstream branch itself, which moves the ref, and `wt add <link>` already makes that the pull request's. luneta keeps what is about a pull request: `gh` for the base and the head, the base's fetch, and a check that the worktree came to the head, which stands in for the check of its branch. It runs wt as `luneta follow`, a program of its own and alone, as `luneta worktree` is: wt talks on stderr, and git may ask for a passphrase. Pins wt to lorenzolfm/wt#28's head, to pin again once that merges.
lorenzolfm
added a commit
to lorenzolfm/luneta
that referenced
this pull request
Nov 6, 2026
lorenzolfm/wt#28 merged as fc6bcd4, with a fix on top of the commit this pinned. A move no longer overwrites an ignored file, which each of wt's links is. A refusal keeps the record of a rewrite, so `r` goes on once the cause is gone. A rewrite another fetch saw first is still refused, and the refusal now gives the command that moves the branch. Two of these are tested here as well as in wt. luneta fetches the base just before wt reads that record, and the command has to reach the note whole, as the last of the three lines wt says. That fix moves the remote-tracking ref after the move, from the directory it is given. A pane in a directory the head leaves out gave it one the move had just deleted, so wt moved the branch, failed, and left the ref behind, which loses the record for the next rewrite. luneta now gives wt the worktree's top, which no move deletes, and says that the pane's directory has gone.
lorenzolfm
added a commit
to lorenzolfm/luneta
that referenced
this pull request
Nov 6, 2026
The moves had nothing of luneta's in them, and two parts of them were there only because luneta cannot see what wt knows: setting the upstream by hand after fetching `refs/pull/N/head`, and rebuilding the pull request's branch from git's config. wt fetches the upstream branch itself, which moves the ref, and `wt add <link>` already makes that the pull request's. luneta keeps what is about a pull request: `gh` for the base and the head, the base's fetch, and a check that the worktree came to the head, which stands in for the check of its branch. It runs wt as `luneta follow`, a program of its own and alone, as `luneta worktree` is: wt talks on stderr, and git may ask for a passphrase. Pins wt to lorenzolfm/wt#28's head, to pin again once that merges.
lorenzolfm
added a commit
to lorenzolfm/luneta
that referenced
this pull request
Nov 6, 2026
lorenzolfm/wt#28 merged as fc6bcd4, with a fix on top of the commit this pinned. A move no longer overwrites an ignored file, which each of wt's links is. A refusal keeps the record of a rewrite, so `r` goes on once the cause is gone. A rewrite another fetch saw first is still refused, and the refusal now gives the command that moves the branch. Two of these are tested here as well as in wt. luneta fetches the base just before wt reads that record, and the command has to reach the note whole, as the last of the three lines wt says. That fix moves the remote-tracking ref after the move, from the directory it is given. A pane in a directory the head leaves out gave it one the move had just deleted, so wt moved the branch, failed, and left the ref behind, which loses the record for the next rewrite. luneta now gives wt the worktree's top, which no move deletes, and says that the pane's directory has gone.
lorenzolfm
added a commit
to lorenzolfm/luneta
that referenced
this pull request
Nov 6, 2026
* Sync a pull request's worktree before `r` reviews it `r` started its review on whatever the clone last fetched, so a second review after a push or a force-push read the commits the first one did, and nothing said so. `r` now fetches the pull request's head and its base in `ready`, on the machine that has the repository, and starts no review where it cannot bring the worktree to the head. `w` and `t` go on as they did. The upstream is set to the head after a sync. Left behind, it would stop matching the tip, and the next force-push would look like local commits. A worktree moves only while the pull request's branch is checked out, as a pane the daemon last saw there may be on `main` by now. A daemon older than `at_head` ignores it, so the answer says it too, and luneta refuses an answer that does not. Closes #291 * Have `wt follow` move the worktree for `r` The moves had nothing of luneta's in them, and two parts of them were there only because luneta cannot see what wt knows: setting the upstream by hand after fetching `refs/pull/N/head`, and rebuilding the pull request's branch from git's config. wt fetches the upstream branch itself, which moves the ref, and `wt add <link>` already makes that the pull request's. luneta keeps what is about a pull request: `gh` for the base and the head, the base's fetch, and a check that the worktree came to the head, which stands in for the check of its branch. It runs wt as `luneta follow`, a program of its own and alone, as `luneta worktree` is: wt talks on stderr, and git may ask for a passphrase. Pins wt to lorenzolfm/wt#28's head, to pin again once that merges. * Pin wt to the merge of `wt follow`, and follow from the top lorenzolfm/wt#28 merged as fc6bcd4, with a fix on top of the commit this pinned. A move no longer overwrites an ignored file, which each of wt's links is. A refusal keeps the record of a rewrite, so `r` goes on once the cause is gone. A rewrite another fetch saw first is still refused, and the refusal now gives the command that moves the branch. Two of these are tested here as well as in wt. luneta fetches the base just before wt reads that record, and the command has to reach the note whole, as the last of the three lines wt says. That fix moves the remote-tracking ref after the move, from the directory it is given. A pane in a directory the head leaves out gave it one the move had just deleted, so wt moved the branch, failed, and left the ref behind, which loses the record for the next rewrite. luneta now gives wt the worktree's top, which no move deletes, and says that the pane's directory has gone. * Run no git hook while `r` syncs a worktree wt's fix took `wt follow` from `reset --keep` to `switch -C`, and `switch` runs `post-checkout`. Where a clone's `core.hooksPath` is a path in the tree, as `.githooks` often is, that hook is the one in the head just checked out, so pressing `r` ran the author's script, with no agent and nothing to approve. Ref updates run `reference-transaction` from the same place, in wt's move and in the base's fetch of the next `r`. wt's add runs git from `.bare`, which finds no such hook, so a worktree's first `r` never had this. `to_head` now gives its fetch and `luneta follow` `core.hooksPath=/dev/null`, through `GIT_CONFIG_*`, which reaches each git wt starts with no change to wt, and adds to what the daemon's environment has. wt's own hook acts only on a new worktree, so a move loses nothing of it. Other hooks do not run for the move either, as they did not for `reset --keep`. Git run in that tree afterwards, by hand or by an agent, can still run one: that comes with such a `core.hooksPath`. * Let `r` go on where no remote names the repository A pane on the branch needed no remote before this branch, as gh names its pull request by itself. `to_head` started by looking the remote up, so `r` there was refused, even at the head, in a repository GitHub renamed, a fork's clone with the parent as gh's default, an `insteadOf` spelling, or `ssh.github.com:443`. With no remote named there is no base to fetch, and the check at the head is what guards the review, so it goes on to that. git not saying its remotes still starts no review. `t` on an issue goes back to main's code. Keep `core.fsmonitor` off for the fetch and `luneta follow` too. By a path in the tree it is the author's script, as a hook in `core.hooksPath` is, and lunetad's own `git status` has it off already. `core.hooksPath` does not reach a hook named by `hook.<name>.command`, so the README now says that one runs.
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.
wt add <link>goes to the worktree that has the branch, and does not change it. A second look at a pull request therefore reads the commits of the first look, and nothing says so.--fetchdoes not help: it runs after the return for a worktree that exists, and a local branch wins over the ref it fetched.wt followbrings the current worktree to its upstream branch. luneta needs this for lorenzolfm/luneta#291, where pressingron a pull request's link should review what GitHub has. The operation knows nothing of pull requests:wt add <link>already makes the branch track the head of the pull request, also from a fork.What changes
cmd::follow::run(dir)takes a worktree directory and noRepo, because it makes no worktree. It works in a clone with a work tree too. It refuses a directory that is not in a worktree, before the fetch.git switch --no-overwrite-ignore -C, for the fast-forward and for the rewrite.git reset --keepis not safe here: it overwrites an ignored file, and each link that wt makes is an ignored file. It also moves the branch under a pausedgit am, and it ends a paused cherry-pick.git switchrefuses all of these.--refmap=). A refusal therefore keeps the record of a rewrite, and the next run can move the branch. The ref moves after a move, or when the branch is at the upstream branch already, so the next rewrite also finds the branch at the ref.branch.<name>.mergeis fetched as it is, so a branch fromgh pr checkoutthat merges fromrefs/pull/N/headalso follows. That ref has no remote-tracking ref, so a rewrite there is refused.Choices to check
git fetchorwt prunebetween two looks moves the remote-tracking ref, and then nothing records the old commits. The command refuses, says that it cannot tell your work from the old commits of a rewrite, and prints the command that moves the branch. The README says this. A real fix needs wt to keep its own record, so that is a separate change.git statuscan look out of date until a move or a different fetch.wt fstays the jump to the only worktree whose name starts withf.wt cloneleaves branches with no upstream.git clone --baremakes each remote branch a local branch with no upstream, andwt followrefuses those and says how to set one.wt add <link>sets the upstream, so pull requests are not affected.wt add <branch>with a local branch does not; I left that alone.wt syncis taken: it makes the links.Testing
wt,wt-clippy,wt-testandwt-fmtpass: 109 tests, 20 of them for this command, on real git.refs/remotes/, which matters only when a local upstream branch moves during the run.wt cloneof a local remote, including--repofrom another directory: at the upstream branch, behind, rewritten, a change, a local commit and a rewrite, no upstream, no branch, an ignored file, an ignored directory, a link to a file and to a directory, a retry after each refusal, a different fetch, a pausedgit am, cherry-pick and merge, a fork remote and a local upstream. Alsowt fandwt followthrough the fish function.4bbe91f, and it needs a bump to the merge.