add git::Worktree::new_detached()
This makes a detached worktree, useful for read-only operations on the issues database branch.
This commit is contained in:
parent
6ea0b98963
commit
f8d35e13ff
1 changed files with 19 additions and 0 deletions
19
src/git.rs
19
src/git.rs
|
|
@ -55,6 +55,25 @@ impl Worktree {
|
|||
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 {
|
||||
self.path.as_ref()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue