use crate::branch_inventory::{
list_branches as list_branches_detailed, upstream_status, BranchDetail, BranchListQuery,
BranchSummary,
};
use crate::branch_tracking::{
apply_push_remote_tracking_updates_in, compare_with_target_optional,
upstream_tracking_full_ref, TargetComparison, TargetComparisonOptions,
};
use crate::error::Result;
use crate::objects::ObjectId;
use crate::porcelain::branch::{
create_branch, delete_branch, list_branches as list_branches_simple, preview_unset_upstream,
rename_branch, resolve_create_tracking, set_upstream, unset_upstream, validate_set_upstream,
BranchCreateOptions, BranchDeleteOptions, BranchList, BranchRenameOptions, CreateBranchOutcome,
DeletedBranch, RenameBranchOutcome, TrackMode,
};
use crate::porcelain::switch::{resolve_create_branch, SwitchMode};
use crate::push_report::PushRefResult;
use crate::repo::Repository;
#[derive(Debug, Copy, Clone)]
pub struct Branches<'repo> {
repo: &'repo Repository,
}
impl<'repo> Branches<'repo> {
pub(crate) fn new(repo: &'repo Repository) -> Self {
Self { repo }
}
#[must_use]
pub fn repository(&self) -> &'repo Repository {
self.repo
}
pub fn create(&self, opts: &BranchCreateOptions) -> Result<CreateBranchOutcome> {
create_branch(self.repo, opts)
}
pub fn resolve_create_tracking(
&self,
branch_short: &str,
start_label: &str,
start_oid: ObjectId,
track: TrackMode,
) -> Result<Option<(String, String)>> {
resolve_create_tracking(self.repo, branch_short, start_label, start_oid, track)
}
pub fn resolve_create_for_switch(
&self,
name: &str,
start: Option<&str>,
track: TrackMode,
) -> Result<SwitchMode> {
resolve_create_branch(self.repo, name, start, track)
}
pub fn list_simple(&self) -> Result<BranchList> {
list_branches_simple(self.repo)
}
pub fn list(
&self,
query: &BranchListQuery,
detail: BranchDetail,
) -> Result<Vec<BranchSummary>> {
list_branches_detailed(self.repo, query, detail)
}
pub fn upstream_status(
&self,
branch: &str,
) -> Result<Option<crate::branch_inventory::UpstreamStatus>> {
upstream_status(self.repo, branch)
}
pub fn delete(&self, name: &str, opts: &BranchDeleteOptions) -> Result<DeletedBranch> {
delete_branch(self.repo, name, opts.mode, opts.dry_run)
}
pub fn rename(&self, opts: &BranchRenameOptions) -> Result<RenameBranchOutcome> {
rename_branch(self.repo, opts)
}
pub fn validate_set_upstream(&self, branch: &str, upstream: &str) -> Result<String> {
validate_set_upstream(self.repo, branch, upstream)
}
pub fn set_upstream(&self, branch: &str, upstream: &str) -> Result<()> {
set_upstream(self.repo, branch, upstream)
}
pub fn preview_unset_upstream(&self, branch: &str) -> Result<()> {
preview_unset_upstream(self.repo, branch)
}
pub fn unset_upstream(&self, branch: &str) -> Result<()> {
unset_upstream(self.repo, branch)
}
#[must_use]
pub fn upstream_tracking_full_ref(&self, branch_short: &str) -> Option<String> {
upstream_tracking_full_ref(self.repo, branch_short)
}
pub fn compare_with_target(
&self,
opts: &TargetComparisonOptions,
) -> Result<Option<TargetComparison>> {
compare_with_target_optional(self.repo, opts)
}
pub fn apply_push_remote_tracking_updates(
&self,
remote: &str,
results: &[PushRefResult],
) -> Result<()> {
apply_push_remote_tracking_updates_in(self.repo, remote, results)
}
}