forge
Explore
Log in

Don't you dare go Hollow

Give spawned git a fixed identity so tests pass on clean machines

Browse files at this commit

8758f0cd0704ae8294854723048c3a7eb27227b6Ahmet Kaan GümüşParent: 670a51d
  • test
    • give spawned git a fixed identity so tests pass on clean machines
Show full message
✅ test: give spawned git a fixed identity so tests pass on clean machines
crates/forge-web/tests/mirrors_e2e.rsmodified+12 -1
@@ -138,6 +138,17 @@ fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
138 );138 );
139 }139 }
140 140
141+/// Fixed identity and config isolation for every git this file spawns, so the result does not
142+/// depend on the machine's global git config (a clean CI container has none).
143+const GIT_HERMETIC_ENV: &[(&str, &str)] = &[
144+ ("GIT_AUTHOR_NAME", "tahinli"),
145+ ("GIT_AUTHOR_EMAIL", "tahinli@example.com"),
146+ ("GIT_COMMITTER_NAME", "tahinli"),
147+ ("GIT_COMMITTER_EMAIL", "tahinli@example.com"),
148+ ("GIT_CONFIG_GLOBAL", "/dev/null"),
149+ ("GIT_CONFIG_NOSYSTEM", "1"),
150+];
151+
141 /// Runs git with credential helpers disabled and extra env. Returns the raw output.152 /// Runs git with credential helpers disabled and extra env. Returns the raw output.
142 fn git_output(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output {153 fn git_output(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output {
143 let mut cmd = Command::new("git");154 let mut cmd = Command::new("git");
@@ -145,7 +156,7 @@ fn git_output(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output {
145 .args(["-c", "credential.helper="])156 .args(["-c", "credential.helper="])
146 .args(args)157 .args(args)
147 .env("GIT_TERMINAL_PROMPT", "0");158 .env("GIT_TERMINAL_PROMPT", "0");
148- for (key, value) in env {159+ for (key, value) in GIT_HERMETIC_ENV.iter().chain(env) {
149 cmd.env(key, value);160 cmd.env(key, value);
150 }161 }
151 cmd.output().expect("run git")162 cmd.output().expect("run git")