use crate::command::GitCommand;
use crate::command::add::AddCommand;
use crate::command::checkout::CheckoutCommand;
use crate::command::commit::CommitCommand;
use crate::command::merge::MergeCommand;
use crate::command::pull::PullCommand;
use crate::error::Result;
use crate::repo::Repository;
#[derive(Debug)]
pub struct WorkflowOps<'a> {
repo: &'a Repository,
}
impl<'a> WorkflowOps<'a> {
pub async fn feature_branch(
&self,
name: impl Into<String>,
base: impl Into<String>,
) -> Result<()> {
let mut cmd = CheckoutCommand::new();
cmd.create(name).target(base);
cmd.current_dir(self.repo.path());
cmd.execute().await?;
Ok(())
}
pub async fn commit_all(&self, message: impl Into<String>) -> Result<()> {
let mut add = AddCommand::new();
add.all();
add.current_dir(self.repo.path());
add.execute().await?;
let mut commit = CommitCommand::new();
commit.message(message);
commit.current_dir(self.repo.path());
commit.execute().await?;
Ok(())
}
pub async fn sync(&self) -> Result<()> {
let mut cmd = PullCommand::new();
cmd.rebase();
cmd.current_dir(self.repo.path());
cmd.execute().await?;
Ok(())
}
pub async fn squash_merge(&self, branch: impl Into<String>) -> Result<()> {
let mut cmd = MergeCommand::new();
cmd.squash().commit_ref(branch);
cmd.current_dir(self.repo.path());
cmd.execute().await?;
Ok(())
}
}
impl Repository {
#[must_use]
pub fn workflow(&self) -> WorkflowOps<'_> {
WorkflowOps { repo: self }
}
}