in focus/operations/src/testing/sync.rs [455:510]
fn sync_skips_checkout_with_unchanged_profile_internal(
sync_mode: SyncMode,
) -> Result<SyncMechanism> {
let snapshot_label = SnapshotLabel::new(format!(
"sync_skips_checkout_with_unchanged_profile_internal_{:?}",
sync_mode
));
init_logging();
let fixture = RepoPairFixture::with_sync_mode(sync_mode)?;
fixture.perform_clone()?;
let path = fixture.sparse_repo_path.clone();
let profile_path = fixture
.sparse_repo()
.unwrap()
.working_tree()?
.sparse_checkout_path();
let initial_profile_contents = std::fs::read_to_string(&profile_path)?;
// Add performs a checkout.
let targets = vec![String::from("bazel://library_b/...")];
assert!(!crate::selection::add(
&fixture.sparse_repo_path,
false, // Skip sync
targets,
false,
fixture.app.clone(),
)?,); // Assert that the add did *NOT* sync
let add_profile_contents = std::fs::read_to_string(&profile_path)?;
assert_eq!(initial_profile_contents, add_profile_contents); // Nothing has changed yet
assert_snapshot!(snapshot_label.next(), add_profile_contents);
// Make sure our selection now contains the requested target
let selection = fixture.sparse_repo()?.computed_selection()?;
let library_b_target = Target::try_from("bazel://library_b/...")?;
assert!(selection.targets.contains(&library_b_target));
// The first sync performs a checkout since the profile changed.
let sync_result = crate::sync::run(&SyncRequest::new(&path, sync_mode), fixture.app.clone())?;
let first_sync_profile_contents = std::fs::read_to_string(&profile_path)?;
assert_snapshot!(snapshot_label.next(), first_sync_profile_contents);
assert!(sync_result.checked_out);
// Subsequent sync does not perform a checkout.
let sync_result = crate::sync::run(&SyncRequest::new(&path, sync_mode), fixture.app.clone())?;
let subsequent_sync_profile_contents = std::fs::read_to_string(&profile_path)?;
assert_snapshot!(snapshot_label.next(), subsequent_sync_profile_contents);
// TODO: Figure out why incremental sync indicates checkout here and why the first and subsequent sync differ, then enable this assertion
// assert!(!sync_result.checked_out);
// // The profiles should be identical
// assert_eq!(first_sync_profile_contents, subsequent_sync_profile_contents);
Ok(sync_result.mechanism)
}