From 58664db6007920939d94977cc7382a5709b16558 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Wed, 12 Jul 2023 17:13:52 +0200 Subject: Starting with tests for the planned git housekeeping tasks --- tests/cli.rs | 34 ++++++++++++++++++++++++++++++++ tests/cli_test_utils/git.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/tests/cli.rs b/tests/cli.rs index b8ada66..0520e89 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -271,3 +271,37 @@ fn can_delete_a_repo() -> Result<()> { Ok(()) } + +#[test] +#[ignore] +fn git_housekeeping_repacks_objects() -> Result<()> { + 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); + create_commit(&checkout_dir)?; + + // push to the repo + // check that objects exist, not packs + // run housekeeping + // check that only packs exist + Ok(()) +} + +#[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 + Ok(()) +} diff --git a/tests/cli_test_utils/git.rs b/tests/cli_test_utils/git.rs index d3f35c4..150af45 100644 --- a/tests/cli_test_utils/git.rs +++ b/tests/cli_test_utils/git.rs @@ -1,5 +1,50 @@ +use crate::context::TestContext; +use anyhow::Result; use assert_cmd::Command; -use std::path::Path; +use std::{ + fs, + path::{Path, PathBuf}, +}; + +pub fn create_clone(c: &TestContext, repo_dir: &Path, relative_name: &str) -> PathBuf { + Command::new("git") + .arg("clone") + .arg(repo_dir) + .arg(relative_name) + .current_dir(&c.workdir) + .timeout(std::time::Duration::from_secs(3)) + .assert() + .success(); + c.workdir.as_ref().join(relative_name) +} + +pub fn create_commit(repo_dir: &Path) -> Result { + let test_file_name = repo_dir.join("some_file"); + fs::write(test_file_name, "Some content or something")?; + Command::new("git") + .args(["add", "--all"]) + .current_dir(&repo_dir) + .timeout(std::time::Duration::from_secs(3)) + .assert() + .success(); + Command::new("git") + .args(["commit", "-m", "A commit message"]) + .current_dir(&repo_dir) + .timeout(std::time::Duration::from_secs(3)) + .assert() + .success(); + + let commit_hash = String::from_utf8( + Command::new("git") + .args(["rev-parse", "HEAD"]) + .current_dir(&repo_dir) + .timeout(std::time::Duration::from_secs(3)) + .output()? + .stdout, + )?; + + Ok(commit_hash) +} pub fn verify_repo_exists(repo_dir: &Path) { Command::new("git") -- cgit v1.2.3