Skip to main content

sync_default_branch

Function sync_default_branch 

Source
pub fn sync_default_branch(
    root: &Path,
    default: &str,
    warnings: &mut Vec<String>,
) -> bool
Expand description

Bring local default branch into sync with origin/<default> without ever pushing.

State matrix — each row documents why the mapped action is correct:

Equal → no-op. Local and origin are identical; nothing to do.

Behind → git merge --ff-only origin/<default> in the main worktree. The main worktree is always checked out on , so running the merge there updates both HEAD and the working tree atomically. If the merge fails (uncommitted local changes overlap with the incoming commits), we print MAIN_BEHIND_DIRTY_OVERLAP guidance and leave the working tree untouched. git’s own error detection is used rather than pre-emptively computing overlap.

Ahead → Print one info line so the user knows local has unpushed commits. No network call, no ref changes. Explicit pushes happen via apm state <id> implemented — apm sync NEVER pushes anything.

Diverged → Print guidance (rebase/merge/push steps). No ref changes. The dirty-aware variant is printed when the main worktree is unclean.

NoRemote → Silent skip. No origin is configured, or origin/<default> could not be resolved (e.g. fetch hasn’t run yet). Fetch failures are already surfaced as a warning by the existing fetch path in sync.rs.