fix(git): fetch origin base before creating a new workspace branch#86
Merged
Zeus-Deus merged 1 commit intoJun 9, 2026
Conversation
New workspace branches resolve their base against origin/<base>, but nothing fetched first, so the ref was whatever the last fetch left behind and new agent workspaces could start from stale code. - git.rs: add fetch_origin_branch() — scoped `git fetch origin <base>` (--quiet --no-tags, GIT_TERMINAL_PROMPT=0, 10s kill-on-timeout cap, skipped for local-only repos) run before find_remote_ref in the new-branch path of git_create_worktree. Best-effort: offline or unreachable remotes fall back to the existing origin/<base> ref, else the local branch — creation never hard-fails. - remote/git.rs: same policy for the headless daemon's worktree_create path, which previously used the local base ref verbatim. - Calling commands already run on the blocking pool (spawn_blocking), so the fetch never stalls the UI. Tested with real git remotes: stale-clone tests assert the new branch starts at the freshly fetched remote tip; offline and no-remote repos still create worktrees from the fallback ref. Verified end-to-end against the codemux-remote daemon with a networked git server: fresh tip picked up, instant fallback when the remote is down, and a hung remote capped at the 10s timeout. Closes #76
9 tasks
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.
Closes #76
Problem
When creating a new workspace branch, the base is resolved against
origin/<base>— but nothing fetched first, so the ref was whatever the last fetch left behind. New agent workspaces could start from stale code and create avoidable merge conflicts. The headless daemon path didn't even prefer the remote ref.Changes
src-tauri/src/git.rs: newfetch_origin_branch()— scopedgit fetch --quiet --no-tags origin <base>withGIT_TERMINAL_PROMPT=0, a 10s kill-on-timeout cap (matches the sidebar divergence fetcher),origin/prefix normalization, and a cheap skip when the repo has nooriginremote. Called ingit_create_worktree's new-branch path beforefind_remote_ref, so the existing "latest remote commit" intent is now actually achieved. All failures are swallowed — offline / no-remote repos fall back to the existingorigin/<base>ref, else the local branch; creation never hard-fails.src-tauri/src/remote/git.rs: parity for the headless daemon'sworktree_createpath — same scoped fetch plus afind_remote_refmirror, so daemon-created branches also prefer a freshly-fetchedorigin/<base>instead of the local ref verbatim.docs/features/workspace-creation.md: documented the base-resolution policy.git_create_worktreeunderspawn_blocking, so the fetch never blocks the UI thread.Acceptance criteria
origin/<base>when a reachable remote existsspawn_blockingincommands/workspace.rsandcommands/git.rs--no-tags, single branch)Testing
8 new integration tests with real git remotes (bare origin + stale clone + publisher clone):
origin/mainis stale (desktop + daemon paths)origin/<base>, creation succeeds (both paths)End-to-end against the real
codemux-remotebinary with a networked git server (git daemonin a docker container overgit://):worktree_createvia the daemon HTTP tool API produced a worktree at the true remote tip, not the stale refcargo check,cargo test(1690 passed; the only 2 failures are pre-existing machine-environment artifacts, verified identical on a clean tree),npm run check,npm run test(1824 passed) all green.