mod clean;
mod done;
mod exec;
mod go;
mod pull;
mod rebase;
pub use clean::{clean, CleanResult};
pub use done::{done, DoneOpts, DoneResult};
pub use exec::{exec, ExecResult};
pub use go::{go, save_last_worktree, GoQuery, GoResult};
pub use pull::{pull, PullResult, PullStatus};
pub use rebase::{rebase, RebaseResult};
use thor_core::{find_repo, list_worktrees, Worktree};
use std::path::PathBuf;
pub async fn list() -> anyhow::Result<Vec<Worktree>> {
let repo = find_repo()?;
Ok(list_worktrees(&repo).await?)
}
pub async fn remove(branch: &str, force: bool) -> anyhow::Result<()> {
let repo = find_repo()?;
Ok(thor_core::remove_worktree(&repo, branch, force).await?)
}
pub struct NewResult {
pub path: PathBuf,
pub branch: String,
}
pub async fn new(branch: &str, base: Option<&str>, track: bool) -> anyhow::Result<NewResult> {
let repo = find_repo()?;
if track {
let fetch_ref = base.unwrap_or("main");
let repo_root = thor_core::repo_root(&repo)?;
let status = std::process::Command::new("git")
.args(["fetch", "origin", fetch_ref])
.current_dir(&repo_root)
.status()?;
if !status.success() {
anyhow::bail!("Failed to fetch origin/{}", fetch_ref);
}
}
let wt = thor_core::create_worktree(&repo, branch, base, ".worktrees").await?;
Ok(NewResult {
path: wt.path,
branch: branch.to_string(),
})
}