handle read-only operations #16

Merged
seb merged 2 commits from read-only-ops into main 2025-07-11 10:11:44 -06:00
Showing only changes of commit f8d35e13ff - Show all commits

View file

@ -55,6 +55,25 @@ impl Worktree {
Ok(Self { path }) Ok(Self { path })
} }
pub fn new_detached(branch: &str) -> Result<Worktree, GitError> {
let path = tempfile::tempdir()?;
let result = std::process::Command::new("git")
.args([
"worktree",
"add",
"--detach",
&path.path().to_string_lossy(),
branch,
])
.output()?;
if !result.status.success() {
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
return Err(GitError::Oops);
}
Ok(Self { path })
}
pub fn path(&self) -> &std::path::Path { pub fn path(&self) -> &std::path::Path {
self.path.as_ref() self.path.as_ref()
} }