Workflow: new worktrees should start from the latest origin, not whatever I last pulled #4115
Replies: 4 comments
|
Implemented in #4116 — narrow per-branch fetch, no mutation of the user's checkout, strictly-behind-only fast-forward, opt-out toggle. Tests and before/after evidence are in the PR. |
|
Adding another occurrence of this, hit today on Paseo 0.7.1 (desktop, macOS 26.6.2, git 2.54.0). I created a new workspace off
So the cached If a smaller change is preferred over #4116: I have a server-only version at main...odoo-mvds:paseo:fix/branch-off-fetch-remote-base (16 lines in Happy to open it as a PR if that direction is wanted; otherwise +1 to #4116. |
|
That reflog is better evidence than anything in my write-up, and it corrects something I got wrong. I claimed in #4116 that staleness is bounded by the 180 s background fetch. It isn't. Your case is already covered by #4116, so I don't think anyone has to choose between the two on that basis. The two changes overlap rather than compete — same fix for the qualified base, and #4116 additionally handles the unqualified Two things where your version is the better shape and I'd rather adopt them than defend mine:
So: no objection at all to yours going in, and if the preference is the smaller change I'm happy for #4116 to be closed in favour of it, or reduced to just the unqualified- |
|
Opened the small version as #4287: server-only, fetches the one remote branch the base resolves to, falls back to the cached ref offline, real-git tests, bot review addressed. 116 lines in 2 files. So the choice is:
Happy with whichever direction you prefer; just need the call. |
Uh oh!
There was an error while loading. Please reload this page.
The workflow
I start most work by creating a new worktree workspace off
main. Often I haven't pulled in a while, so the agent starts working on history that already trails the remote. I only notice later, when the PR is based on old commits or a rebase turns up conflicts that shouldn't exist."Remember to pull first" is the kind of step I will keep forgetting.
What actually happens today
Nothing in the
branch-offcreation path fetches.resolveBaseBranchForWorktree(packages/server/src/utils/worktree.ts) only runsgit rev-parse --verifyagainstrefs/heads/<x>, thenrefs/remotes/origin/<x>— no network. The freshest those refs can be is the daemon's backgroundgit fetch origin --prune, which runs on a 180 s interval.Two things make it easy to miss:
resolveRepositoryDefaultBranchdeliberately prefers the local branch name over the remote-tracking ref, so an unqualifiedmainresolves to your possibly-stale localmain.createWorktreethen stores that resolved ref in the worktree metadata (baseRef: "refs/heads/main"), andgetCheckoutStatuscompares against exactly that stored ref. So a worktree cut from a 2-commit-stalemainreportsaheadBehind {ahead: 0, behind: 0}.Measured on a local repro:
The workspace is two commits behind the remote and nothing in the UI says so.
public-docs/worktrees.mdalready documents the manual workaround — "Useorigin/mainrather thanmain" — which is good advice nobody remembers to follow, and which doesn't help the New Workspace screen's default path orresolveDefaultBranch.Proposal
Before
git worktree add, refresh the base branch from its remote, then start from the remote tip when the local branch is purely behind it.git fetch <remote> <branch>— one branch, never--prune, never the repository-wide refspec. This matters for bug: background fetch can massively inflate partial-clone repositories #3335, where the broad background fetch inflates partial clones.git pull. That avoids every dirty-tree / diverged / branch-is-checked-out failure mode.refs/remotes/upstream/mainfetchesupstream, notorigin.fetchBase: falseon the create request for anyone whose fetching is managed outside Paseo.Default on, because branching off a stale base is almost never what you want.
Cost is small: two extra local git commands when there's no remote (one
config --get remote.<name>.url, onerev-list), plus onefetchwhen there is.Scope
Worktree workspaces only. Local isolation is deliberately untouched — there the workspace is your checkout, and pulling it automatically would mutate your working tree.
I have this implemented and tested and am happy to open the PR, but wanted to check the direction first per CONTRIBUTING. Two things I'd particularly like a call on:
All reactions