diff --git a/test-support/src/lib.rs b/test-support/src/lib.rs index ed2f7dc0..632e61ea 100644 --- a/test-support/src/lib.rs +++ b/test-support/src/lib.rs @@ -14,7 +14,8 @@ use std::{ }; /// Runs `git` in `dir` as the studio's own identity, away from the developer's git config, and -/// returns its output without the trailing newline. +/// returns its output without the trailing newline. It never starts auto maintenance, which every +/// commit would otherwise start in the background (#823); the hook's `git` turns it off too (#141). pub fn git(dir: &Path, args: &[&str]) -> String { let output = Command::new("git") .args([ @@ -22,6 +23,10 @@ pub fn git(dir: &Path, args: &[&str]) -> String { "user.name=Studio", "-c", "user.email=studio@example.com", + "-c", + "maintenance.auto=false", + "-c", + "gc.auto=0", ]) .args(args) .current_dir(dir) diff --git a/test-support/tests/git.rs b/test-support/tests/git.rs new file mode 100644 index 00000000..edb90158 --- /dev/null +++ b/test-support/tests/git.rs @@ -0,0 +1,28 @@ +//! The tests' `git`: what it starts besides the command it was given. + +use std::fs; +use studio_test_support::{git, repo}; + +#[test] +fn a_commit_through_the_tests_git_starts_no_auto_maintenance() { + let (dir, _) = repo(); + let trace = dir.path().join("trace"); + // SAFETY: nextest runs each test in a process of its own, and no thread has started yet; this file's binary + // holds this one test, so under `cargo test` no other test thread reads the environment either. + unsafe { std::env::set_var("GIT_TRACE", &trace) }; + + git( + dir.path(), + &["commit", "-q", "--allow-empty", "-m", "Second"], + ); + + let trace = fs::read_to_string(&trace).unwrap(); + assert!( + trace.contains("commit"), + "the trace caught the commit:\n{trace}" + ); + assert!( + !trace.contains("maintenance"), + "the commit started auto maintenance:\n{trace}" + ); +}