diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-18 17:57:10 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-18 17:57:10 +0200 |
| commit | c10134b402544085aba900eaaa2aa485be2cd390 (patch) | |
| tree | 8a23d571c6a94f1acb171ec7964d0ef6684a2454 /src/remote/git.rs | |
| parent | 7edb7f578d5e87a4d9e28586c2e066269041cc1d (diff) | |
Test for publish, imrpove git test
Diffstat (limited to 'src/remote/git.rs')
| -rw-r--r-- | src/remote/git.rs | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/remote/git.rs b/src/remote/git.rs index c8aaf46..2960448 100644 --- a/src/remote/git.rs +++ b/src/remote/git.rs @@ -39,13 +39,17 @@ impl super::Remote for Git { ]; for arguments in command_arguments { - Command::new("git") + let status = Command::new("git") .current_dir(directory) .args(&arguments) .stdout(Stdio::null()) .stderr(Stdio::null()) .status() .map_err(|_| Error::other("Failed while performing sync up with git"))?; + + if !status.success() { + return Err(Error::other("Failed while performing sync up with git")); + } } Ok(()) @@ -54,19 +58,23 @@ impl super::Remote for Git { fn sync_down(&self, remote: &str, directory: &Path) -> Result<()> { let command_arguments = vec![ vec!["init", "-b", "main"], - vec!["checkout", "."], + vec!["reset", "--hard"], vec!["clean", ".", "-f"], vec!["pull", &remote, "main"], ]; for arguments in command_arguments { - Command::new("git") + let status = Command::new("git") .current_dir(directory) .args(&arguments) .stdout(Stdio::null()) .stderr(Stdio::null()) .status() .map_err(|_| Error::other("Failed while performing sync down with git"))?; + + if !status.success() { + return Err(Error::other("Failed while performing sync down with git")); + } } Ok(()) } @@ -174,7 +182,7 @@ mod tests { } #[test] - fn test_sync_up_fails_with_an_invalid_remote() { + fn test_sync_up_fails_with_an_invalid_string() { let git = Git::new(); let test_dir = setup_test_dir(); let local_dir = test_dir.join("local"); @@ -189,6 +197,21 @@ mod tests { } #[test] + fn test_sync_up_fails_with_an_invalid_remote() { + let git = Git::new(); + let test_dir = setup_test_dir(); + let local_dir = test_dir.join("local"); + create_dir_all(&local_dir).expect("Could not create local test directory"); + + let invalid_remote = String::from("my guy does not exist"); + + let result = git.sync_up(&invalid_remote, &local_dir); + + assert!(result.is_err()); + cleanup_test_dir(&test_dir); + } + + #[test] fn test_syncs_remote_down() { let git = Git::new(); let test_dir = setup_test_dir(); @@ -247,7 +270,7 @@ mod tests { } #[test] - fn test_sync_down_fails_with_an_invalid_remote() { + fn test_sync_down_fails_with_an_invalid_string() { let git = Git::new(); let test_dir = setup_test_dir(); let local_dir = test_dir.join("local"); @@ -260,4 +283,19 @@ mod tests { assert!(result.is_err()); cleanup_test_dir(&test_dir); } + + #[test] + fn test_sync_down_fails_with_an_invalid_remote() { + let git = Git::new(); + let test_dir = setup_test_dir(); + let local_dir = test_dir.join("local"); + create_dir_all(&local_dir).expect("Could not create local test directory"); + + let invalid_remote = String::from("thisremotedoesnotexist"); + + let result = git.sync_down(&invalid_remote, &local_dir); + + assert!(result.is_err()); + cleanup_test_dir(&test_dir); + } } |