mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-05 21:39:54 +02:00
The bare cache used a mirror-style fetch refspec (+refs/heads/*:refs/heads/*) which collided with worktree-locked refs/heads/agent/<task> branches once those branches were pushed back to origin as PRs. git fetch aborted with "refusing to fetch into branch ... checked out at ...", the error was swallowed as a warning, and every subsequent checkout reused the snapshot from the original clone. Fix: - Clone / migrate bare caches to a remote-tracking layout (+refs/heads/*:refs/remotes/origin/*) so fetched heads never land in refs/heads/*. - Resolve the base ref from refs/remotes/origin/HEAD with a 5-level fallback (verified origin/HEAD symref to origin/main or origin/master to the bare HEAD bridged into origin/<same> to single-entry origin/* scan to bare HEAD for legacy caches). - Refuse to guess when refs/remotes/origin/* has multiple candidates and none match a known fallback, so CreateWorktree fails loudly instead of basing work on an arbitrary branch. - Refresh refs/remotes/origin/HEAD after every successful fetch, not just on the legacy migration path, so a cache that was already modern picks up an upstream default-branch change. - Verify the primary symref target actually exists so a phantom refs/remotes/origin/HEAD from a broken set-head does not surface a deleted branch. - Detect legacy caches on the fly and rewrite refspec + refs/remotes/origin/* + refs/remotes/origin/HEAD in place so existing clones self-heal on next use. - Serialize per-bare-repo mutation (both Sync and CreateWorktree) with sync.Map-backed mutexes so concurrent fetch and worktree add on the same repo cannot race on git's own lockfiles. - Narrow the already-exists retry to actual branch-collision errors so a path-collision no longer silently leaks a branch into the bare repo.