Skip to main content

vex_git/
lib.rs

1use std::path::Path;
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum GitError {
7    #[error("not a git repository: {0}")]
8    NotARepo(String),
9    #[error("git command failed: {0}")]
10    CommandFailed(String),
11    #[error("worktree error: {0}")]
12    WorktreeError(String),
13    #[error("IO error: {0}")]
14    Io(#[from] std::io::Error),
15}
16
17#[derive(Debug, Clone)]
18pub struct CommitInfo {
19    pub hash: String,
20    pub short_hash: String,
21    pub subject: String,
22    pub author: String,
23    pub date: String,
24}
25
26pub trait GitPort {
27    fn is_git_repo(&self, path: &Path) -> Result<bool, GitError>;
28    fn get_github_remote(&self, path: &Path) -> Result<Option<String>, GitError>;
29    fn create_worktree(
30        &self,
31        repo_path: &Path,
32        worktree_path: &Path,
33        branch: &str,
34        create_branch: bool,
35    ) -> Result<(), GitError>;
36    fn remove_worktree(&self, repo_path: &Path, worktree_path: &Path) -> Result<(), GitError>;
37    fn current_branch(&self, path: &Path) -> Result<String, GitError>;
38    fn get_pr_branch(&self, pr_url: &str) -> Result<String, GitError>;
39    fn staged_diff(&self, path: &Path) -> Result<String, GitError>;
40    fn unstaged_diff(&self, path: &Path) -> Result<String, GitError>;
41    fn log_commits(&self, path: &Path, base: &str) -> Result<Vec<CommitInfo>, GitError>;
42}