#![allow(dead_code)]
#![allow(unused_imports)]
pub use codetree::config::Config;
pub use codetree::error::{Context, Result};
pub use codetree::branch::{BranchManager, BranchStatus};
pub use codetree::vcs::VcsManager;
pub use codetree::resolution::{PendingResolution, ResolutionCache};
pub use codetree::snapshot::SnapshotManager;
pub use codetree::commands;
pub use codetree::commands::BisectAction;
pub use codetree::commands::ConfigAction;
pub use codetree::commands::TagAction;
pub use std::path::PathBuf;
pub use tempfile::TempDir;
pub use std::env;
pub use tokio::sync::Mutex;
pub async fn create_test_repo() -> Result<(TempDir, PathBuf)> {
let temp_dir = TempDir::new()?;
let repo_path = temp_dir.path().to_path_buf();
let mgr = VcsManager::init_at(&repo_path)?;
mgr.commit("Initial commit").await?;
Ok((temp_dir, repo_path))
}
pub static WORKDIR_LOCK: Mutex<()> = Mutex::const_new(());
pub struct DirGuard {
original: PathBuf,
}
impl DirGuard {
pub fn new(path: &PathBuf) -> Self {
let original = env::current_dir().unwrap();
env::set_current_dir(path).unwrap();
Self { original }
}
}
impl Drop for DirGuard {
fn drop(&mut self) {
let _ = env::set_current_dir(&self.original);
}
}
pub fn count_commits_from(repo: &codetree::vcs::Repository, start: &str) -> usize {
let mut count = 0;
let mut current = Some(start.to_string());
while let Some(id) = current {
count += 1;
match repo.read_commit(&id) {
Ok(c) => {
current = c.parents.first().cloned();
}
Err(_) => break,
}
}
count
}