From f8d35e13ffb15e77e83a23551a7fd1893dba592e Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Thu, 10 Jul 2025 12:39:03 -0600 Subject: [PATCH] add git::Worktree::new_detached() This makes a detached worktree, useful for read-only operations on the issues database branch. --- src/git.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/git.rs b/src/git.rs index 3374542..9765996 100644 --- a/src/git.rs +++ b/src/git.rs @@ -55,6 +55,25 @@ impl Worktree { Ok(Self { path }) } + pub fn new_detached(branch: &str) -> Result { + 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 { self.path.as_ref() }