fn validate_merge_base()

in focus/operations/src/pull.rs [45:86]


fn validate_merge_base(app: Arc<App>, repo_path: &Path) -> Result<()> {
    let default_prefetch_ref_sha =
        git_helper::parse_ref(app.clone(), repo_path, PREFETCH_DEFAULT_REF)
            .expect("Could not parse default prefetch ref");
    let focus_sync_ref_sha = git_helper::parse_ref(app.clone(), repo_path, FOCUS_SYNC_REF)
        .expect("Could not parse `refs/focus/sync`");
    let current_head = git_helper::get_current_revision(app.clone(), repo_path)?;

    // If prefetch refs and HEAD are equal then we can exit early
    if default_prefetch_ref_sha == current_head {
        bail!("HEAD is up to date with prefetch, nothing to do.")
    }

    let merge_base_prefetch_and_head = git_helper::get_merge_base(
        app.clone(),
        repo_path,
        &current_head,
        PREFETCH_DEFAULT_REF,
        None,
    )
    .context(
        "Could not get merge-base between current HEAD and 'refs/prefetch/remotes/origin/master'",
    )?;

    // If prefetch is behind current HEAD, then exit early
    if merge_base_prefetch_and_head == default_prefetch_ref_sha {
        bail!("Exiting: Prefetch is behind HEAD");
    }

    // Tests fail if I take out the redundant clone here
    #[allow(clippy::redundant_clone)]
    let merge_base_focus_sync_and_head =
        git_helper::get_merge_base(app.clone(), repo_path, &current_head, FOCUS_SYNC_REF, None)
            .context("Could not get merge-base between current HEAD and 'refs/focus/sync'")?;

    // If focus sync is behind current HEAD, then exit early
    if merge_base_focus_sync_and_head == focus_sync_ref_sha {
        bail!("Exiting: refs/focus/sync is behind HEAD");
    }

    Ok(())
}