fix git tests (#1747)

the git tests were failing on my local machine due to gpg signing config
in my ~/.gitconfig. tests should not be affected by ~/.gitconfig, so
configure them to ignore it.
This commit is contained in:
Jeremy Rose
2025-07-31 09:17:59 -07:00
committed by GitHub
parent d86270696e
commit be0cd34300
3 changed files with 29 additions and 0 deletions

View File

@@ -10,8 +10,13 @@ use tokio::process::Command;
async fn create_temp_git_repo() -> anyhow::Result<TempDir> { async fn create_temp_git_repo() -> anyhow::Result<TempDir> {
let temp_dir = TempDir::new()?; let temp_dir = TempDir::new()?;
let repo_path = temp_dir.path(); let repo_path = temp_dir.path();
let envs = vec![
("GIT_CONFIG_GLOBAL", "/dev/null"),
("GIT_CONFIG_NOSYSTEM", "1"),
];
let output = Command::new("git") let output = Command::new("git")
.envs(envs.clone())
.args(["init"]) .args(["init"])
.current_dir(repo_path) .current_dir(repo_path)
.output() .output()
@@ -25,12 +30,14 @@ async fn create_temp_git_repo() -> anyhow::Result<TempDir> {
} }
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["config", "user.email", "test@example.com"]) .args(["config", "user.email", "test@example.com"])
.current_dir(repo_path) .current_dir(repo_path)
.output() .output()
.await?; .await?;
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["config", "user.name", "Test User"]) .args(["config", "user.name", "Test User"])
.current_dir(repo_path) .current_dir(repo_path)
.output() .output()
@@ -39,12 +46,14 @@ async fn create_temp_git_repo() -> anyhow::Result<TempDir> {
std::fs::write(repo_path.join("README.md"), "# Test Repo\n")?; std::fs::write(repo_path.join("README.md"), "# Test Repo\n")?;
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["add", "README.md"]) .args(["add", "README.md"])
.current_dir(repo_path) .current_dir(repo_path)
.output() .output()
.await?; .await?;
let output = Command::new("git") let output = Command::new("git")
.envs(envs.clone())
.args(["commit", "-m", "Initial commit"]) .args(["commit", "-m", "Initial commit"])
.current_dir(repo_path) .current_dir(repo_path)
.output() .output()

View File

@@ -111,9 +111,14 @@ mod tests {
// Helper function to create a test git repository // Helper function to create a test git repository
async fn create_test_git_repo(temp_dir: &TempDir) -> PathBuf { async fn create_test_git_repo(temp_dir: &TempDir) -> PathBuf {
let repo_path = temp_dir.path().to_path_buf(); let repo_path = temp_dir.path().to_path_buf();
let envs = vec![
("GIT_CONFIG_GLOBAL", "/dev/null"),
("GIT_CONFIG_NOSYSTEM", "1"),
];
// Initialize git repo // Initialize git repo
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["init"]) .args(["init"])
.current_dir(&repo_path) .current_dir(&repo_path)
.output() .output()
@@ -122,6 +127,7 @@ mod tests {
// Configure git user (required for commits) // Configure git user (required for commits)
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["config", "user.name", "Test User"]) .args(["config", "user.name", "Test User"])
.current_dir(&repo_path) .current_dir(&repo_path)
.output() .output()
@@ -129,6 +135,7 @@ mod tests {
.expect("Failed to set git user name"); .expect("Failed to set git user name");
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["config", "user.email", "test@example.com"]) .args(["config", "user.email", "test@example.com"])
.current_dir(&repo_path) .current_dir(&repo_path)
.output() .output()
@@ -140,6 +147,7 @@ mod tests {
fs::write(&test_file, "test content").expect("Failed to write test file"); fs::write(&test_file, "test content").expect("Failed to write test file");
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["add", "."]) .args(["add", "."])
.current_dir(&repo_path) .current_dir(&repo_path)
.output() .output()
@@ -147,6 +155,7 @@ mod tests {
.expect("Failed to add files"); .expect("Failed to add files");
Command::new("git") Command::new("git")
.envs(envs.clone())
.args(["commit", "-m", "Initial commit"]) .args(["commit", "-m", "Initial commit"])
.current_dir(&repo_path) .current_dir(&repo_path)
.output() .output()

View File

@@ -460,9 +460,14 @@ async fn integration_git_info_unit_test() {
// 1. Create temp directory for git repo // 1. Create temp directory for git repo
let temp_dir = TempDir::new().unwrap(); let temp_dir = TempDir::new().unwrap();
let git_repo = temp_dir.path().to_path_buf(); let git_repo = temp_dir.path().to_path_buf();
let envs = vec![
("GIT_CONFIG_GLOBAL", "/dev/null"),
("GIT_CONFIG_NOSYSTEM", "1"),
];
// 2. Initialize a git repository with some content // 2. Initialize a git repository with some content
let init_output = std::process::Command::new("git") let init_output = std::process::Command::new("git")
.envs(envs.clone())
.args(["init"]) .args(["init"])
.current_dir(&git_repo) .current_dir(&git_repo)
.output() .output()
@@ -471,12 +476,14 @@ async fn integration_git_info_unit_test() {
// Configure git user (required for commits) // Configure git user (required for commits)
std::process::Command::new("git") std::process::Command::new("git")
.envs(envs.clone())
.args(["config", "user.name", "Integration Test"]) .args(["config", "user.name", "Integration Test"])
.current_dir(&git_repo) .current_dir(&git_repo)
.output() .output()
.unwrap(); .unwrap();
std::process::Command::new("git") std::process::Command::new("git")
.envs(envs.clone())
.args(["config", "user.email", "test@example.com"]) .args(["config", "user.email", "test@example.com"])
.current_dir(&git_repo) .current_dir(&git_repo)
.output() .output()
@@ -487,12 +494,14 @@ async fn integration_git_info_unit_test() {
std::fs::write(&test_file, "integration test content").unwrap(); std::fs::write(&test_file, "integration test content").unwrap();
std::process::Command::new("git") std::process::Command::new("git")
.envs(envs.clone())
.args(["add", "."]) .args(["add", "."])
.current_dir(&git_repo) .current_dir(&git_repo)
.output() .output()
.unwrap(); .unwrap();
let commit_output = std::process::Command::new("git") let commit_output = std::process::Command::new("git")
.envs(envs.clone())
.args(["commit", "-m", "Integration test commit"]) .args(["commit", "-m", "Integration test commit"])
.current_dir(&git_repo) .current_dir(&git_repo)
.output() .output()
@@ -501,6 +510,7 @@ async fn integration_git_info_unit_test() {
// Create a branch to test branch detection // Create a branch to test branch detection
std::process::Command::new("git") std::process::Command::new("git")
.envs(envs.clone())
.args(["checkout", "-b", "integration-test-branch"]) .args(["checkout", "-b", "integration-test-branch"])
.current_dir(&git_repo) .current_dir(&git_repo)
.output() .output()
@@ -508,6 +518,7 @@ async fn integration_git_info_unit_test() {
// Add a remote to test repository URL detection // Add a remote to test repository URL detection
std::process::Command::new("git") std::process::Command::new("git")
.envs(envs.clone())
.args([ .args([
"remote", "remote",
"add", "add",