in focus/operations/src/pull.rs [141:212]
fn test_preflight_check() -> Result<()> {
let temp_sparse_dir = tempfile::tempdir()?;
let scratch_repo = ScratchGitRepo::new_static_fixture(temp_sparse_dir.path())?;
let repo_dir = scratch_repo.path();
let app = Arc::new(App::new_for_testing()?);
let head = git_helper::get_current_revision(app.clone(), repo_dir)?;
// ref existence check should fail when the required refs don't exist
assert!(validation_ref_existence(app.clone(), repo_dir).is_err());
// Create `refs/focus/sync`
let _ = git_helper::run_consuming_stdout(
repo_dir,
["update-ref", "refs/focus/sync", &head],
app.clone(),
)?;
// Create a default prefetch ref
let _ = git_helper::run_consuming_stdout(
repo_dir,
["update-ref", "refs/prefetch/remotes/origin/master", &head],
app.clone(),
)?;
// All required refs exist, ref existence check should succeed
assert!(validation_ref_existence(app.clone(), repo_dir).is_ok());
// Create a default remote ref
let _ = git_helper::run_consuming_stdout(
repo_dir,
["update-ref", "refs/remotes/origin/master", &head],
app.clone(),
)?;
// Since all refs point to the same commit, merge base validation should fail
assert!(validate_merge_base(app.clone(), repo_dir).is_err());
// Create a new branch and a new commit
scratch_repo.create_and_switch_to_branch("test-branch")?;
// Add a commit to our test branch, we will use this commit to move prefetch ahead
scratch_repo.make_empty_commit("test commit", None)?;
let new_commit = git_helper::get_current_revision(app.clone(), repo_dir)?;
// Update prefetch default to new commit
let _ = git_helper::run_consuming_stdout(
repo_dir,
[
"update-ref",
"refs/prefetch/remotes/origin/master",
&new_commit,
],
app.clone(),
)?;
// Switch back to `main` branch
let _ = git_helper::run_consuming_stdout(repo_dir, ["checkout", "main"], app.clone())?;
// Since focus/sync still points to `main` HEAD, merge base validation should still fail
assert!(validate_merge_base(app.clone(), repo_dir).is_err());
// Update focus/sync to new commit
let _ = git_helper::run_consuming_stdout(
repo_dir,
["update-ref", "refs/focus/sync", &new_commit],
app.clone(),
)?;
assert!(validate_merge_base(app, repo_dir).is_ok());
Ok(())
}