summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-07-14 13:32:20 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-07-14 13:32:20 +0200
commit06c31461d74b10ed6fa01498fd9e2e390ad5395c (patch)
treee89ad9f485f9e58f7c47ba01b53adee81d88a3ca
parent755e28d044aaff9a8aa0fa4700105564726ec33d (diff)
Add cleaning up stale objects to the housekeeping task
-rw-r--r--src/git.rs1
-rw-r--r--tests/cli.rs25
-rw-r--r--tests/cli_test_utils/git.rs24
3 files changed, 37 insertions, 13 deletions
diff --git a/src/git.rs b/src/git.rs
index 76ff326..9fa3e78 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -241,6 +241,7 @@ pub fn housekeeping(directory: &Path) -> Result<(), ShackleError> {
Command::new("git")
.arg("gc")
+ .arg("--prune=now")
.current_dir(directory)
.spawn()?
.wait()?;
diff --git a/tests/cli.rs b/tests/cli.rs
index 598152b..01c3347 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -296,15 +296,22 @@ fn git_housekeeping_repacks_objects() -> Result<()> {
}
#[test]
-#[ignore]
fn git_housekeeping_cleans_out_stale_refs() -> Result<()> {
- // create a repo
- // create a local clone
- // make branch b, with commit b
- // push it to the repo
- // delete branch b on the remote
- // check that commit b is still accessible by hash on the remote
- // run housekeeping
- // check that commit b isn't in the repo anymore
+ let mut c = TestContext::new_interactive()?;
+ let repo_path = personal_repo_path(REPO_NAME);
+ let repo_dir = c.personal_repo_dir(REPO_NAME);
+
+ c.p.send_line(&format!("init {}", REPO_NAME))?;
+ c.expect_successful_init_message(&repo_path)?;
+
+ let checkout_dir = create_clone(&c, &repo_dir, REPO_NAME);
+ let commit_hash = create_commit(&checkout_dir)?;
+ push(&checkout_dir, "main:temporary-branch");
+ push(&checkout_dir, ":temporary-branch");
+
+ verify_commit_exists(&repo_dir, &commit_hash);
+ c.p.send_line(&format!("housekeeping"))?;
+ c.p.exp_string(&format!("Successfully did housekeeping on \"{repo_path}\""))?;
+ verify_commit_does_not_exist(&repo_dir, &commit_hash);
Ok(())
}
diff --git a/tests/cli_test_utils/git.rs b/tests/cli_test_utils/git.rs
index fe6e1bd..a2acd59 100644
--- a/tests/cli_test_utils/git.rs
+++ b/tests/cli_test_utils/git.rs
@@ -1,6 +1,6 @@
use crate::context::TestContext;
use anyhow::Result;
-use assert_cmd::Command;
+use assert_cmd::{assert::Assert, Command};
use std::{
fs,
path::{Path, PathBuf},
@@ -43,12 +43,12 @@ pub fn create_commit(repo_dir: &Path) -> Result<String> {
.stdout,
)?;
- Ok(commit_hash)
+ Ok(commit_hash.trim().to_owned())
}
-pub fn push(local_repo_dir: &Path, branch: &str) {
+pub fn push(local_repo_dir: &Path, refspec: &str) {
Command::new("git")
- .args(["push", "origin", branch])
+ .args(["push", "origin", refspec])
.current_dir(&local_repo_dir)
.timeout(std::time::Duration::from_secs(3))
.assert()
@@ -65,6 +65,22 @@ pub fn verify_repo_exists(repo_dir: &Path) {
.stdout("");
}
+fn check_commit_exists(repo_dir: &Path, commit_hash: &str) -> Assert {
+ Command::new("git")
+ .arg("rev-list")
+ .arg(commit_hash)
+ .current_dir(repo_dir)
+ .assert()
+}
+
+pub fn verify_commit_exists(repo_dir: &Path, commit_hash: &str) {
+ check_commit_exists(repo_dir, commit_hash).success();
+}
+
+pub fn verify_commit_does_not_exist(repo_dir: &Path, commit_hash: &str) {
+ check_commit_exists(repo_dir, commit_hash).failure();
+}
+
pub fn verify_repo_does_not_exist(repo_dir: &Path) {
assert!(!repo_dir.exists());
}