Skip to content

Commit be0cd34

Browse files
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.
1 parent d862706 commit be0cd34

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

codex-rs/chatgpt/tests/apply_command_e2e.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ use tokio::process::Command;
1010
async fn create_temp_git_repo() -> anyhow::Result<TempDir> {
1111
let temp_dir = TempDir::new()?;
1212
let repo_path = temp_dir.path();
13+
let envs = vec![
14+
("GIT_CONFIG_GLOBAL", "/dev/null"),
15+
("GIT_CONFIG_NOSYSTEM", "1"),
16+
];
1317

1418
let output = Command::new("git")
19+
.envs(envs.clone())
1520
.args(["init"])
1621
.current_dir(repo_path)
1722
.output()
@@ -25,12 +30,14 @@ async fn create_temp_git_repo() -> anyhow::Result<TempDir> {
2530
}
2631

2732
Command::new("git")
33+
.envs(envs.clone())
2834
.args(["config", "user.email", "[email protected]"])
2935
.current_dir(repo_path)
3036
.output()
3137
.await?;
3238

3339
Command::new("git")
40+
.envs(envs.clone())
3441
.args(["config", "user.name", "Test User"])
3542
.current_dir(repo_path)
3643
.output()
@@ -39,12 +46,14 @@ async fn create_temp_git_repo() -> anyhow::Result<TempDir> {
3946
std::fs::write(repo_path.join("README.md"), "# Test Repo\n")?;
4047

4148
Command::new("git")
49+
.envs(envs.clone())
4250
.args(["add", "README.md"])
4351
.current_dir(repo_path)
4452
.output()
4553
.await?;
4654

4755
let output = Command::new("git")
56+
.envs(envs.clone())
4857
.args(["commit", "-m", "Initial commit"])
4958
.current_dir(repo_path)
5059
.output()

codex-rs/core/src/git_info.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ mod tests {
111111
// Helper function to create a test git repository
112112
async fn create_test_git_repo(temp_dir: &TempDir) -> PathBuf {
113113
let repo_path = temp_dir.path().to_path_buf();
114+
let envs = vec![
115+
("GIT_CONFIG_GLOBAL", "/dev/null"),
116+
("GIT_CONFIG_NOSYSTEM", "1"),
117+
];
114118

115119
// Initialize git repo
116120
Command::new("git")
121+
.envs(envs.clone())
117122
.args(["init"])
118123
.current_dir(&repo_path)
119124
.output()
@@ -122,13 +127,15 @@ mod tests {
122127

123128
// Configure git user (required for commits)
124129
Command::new("git")
130+
.envs(envs.clone())
125131
.args(["config", "user.name", "Test User"])
126132
.current_dir(&repo_path)
127133
.output()
128134
.await
129135
.expect("Failed to set git user name");
130136

131137
Command::new("git")
138+
.envs(envs.clone())
132139
.args(["config", "user.email", "[email protected]"])
133140
.current_dir(&repo_path)
134141
.output()
@@ -140,13 +147,15 @@ mod tests {
140147
fs::write(&test_file, "test content").expect("Failed to write test file");
141148

142149
Command::new("git")
150+
.envs(envs.clone())
143151
.args(["add", "."])
144152
.current_dir(&repo_path)
145153
.output()
146154
.await
147155
.expect("Failed to add files");
148156

149157
Command::new("git")
158+
.envs(envs.clone())
150159
.args(["commit", "-m", "Initial commit"])
151160
.current_dir(&repo_path)
152161
.output()

codex-rs/core/tests/cli_stream.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,14 @@ async fn integration_git_info_unit_test() {
460460
// 1. Create temp directory for git repo
461461
let temp_dir = TempDir::new().unwrap();
462462
let git_repo = temp_dir.path().to_path_buf();
463+
let envs = vec![
464+
("GIT_CONFIG_GLOBAL", "/dev/null"),
465+
("GIT_CONFIG_NOSYSTEM", "1"),
466+
];
463467

464468
// 2. Initialize a git repository with some content
465469
let init_output = std::process::Command::new("git")
470+
.envs(envs.clone())
466471
.args(["init"])
467472
.current_dir(&git_repo)
468473
.output()
@@ -471,12 +476,14 @@ async fn integration_git_info_unit_test() {
471476

472477
// Configure git user (required for commits)
473478
std::process::Command::new("git")
479+
.envs(envs.clone())
474480
.args(["config", "user.name", "Integration Test"])
475481
.current_dir(&git_repo)
476482
.output()
477483
.unwrap();
478484

479485
std::process::Command::new("git")
486+
.envs(envs.clone())
480487
.args(["config", "user.email", "[email protected]"])
481488
.current_dir(&git_repo)
482489
.output()
@@ -487,12 +494,14 @@ async fn integration_git_info_unit_test() {
487494
std::fs::write(&test_file, "integration test content").unwrap();
488495

489496
std::process::Command::new("git")
497+
.envs(envs.clone())
490498
.args(["add", "."])
491499
.current_dir(&git_repo)
492500
.output()
493501
.unwrap();
494502

495503
let commit_output = std::process::Command::new("git")
504+
.envs(envs.clone())
496505
.args(["commit", "-m", "Integration test commit"])
497506
.current_dir(&git_repo)
498507
.output()
@@ -501,13 +510,15 @@ async fn integration_git_info_unit_test() {
501510

502511
// Create a branch to test branch detection
503512
std::process::Command::new("git")
513+
.envs(envs.clone())
504514
.args(["checkout", "-b", "integration-test-branch"])
505515
.current_dir(&git_repo)
506516
.output()
507517
.unwrap();
508518

509519
// Add a remote to test repository URL detection
510520
std::process::Command::new("git")
521+
.envs(envs.clone())
511522
.args([
512523
"remote",
513524
"add",

0 commit comments

Comments
 (0)