WIP start adding git support

This commit is contained in:
Sebastian Kuzminsky 2025-07-04 13:07:10 -06:00
parent 5b73a6b34c
commit 9d9a30d90a
2 changed files with 48 additions and 0 deletions

47
src/git.rs Normal file
View file

@ -0,0 +1,47 @@
#[derive(Debug, thiserror::Error)]
pub enum GitError {
#[error(transparent)]
StdIoError(#[from] std::io::Error),
#[error("Oops, something went wrong")]
Oops,
}
pub fn checkout_branch_in_worktree(
branch: &str,
worktree_dir: &std::path::Path,
) -> Result<(), GitError> {
let result = std::process::Command::new("git")
.args(["worktree", "add", &worktree_dir.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(())
}
pub fn remove_worktree(worktree_dir: &std::path::Path) -> Result<(), GitError> {
std::fs::remove_dir_all(worktree_dir)?;
let result = std::process::Command::new("git")
.args(["worktree", "prune"])
.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(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn worktree() {
let worktree_dir = std::path::Path::new("/tmp/boo");
checkout_branch_in_worktree("main", worktree_dir).unwrap();
remove_worktree(worktree_dir).unwrap();
}
}

View file

@ -1,2 +1,3 @@
pub mod git;
pub mod issue; pub mod issue;
pub mod issues; pub mod issues;