use std::path::PathBuf;
use crate::remote::fetch;
#[derive(Debug, Clone)]
pub struct Outcome {
pub edits: Vec<gix_ref::transaction::RefEdit>,
pub updates: Vec<super::Update>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Mode {
NoChangeNeeded,
FastForward,
Forced,
New,
ImplicitTagNotSentByRemote,
RejectedSourceObjectNotFound {
id: gix_hash::ObjectId,
},
RejectedTagUpdate,
RejectedNonFastForward,
RejectedToReplaceWithUnborn,
RejectedCurrentlyCheckedOut {
worktree_dirs: Vec<PathBuf>,
},
}
impl std::fmt::Display for Mode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Mode::NoChangeNeeded => "up-to-date",
Mode::FastForward => "fast-forward",
Mode::Forced => "forced-update",
Mode::New => "new",
Mode::ImplicitTagNotSentByRemote => "unrelated tag on remote",
Mode::RejectedSourceObjectNotFound { id } => return write!(f, "rejected ({id} not found)"),
Mode::RejectedTagUpdate => "rejected (would overwrite existing tag)",
Mode::RejectedNonFastForward => "rejected (non-fast-forward)",
Mode::RejectedToReplaceWithUnborn => "rejected (refusing to overwrite existing with unborn ref)",
Mode::RejectedCurrentlyCheckedOut { worktree_dirs } => {
return write!(
f,
"rejected (cannot write into checked-out branch at \"{}\")",
worktree_dirs
.iter()
.filter_map(|d| d.to_str())
.collect::<Vec<_>>()
.join(", ")
);
}
}
.fmt(f)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum TypeChange {
DirectToSymbolic,
SymbolicToDirect,
}
impl Outcome {
pub fn iter_mapping_updates<'a, 'b>(
&self,
mappings: &'a [fetch::refmap::Mapping],
refspecs: &'b [gix_refspec::RefSpec],
extra_refspecs: &'b [gix_refspec::RefSpec],
) -> impl Iterator<
Item = (
&super::Update,
&'a fetch::refmap::Mapping,
Option<&'b gix_refspec::RefSpec>,
Option<&gix_ref::transaction::RefEdit>,
),
> {
self.updates.iter().zip(mappings.iter()).map(move |(update, mapping)| {
(
update,
mapping,
mapping.spec_index.get(refspecs, extra_refspecs),
update.edit_index.and_then(|idx| self.edits.get(idx)),
)
})
}
}