mod common;
use anyhow::Result;
use common::TestRepoSetup;
use git_sync_rs::{RepositorySynchronizer, SyncConfig};
use std::fs;
#[test]
fn handle_file_deleted_remotely() -> Result<()> {
let setup = TestRepoSetup::new()?;
setup.commit_file("keep.txt", "Keep this\n", "Add files")?;
setup.commit_file("delete.txt", "Delete this\n", "Add delete file")?;
setup.push()?;
let second = setup.create_second_clone("second")?;
fs::remove_file(second.join("delete.txt"))?;
run_git_command(&second, &["add", "-A"])?;
run_git_command(&second, &["commit", "-m", "Delete file"])?;
setup.push_from(&second)?;
setup.commit_file("delete.txt", "Modified locally\n", "Modify file")?;
let config = SyncConfig {
sync_new_files: true,
skip_hooks: false,
commit_message: Some("Sync deletion conflict".to_string()),
remote_name: "origin".to_string(),
branch_name: "master".to_string(),
conflict_branch: false,
target_branch: None,
};
let mut sync = RepositorySynchronizer::new_with_detected_branch(&setup.local_path, config)?;
let _result = sync.sync(false);
setup.assert_file_content("keep.txt", "Keep this\n")?;
Ok(())
}
fn run_git_command(cwd: &std::path::Path, args: &[&str]) -> Result<()> {
let output = std::process::Command::new("git")
.current_dir(cwd)
.args(args)
.output()?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!("Git command failed: git {} - {}", args.join(" "), stderr);
}
Ok(())
}