Skip to content

feat: wt cd --fetch tells what is new on the upstream branch - #29

Merged
lorenzolfm merged 3 commits into
mainfrom
fetch-whenever-i-jump
Nov 9, 2026
Merged

lorenzolfm merged 3 commits into
mainfrom
fetch-whenever-i-jump

Conversation

@lorenzolfm

Copy link
Copy Markdown
Owner

Problem

A jump to a worktree says nothing about the upstream branch. Commits that the author pushed after the last look stay unknown until a fetch. wt add --fetch does not help: for a worktree that exists, it returns before the fetch.

Change

wt cd -f <worktree>, wt <worktree> -f and wt add -f <branch> fetch the upstream branch of the worktree, and tell what each side has before the shell changes directory:

  fetching   origin refs/heads/feat
  upstream   origin/feat has 2 commits that feat does not have
  run wt follow to bring them here
  • The command changes no branch and no file. wt follow stays the command that moves the branch.
  • A failed fetch, for example with no network, is a warning. The shell still goes to the worktree.
  • The fetch moves the remote-tracking ref only when the new tip contains it, so git status shows [behind N]. After a rewrite the ref stays, because wt follow needs that record to move the branch. The report then says that the history is different.
  • In the short form the option goes after the name. wt -f deny is an option of wt itself, and the fish function passes -* through without a cd.
  • The fish completions offer -f/--fetch for cd and add, and --no-fetch for add.

Tests

  • follow::check has unit tests: nothing new, new commits upstream (the ref moves, the worktree does not), commits on each side, a rewrite (the ref stays and wt follow still moves the branch), an absent ref, no upstream branch or no branch, and a failed fetch.
  • I ran the binary end to end against a local remote: push, wt follow, a rewrite with and without local commits, and a remote that is gone.

A jump to a worktree says nothing about the upstream branch. Commits that
the author pushed after the last look stay unknown until a fetch, and the
jump does none. `wt add --fetch` does not help either: for a worktree that
exists, it returns before the fetch.

`wt cd -f`, `wt <worktree> -f` and `wt add -f` now fetch the upstream branch
of the worktree and tell what each side has: new commits upstream, commits
that only the local branch has, a divergence, or a rewrite. The command
changes no branch and no file, and the report names `wt follow` when it can
help. A failed fetch is a warning, and the shell still goes to the worktree.

The fetch moves the remote-tracking ref only when the new tip contains it,
as `git fetch` does, so `git status` shows the new commits. After a rewrite
the ref stays: it is the record that `wt follow` needs to move the branch.
- check and follow decide with one Plan. The report says "run wt follow"
  only when wt follow moves the branch. A commit that the author removed
  is no longer reported as local work.
- wt add --fetch does not fetch before it makes the worktree of a local
  branch. That fetch moved the remote-tracking ref after a rewrite, and
  wt follow then refused the move.
- check prints its own warning, so its callers do not repeat it.
- wt <worktree> names the word that it does not accept.
- wt add --fetch skips the first fetch only for a local branch that tracks
  its remote branch. A local branch with no upstream branch has no record
  to keep, so the command fetches it as before, for example a branch from
  the bare clone of wt clone.
- The command still deletes each ref that blocks a local branch. Without
  that, the report could not make the absent ref, and wt prune --no-fetch
  read the branch as gone.
- When wt follow would move the branch but the worktree has changes that
  are not committed, the report tells you to commit them first. wt follow
  refuses the move until then.
- The report of a worktree whose directory is absent says that there is no
  git repository, and not that the worktree has no branch.
@lorenzolfm
lorenzolfm merged commit 5420506 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