Skip to content

bug: mc_sync targets HEAD@{upstream} instead of base branch — can no-op or sync wrong ref #32

@nigel-dev

Description

@nigel-dev

Description

syncWorktree() in src/lib/worktree.ts determines the sync target by first checking HEAD@{upstream}, falling back to origin/main. This has two problems:

  1. Syncs against origin, not local main. If you merge job A locally via mc_merge but haven't pushed, mc_sync on job B won't see job A's changes. The sequential merge workflow for standalone jobs requires pushing to origin between each merge.

  2. Can sync against the job's own tracking branch. If the job branch has an upstream set (e.g. after git push -u), HEAD@{upstream} resolves to the job's own remote branch — the sync effectively does nothing useful.

Expected Behavior

mc_sync should reliably sync against the project's base branch (main/master), with an option to target local vs origin:

  • Default: sync against the local base branch (covers the common mc_mergemc_syncmc_merge workflow)
  • Optional source: 'origin' flag for syncing against the remote

Current Behavior

// src/lib/worktree.ts — syncWorktree()
const upstreamResult = await gitCommand(
  ['-C', path, 'rev-parse', '--abbrev-ref', 'HEAD@{upstream}'],
);
// Falls back to origin/main if no upstream set

This logic should use getDefaultBranch() from src/lib/git.ts to determine the base branch, then target either the local ref or origin/<base>.

Proposed Fix

  1. Use getDefaultBranch() to determine base branch name
  2. Add source: 'local' | 'origin' parameter (default 'local')
  3. Target <baseBranch> for local, origin/<baseBranch> for origin
  4. Update src/tools/sync.ts to expose the new parameter

Files

  • src/lib/worktree.tssyncWorktree()
  • src/tools/sync.ts — tool definition
  • src/lib/git.ts — reuse getDefaultBranch()

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1: highImportant fix or feature — next up after criticalbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions