use std::path::Path;
use thiserror::Error;
#[derive(Error, Debug)]
#[allow(dead_code)] pub enum VcsError {
#[error("invalid reference: {0}")]
InvalidRef(String),
#[error("file not found: {0}")]
FileNotFound(String),
#[error("not a repository")]
NotARepository,
#[error("command failed: {0}")]
CommandFailed(String),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Other(String),
}
#[derive(Clone, Debug)]
pub struct StackedCommitInfo {
pub commit_id: String,
pub short_id: String,
pub change_id: Option<String>,
pub summary: String,
}
#[derive(Debug, Clone)]
#[allow(dead_code)] pub struct CommitInfo {
pub commit_id: String,
pub change_id: Option<String>,
pub message: String,
pub diff: String,
pub author: String,
pub date: String,
}
#[allow(dead_code)] pub trait VcsBackend {
fn get_commit(&self, reference: &str) -> Result<CommitInfo, VcsError>;
fn get_working_tree_diff(&self, staged: bool) -> Result<String, VcsError>;
fn get_range_diff(&self, from: &str, to: &str, three_dot: bool) -> Result<String, VcsError>;
fn get_changed_files(&self, reference: &str) -> Result<Vec<String>, VcsError>;
fn get_file_content_at_ref(&self, reference: &str, path: &Path) -> Result<String, VcsError>;
fn get_current_branch(&self) -> Result<Option<String>, VcsError>;
fn get_commit_log_for_fzf(&self) -> Result<String, VcsError>;
fn resolve_ref(&self, reference: &str) -> Result<String, VcsError>;
fn get_working_tree_changed_files(&self) -> Result<Vec<String>, VcsError>;
fn get_merge_base(&self, ref1: &str, ref2: &str) -> Result<String, VcsError>;
fn working_copy_parent_ref(&self) -> &'static str;
fn get_range_changed_files(&self, from: &str, to: &str) -> Result<Vec<String>, VcsError>;
fn get_parent_ref_or_empty(&self, reference: &str) -> Result<String, VcsError>;
fn get_commits_in_range(
&self,
from: &str,
to: &str,
) -> Result<Vec<StackedCommitInfo>, VcsError>;
fn name(&self) -> &'static str;
}