From 06c31461d74b10ed6fa01498fd9e2e390ad5395c Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Fri, 14 Jul 2023 13:32:20 +0200 Subject: Add cleaning up stale objects to the housekeeping task --- tests/cli_test_utils/git.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'tests/cli_test_utils/git.rs') 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 { .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()); } -- cgit v1.2.3