| 197 | } |
| 198 | |
| 199 | fn ensure_snapshot_repo(directory: &Path) -> Result<PathBuf> { |
| 200 | let git_dir = snapshot_git_dir(directory); |
| 201 | let parent = git_dir |
| 202 | .parent() |
| 203 | .context("snapshot git directory has no parent")?; |
| 204 | fs::create_dir_all(parent)?; |
| 205 | |
| 206 | if !git_dir.join("HEAD").exists() { |
| 207 | let init_output = Command::new("git") |
| 208 | .arg("init") |
| 209 | .arg("--quiet") |
| 210 | .current_dir(directory) |
| 211 | .env("GIT_DIR", &git_dir) |
| 212 | .env("GIT_WORK_TREE", directory) |
| 213 | .output() |
| 214 | .context("failed to run git init for snapshot repo")?; |
| 215 | if !init_output.status.success() { |
| 216 | anyhow::bail!( |
| 217 | "failed to initialize snapshot repo: {}", |
| 218 | String::from_utf8_lossy(&init_output.stderr).trim() |
| 219 | ); |
| 220 | } |
| 221 | |
| 222 | // Keep line endings stable across platforms. |
| 223 | let _ = git_output(directory, &git_dir, &["config", "core.autocrlf", "false"]); |
| 224 | } |
| 225 | |
| 226 | Ok(git_dir) |
| 227 | } |
| 228 | |
| 229 | fn git_output(directory: &Path, git_dir: &Path, args: &[&str]) -> Result<Output> { |
| 230 | let output = Command::new("git") |