Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ 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([
"-c",
"user.name=Studio",
"-c",
"user.email=studio@example.com",
"-c",
"maintenance.auto=false",
"-c",
"gc.auto=0",
])
.args(args)
.current_dir(dir)
Expand Down
28 changes: 28 additions & 0 deletions test-support/tests/git.rs
Original file line number Diff line number Diff line change
@@ -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}"
);
}
Loading