MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / ensure_snapshot_repo

Function ensure_snapshot_repo

crates/opencode-session/src/snapshot.rs:199–227  ·  view source on GitHub ↗
(directory: &Path)

Source from the content-addressed store, hash-verified

197}
198
199fn 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
229fn git_output(directory: &Path, git_dir: &Path, args: &[&str]) -> Result<Output> {
230 let output = Command::new("git")

Callers 5

trackMethod · 0.85
revertMethod · 0.85
restoreMethod · 0.85
diffMethod · 0.85
diff_fullMethod · 0.85

Calls 6

snapshot_git_dirFunction · 0.85
newFunction · 0.85
existsMethod · 0.80
outputMethod · 0.80
git_outputFunction · 0.70
successMethod · 0.45

Tested by

no test coverage detected