use crate::diff::DiffEntry;
use crate::error::Result;
use crate::objects::ObjectId;
use crate::porcelain::stash::{
apply_stash_entry, apply_stash_oid, clear_stashes, create_stash, drop_stash, list_stashes,
pop_stash_entry, preview_stash, push_stash, stash_branch, stash_diff, StashApplyOptions,
StashApplyOutcome, StashBranchOutcome, StashDiffOptions, StashEntry, StashPreview,
StashPushOptions, StashPushResult,
};
use crate::repo::Repository;
#[derive(Debug, Copy, Clone)]
pub struct RepositoryStash<'repo> {
repo: &'repo Repository,
}
impl<'repo> RepositoryStash<'repo> {
pub(crate) fn new(repo: &'repo Repository) -> Self {
Self { repo }
}
#[must_use]
pub fn repository(&self) -> &'repo Repository {
self.repo
}
pub fn list(&self) -> Result<Vec<StashEntry>> {
list_stashes(self.repo)
}
pub fn push(&self, options: &StashPushOptions) -> Result<Option<StashPushResult>> {
push_stash(self.repo, options)
}
pub fn preview(&self, options: &StashPushOptions) -> Result<Option<StashPreview>> {
preview_stash(self.repo, options)
}
pub fn create(&self, options: &StashPushOptions) -> Result<Option<ObjectId>> {
create_stash(self.repo, options)
}
pub fn apply(&self, index: usize, options: &StashApplyOptions) -> Result<StashApplyOutcome> {
apply_stash_entry(self.repo, index, options)
}
pub fn apply_commit(
&self,
stash: &ObjectId,
options: &StashApplyOptions,
) -> Result<StashApplyOutcome> {
apply_stash_oid(self.repo, stash, options)
}
pub fn pop(&self, index: usize, options: &StashApplyOptions) -> Result<StashApplyOutcome> {
pop_stash_entry(self.repo, index, options)
}
pub fn drop(&self, index: usize) -> Result<()> {
drop_stash(self.repo, index)
}
pub fn clear(&self) -> Result<usize> {
clear_stashes(self.repo)
}
pub fn diff(&self, index: usize, options: &StashDiffOptions) -> Result<Vec<DiffEntry>> {
stash_diff(self.repo, index, options)
}
pub fn branch(&self, name: &str, index: usize) -> Result<StashBranchOutcome> {
stash_branch(self.repo, name, index)
}
}