use crate::error::GitError;
use crate::types::{
CherryPickOptions, CommitOptions, FetchOptions, GitMergeResult, GitStatus, GitWorktree,
MergeOptions, Oid, PushOptions, RebaseOptions,
};
use async_trait::async_trait;
use std::path::Path;
#[async_trait]
pub trait GitApi {
async fn ensure_clean(&self) -> Result<(), GitError>;
async fn status(&self) -> Result<GitStatus, GitError>;
async fn current_branch(&self) -> Result<String, GitError>;
async fn head_commit(&self) -> Result<Oid, GitError>;
async fn changed_files(&self) -> Result<Vec<String>, GitError>;
async fn worktree_add(&self, path: &Path, branch: &str) -> Result<GitWorktree, GitError>;
async fn worktree_remove(&self, path: &Path, force: bool) -> Result<(), GitError>;
async fn worktree_list(&self) -> Result<Vec<GitWorktree>, GitError>;
async fn branch_create(&self, name: &str, start_point: Option<&str>) -> Result<(), GitError>;
async fn branch_delete(&self, name: &str, force: bool) -> Result<(), GitError>;
async fn branch_exists(&self, name: &str) -> Result<bool, GitError>;
async fn checkout(&self, branch: &str) -> Result<(), GitError>;
async fn commit_opts(&self, opts: &CommitOptions<'_>) -> Result<String, GitError>;
async fn commit(
&self,
message: &str,
paths: &[&std::path::Path],
no_verify: bool,
) -> Result<String, GitError> {
self.commit_opts(&CommitOptions {
message,
paths,
no_verify,
amend: false,
signoff: false,
})
.await
}
async fn push_opts(&self, opts: &PushOptions<'_>) -> Result<(), GitError>;
async fn push(&self, remote: &str, branch: &str, force: bool) -> Result<(), GitError> {
self.push_opts(&PushOptions {
remote,
branch,
force_with_lease: force,
..Default::default()
})
.await
}
async fn fetch_opts(&self, opts: &FetchOptions<'_>) -> Result<(), GitError>;
async fn fetch(&self, remote: &str) -> Result<(), GitError> {
self.fetch_opts(&FetchOptions {
remote,
..Default::default()
})
.await
}
async fn merge_tree(&self, base: &str, branch: &str) -> Result<GitMergeResult, GitError>;
async fn merge_opts(&self, opts: &MergeOptions<'_>) -> Result<(), GitError>;
async fn merge(&self, branch: &str, no_edit: bool) -> Result<(), GitError> {
self.merge_opts(&MergeOptions {
branch,
no_edit,
..Default::default()
})
.await
}
async fn rebase_opts(&self, opts: &RebaseOptions<'_>) -> Result<(), GitError>;
async fn rebase(&self, branch: &str) -> Result<(), GitError> {
self.rebase_opts(&RebaseOptions {
branch,
..Default::default()
})
.await
}
async fn stash(&self, message: Option<&str>) -> Result<(), GitError>;
async fn diff(&self) -> Result<String, GitError>;
async fn diff_structured(&self) -> Result<Vec<crate::types::FileDiff>, GitError>;
async fn diff_cached_structured(&self) -> Result<Vec<crate::types::FileDiff>, GitError>;
async fn log(
&self,
max_count: Option<usize>,
) -> Result<Vec<crate::types::GitLogEntry>, GitError>;
async fn log_paginated(
&self,
skip: usize,
max_count: usize,
) -> Result<Vec<crate::types::GitLogEntry>, GitError>;
async fn remotes(&self) -> Result<Vec<crate::types::GitRemote>, GitError>;
async fn config_get(&self, key: &str) -> Result<Option<String>, GitError>;
async fn config_set(&self, key: &str, value: &str) -> Result<(), GitError>;
async fn config_unset(&self, key: &str) -> Result<(), GitError>;
async fn tag_list(&self) -> Result<Vec<crate::types::GitTag>, GitError>;
async fn tag_create(
&self,
name: &str,
message: Option<&str>,
force: bool,
) -> Result<(), GitError>;
async fn tag_create_signed(
&self,
name: &str,
message: &str,
gpg_key: Option<&str>,
) -> Result<(), GitError>;
async fn verify_tag(&self, name: &str) -> Result<crate::types::GitVerification, GitError>;
async fn show(&self, path: &str, rev: Option<&str>) -> Result<String, GitError>;
async fn blame(&self, path: &str) -> Result<String, GitError>;
async fn blame_structured(&self, path: &str) -> Result<Vec<crate::types::BlameLine>, GitError>;
async fn format_patch(&self, range: &str) -> Result<Vec<crate::types::Patch>, GitError>;
async fn apply_patch(&self, patch: &str, dry_run: bool) -> Result<(), GitError>;
async fn apply_patch_file(&self, path: &Path, dry_run: bool) -> Result<(), GitError>;
async fn bundle_create(&self, output: &Path, refs: Option<&[&str]>) -> Result<(), GitError>;
async fn bundle_list_heads(&self, path: &Path) -> Result<Vec<String>, GitError>;
async fn bundle_verify(&self, path: &Path) -> Result<(), GitError>;
async fn bundle_unbundle(&self, path: &Path) -> Result<Vec<String>, GitError>;
async fn reflog_list(
&self,
ref_name: Option<&str>,
) -> Result<Vec<crate::types::ReflogEntry>, GitError>;
async fn reflog_expire(
&self,
ref_name: &str,
expire_time: Option<&str>,
) -> Result<(), GitError>;
async fn hooks_list(&self) -> Result<Vec<crate::types::Hook>, GitError>;
async fn hook_install(&self, name: &str, script: &str) -> Result<(), GitError>;
async fn hook_remove(&self, name: &str) -> Result<(), GitError>;
async fn run_hook(&self, name: &str) -> Result<crate::types::HookOutput, GitError>;
async fn check_ignore(&self, paths: &[&std::path::Path]) -> Result<Vec<String>, GitError>;
async fn check_attr(
&self,
paths: &[&std::path::Path],
attrs: &[&str],
) -> Result<Vec<crate::types::GitAttr>, GitError>;
async fn bisect_start(
&self,
bad: Option<&str>,
good: &[&str],
) -> Result<crate::types::BisectState, GitError>;
async fn bisect_bad(&self, commit: Option<&str>)
-> Result<crate::types::BisectState, GitError>;
async fn bisect_good(
&self,
commit: Option<&str>,
) -> Result<crate::types::BisectState, GitError>;
async fn bisect_reset(&self) -> Result<(), GitError>;
async fn bisect_run(&self, command: &str) -> Result<String, GitError>;
async fn notes_list(
&self,
namespace: Option<&str>,
) -> Result<Vec<crate::types::GitNote>, GitError>;
async fn notes_show(&self, object: &str, namespace: Option<&str>) -> Result<String, GitError>;
async fn notes_add(
&self,
message: &str,
object: &str,
namespace: Option<&str>,
force: bool,
) -> Result<(), GitError>;
async fn notes_remove(&self, object: &str, namespace: Option<&str>) -> Result<(), GitError>;
async fn reset(
&self,
mode: crate::types::ResetMode,
target: Option<&str>,
) -> Result<(), GitError>;
async fn stash_list(&self) -> Result<Vec<crate::types::GitStash>, GitError>;
async fn cherry_pick_opts(&self, opts: &CherryPickOptions<'_>) -> Result<(), GitError>;
async fn cherry_pick(&self, commits: &[&str]) -> Result<(), GitError> {
self.cherry_pick_opts(&CherryPickOptions {
commits,
..Default::default()
})
.await
}
async fn commit_signed(
&self,
paths: &[&Path],
message: &str,
gpg_key: Option<&str>,
no_verify: bool,
) -> Result<(), GitError>;
async fn verify_commit(&self, sha: &str) -> Result<crate::types::GitVerification, GitError>;
async fn submodule_list(&self) -> Result<Vec<crate::types::GitSubmodule>, GitError>;
async fn submodule_add(&self, url: &str, path: &Path) -> Result<(), GitError>;
async fn submodule_update(&self, init: bool, recursive: bool) -> Result<(), GitError>;
async fn submodule_deinit(&self, path: &Path, force: bool) -> Result<(), GitError>;
async fn submodule_sync(&self) -> Result<(), GitError>;
async fn ls_files(
&self,
deleted: bool,
others: bool,
exclude_standard: bool,
) -> Result<Vec<String>, GitError>;
async fn diff_cached(&self) -> Result<String, GitError>;
async fn archive(&self, ref_name: &str, output: &Path) -> Result<(), GitError>;
async fn grep(&self, pattern: &str) -> Result<Vec<crate::types::GitGrepResult>, GitError>;
async fn describe(&self, tags: bool, long: bool) -> Result<String, GitError>;
async fn clean(
&self,
force: bool,
directories: bool,
dry_run: bool,
) -> Result<Vec<String>, GitError>;
async fn lfs_track(&self, patterns: &[&str]) -> Result<(), GitError>;
async fn lfs_untrack(&self, patterns: &[&str]) -> Result<(), GitError>;
async fn lfs_ls_files(&self) -> Result<Vec<crate::types::GitLfsFile>, GitError>;
async fn lfs_lock(&self, path: &str) -> Result<(), GitError>;
async fn lfs_unlock(&self, path: &str, force: bool) -> Result<(), GitError>;
async fn sparse_checkout_init(&self, cone: bool) -> Result<(), GitError>;
async fn sparse_checkout_set(&self, paths: &[&str]) -> Result<(), GitError>;
async fn sparse_checkout_add(&self, paths: &[&str]) -> Result<(), GitError>;
async fn sparse_checkout_disable(&self) -> Result<(), GitError>;
async fn sparse_checkout_list(&self) -> Result<Vec<String>, GitError>;
async fn pull(&self, remote: &str, branch: &str, rebase: bool) -> Result<(), GitError>;
async fn switch(&self, branch: &str, create: bool) -> Result<(), GitError>;
async fn restore(
&self,
paths: &[&std::path::Path],
staged: bool,
source: Option<&str>,
) -> Result<(), GitError>;
async fn revert(&self, commits: &[&str], no_edit: bool) -> Result<(), GitError>;
async fn stash_drop(&self, index: Option<usize>) -> Result<(), GitError>;
async fn stash_apply(&self, index: Option<usize>) -> Result<(), GitError>;
async fn stash_show(&self, index: Option<usize>) -> Result<String, GitError>;
async fn remote_add(&self, name: &str, url: &str) -> Result<(), GitError>;
async fn remote_remove(&self, name: &str) -> Result<(), GitError>;
async fn remote_rename(&self, old: &str, new: &str) -> Result<(), GitError>;
async fn ls_remote(
&self,
remote: &str,
refs: Option<&[&str]>,
) -> Result<Vec<(String, String)>, GitError>;
async fn branch_rename(&self, old: &str, new: &str, force: bool) -> Result<(), GitError>;
async fn tag_delete(&self, name: &str) -> Result<(), GitError>;
async fn worktree_prune(&self) -> Result<(), GitError>;
async fn worktree_lock(&self, path: &std::path::Path) -> Result<(), GitError>;
async fn worktree_unlock(&self, path: &std::path::Path) -> Result<(), GitError>;
async fn worktree_move(
&self,
old_path: &std::path::Path,
new_path: &std::path::Path,
) -> Result<(), GitError>;
async fn mv(&self, source: &std::path::Path, dest: &std::path::Path) -> Result<(), GitError>;
async fn rm(&self, paths: &[&std::path::Path], cached: bool) -> Result<(), GitError>;
async fn merge_base(&self, commits: &[&str]) -> Result<String, GitError>;
async fn rev_parse(&self, rev: &str) -> Result<String, GitError>;
async fn hash_object(&self, data: &[u8]) -> Result<Oid, GitError>;
async fn write_blob(&self, data: &[u8]) -> Result<Oid, GitError>;
async fn mktree(&self, entries: &[crate::types::TreeEntry]) -> Result<Oid, GitError>;
async fn write_tree(&self, entries: &[crate::types::TreeEntry]) -> Result<Oid, GitError>;
async fn read_object(&self, oid: &Oid) -> Result<crate::types::ObjectContent, GitError>;
async fn read_tree(&self, oid: &Oid) -> Result<Vec<crate::types::TreeEntry>, GitError>;
async fn read_blob(&self, oid: &Oid) -> Result<Vec<u8>, GitError>;
async fn read_commit(&self, oid: &Oid) -> Result<crate::types::GitCommit, GitError>;
async fn write_commit(
&self,
parents: &[&Oid],
tree: &Oid,
message: &str,
) -> Result<Oid, GitError>;
async fn read_index(&self) -> Result<Vec<crate::types::IndexEntry>, GitError>;
async fn update_index(
&self,
path: &std::path::Path,
oid: &Oid,
mode: u32,
) -> Result<(), GitError>;
async fn remove_index(&self, path: &std::path::Path) -> Result<(), GitError>;
}