use std::collections::{HashMap, HashSet};
use futures_io::{AsyncRead, AsyncWrite};
use ostrya_core::{Checksum, Commit, CommitLink, ObjectName, ObjectType};
use super::invalid;
use super::refspec::PushTarget;
use super::source::RepoSource;
use crate::error::{Error, Result};
use crate::lock::{LockGuard, LockKind};
use crate::read::CommitState;
use crate::refs::MAX_COLLECTION_ID_LEN;
use crate::related::{self, HeldDependency, RelatedField, RelatedRule};
use crate::remote::{
Compression, Endpoint, Expected, PushOutcome, PushProgress, PushSession, RefUpdate, ServerInfo,
SessionOptions,
};
use crate::repo::Repo;
#[derive(Clone, Debug, Default)]
pub struct RepoPushOptions {
pub refspecs: Vec<String>,
pub depth: Option<i32>,
pub collection: Option<String>,
pub tags: Vec<String>,
pub compression: Compression,
pub force: bool,
pub progress: Option<PushProgress>,
pub break_lock: bool,
#[doc(hidden)]
pub part_size: Option<u64>,
}
fn refuse_bucket_fields(opts: &RepoPushOptions) -> Result<()> {
let set = [
("break_lock", opts.break_lock),
("part_size", opts.part_size.is_some()),
];
match set.iter().find(|(_, set)| *set) {
Some((name, _)) => Err(invalid(format!(
"{name} applies to a push to an s3:// address"
))),
None => Ok(()),
}
}
#[derive(Debug, Clone, Copy)]
pub(super) enum Local {
Held(CommitLink),
Partial,
Absent,
}
pub(super) fn link_of(commit: &Commit) -> CommitLink {
CommitLink {
parent: commit.parent,
root_dirtree: commit.root_dirtree,
root_dirmeta: commit.root_dirmeta,
}
}
#[derive(Default)]
pub(super) struct Commits {
pub(super) local: HashMap<Checksum, Local>,
fields: HashMap<Checksum, Result<Vec<(String, Checksum)>>>,
known: HashSet<Checksum>,
}
impl Commits {
pub(super) fn record(&mut self, commit: Checksum, field: Result<Vec<(String, Checksum)>>) {
if !field.as_ref().is_ok_and(Vec::is_empty) {
self.fields.insert(commit, field);
}
}
pub(super) fn check_fields<'a>(
&mut self,
commits: impl IntoIterator<Item = &'a Checksum>,
) -> Result<()> {
for commit in commits {
if self.fields.get(commit).is_some_and(Result::is_err) {
return self
.fields
.remove(commit)
.expect("the field is recorded")
.map(drop);
}
}
Ok(())
}
pub(super) fn dependencies_of(
&self,
commit: &Checksum,
) -> impl Iterator<Item = Checksum> + use<'_> {
self.fields
.get(commit)
.into_iter()
.flat_map(|field| field.iter().flatten())
.map(|(_, dependency)| *dependency)
}
pub(super) async fn check_dependencies<'a>(
&mut self,
repo: &Repo,
commits: impl IntoIterator<Item = &'a Checksum>,
) -> Result<()> {
let mut named: Vec<(Checksum, Checksum, &str)> = Vec::new();
for commit in commits {
let entries = match self.fields.get(commit) {
Some(Ok(entries)) => entries,
Some(Err(_)) => {
unreachable!("the field 2 of a resolved commit passed the check")
}
None => continue,
};
for (name, dependency) in entries {
if self.known.insert(*dependency) {
named.push((*dependency, *commit, name));
}
}
}
let unread: Vec<Checksum> = named
.iter()
.map(|(dependency, _, _)| *dependency)
.filter(|dependency| !self.local.contains_key(dependency))
.collect();
let mut loaded: HashMap<_, Result<HeldDependency<CommitLink>>> = if unread.is_empty() {
HashMap::new()
} else {
let repo = repo.clone();
ostrya_rt::unblock(move || {
unread
.into_iter()
.map(|key| {
let state = related::held_dependency_blocking(&repo, None, &key, |b| {
Ok(Commit::parse_link(b)?)
});
(key, state)
})
.collect()
})
.await
};
for (dependency, naming, name) in named {
let nested = match loaded.remove(&dependency) {
Some(result) => {
let (local, nested) = match result? {
HeldDependency::Absent => (Local::Absent, false),
HeldDependency::Partial => (Local::Partial, false),
HeldDependency::Complete { nested, value } => (Local::Held(value), nested),
};
self.local.insert(dependency, local);
nested
}
None => self.fields.contains_key(&dependency),
};
match self.local[&dependency] {
Local::Absent => {
return Err(Error::ObjectNotFound {
checksum: dependency,
ty: ObjectType::Commit,
});
}
Local::Partial => {
return Err(related::partial_dependency(naming, name, &dependency));
}
Local::Held(_) if nested => {
return Err(related::nested_dependency(naming, name, &dependency));
}
Local::Held(_) => {}
}
}
Ok(())
}
}
pub(super) struct Plan {
pub(super) repo: Repo,
pub(super) _lock: LockGuard,
pub(super) refs: Vec<String>,
pub(super) targets: Vec<PushTarget>,
pub(super) collection: Option<String>,
pub(super) sources: Vec<(Checksum, Option<String>)>,
pub(super) chains: Vec<Vec<Checksum>>,
pub(super) commits: Commits,
}
impl Repo {
pub async fn push(&self, endpoint: Endpoint, opts: RepoPushOptions) -> Result<PushOutcome> {
#[cfg(feature = "s3")]
let endpoint = match endpoint {
Endpoint::S3(s3) => {
return Ok(Box::pin(self.push_to_bucket(s3, opts)).await?.outcome);
}
other => other,
};
refuse_bucket_fields(&opts)?;
let transport = PushSession::prepare(endpoint).await?;
let plan = self.plan_push(&opts).await?;
let session = transport
.open(&plan.refs, plan.session_options(&opts))
.await?;
plan.run(session, &opts).await
}
pub async fn push_over_stream<R, W>(
&self,
input: R,
output: W,
opts: RepoPushOptions,
) -> Result<PushOutcome>
where
R: AsyncRead + Unpin + Send + 'static,
W: AsyncWrite + Unpin + Send + 'static,
{
refuse_bucket_fields(&opts)?;
let plan = self.plan_push(&opts).await?;
let session =
PushSession::over_stream(input, output, &plan.refs, plan.session_options(&opts))
.await?;
plan.run(session, &opts).await
}
pub(super) async fn plan_push(&self, opts: &RepoPushOptions) -> Result<Plan> {
if let Some(depth) = opts.depth
&& depth < -1
{
return Err(invalid(format!("depth {depth} is below -1")));
}
if let Some(reason) = opts.collection.as_deref().and_then(collection_id_refusal) {
return Err(invalid(reason));
}
check_tag_names(&opts.tags)?;
let lock = self.lock_repo(LockKind::Shared).await?;
let targets = self.push_targets(&opts.refspecs).await?;
let mut sources: Vec<(Checksum, Commit)> = Vec::new();
let mut commits = Commits::default();
for target in &targets {
let Some(checksum) = target.commit else {
continue;
};
let position = match sources.iter().position(|(c, _)| *c == checksum) {
Some(position) => position,
None => {
let (mut commit, state) = self.load_commit(&checksum).await?;
if state == CommitState::Partial {
return Err(invalid(format!(
"commit {checksum} for '{}' is marked partial in the local \
repository",
target.dst
)));
}
commits
.local
.insert(checksum, Local::Held(link_of(&commit)));
let related = std::mem::take(&mut commit.related);
commits.record(checksum, related::checked_dependencies(&checksum, related));
sources.push((checksum, commit));
sources.len() - 1
}
};
check_ref_binding(&checksum, &sources[position].1, &target.dst)?;
}
check_tags(&opts.tags, &targets, &sources)?;
let sources: Vec<(Checksum, Option<String>)> = sources
.into_iter()
.map(|(checksum, commit)| (checksum, commit.collection_binding().map(str::to_owned)))
.collect();
let collection = hello_collection(opts.collection.as_deref(), &sources)?;
let depth = opts.depth.unwrap_or(-1);
let mut chains = Vec::with_capacity(targets.len());
for target in &targets {
let mut chain = Vec::new();
if let Some(source) = target.commit {
let mut next = match commits.local[&source] {
Local::Held(link) => link.parent,
Local::Partial | Local::Absent => unreachable!("a source commit is held"),
};
let mut remaining = depth;
while remaining != 0
&& let Some(parent) = next
{
match self.history_commit(&parent, &mut commits).await? {
Local::Held(link) => {
chain.push(parent);
next = link.parent;
}
Local::Partial => {
if opts.depth.is_none() {
chain.push(parent);
}
break;
}
Local::Absent => break,
}
if remaining > 0 {
remaining -= 1;
}
}
}
chains.push(chain);
}
let walked = sources
.iter()
.map(|(checksum, _)| checksum)
.chain(chains.iter().flatten());
commits.check_fields(walked.clone())?;
match opts.depth {
Some(_) => commits.check_dependencies(self, walked).await?,
None => {
let sources = sources.iter().map(|(checksum, _)| checksum);
commits.check_dependencies(self, sources).await?;
}
}
Ok(Plan {
repo: self.clone(),
_lock: lock,
refs: targets
.iter()
.map(|t| t.dst.clone())
.chain(opts.tags.iter().cloned())
.collect(),
targets,
collection,
chains,
sources,
commits,
})
}
pub(super) async fn history_commit(
&self,
checksum: &Checksum,
commits: &mut Commits,
) -> Result<Local> {
if let Some(local) = commits.local.get(checksum) {
return Ok(*local);
}
let repo = self.clone();
let key = *checksum;
let (local, field) = ostrya_rt::unblock(move || {
let bytes = match repo.load_object_bytes_blocking(ObjectType::Commit, &key) {
Ok(bytes) => bytes,
Err(Error::ObjectNotFound { .. }) => return Ok((Local::Absent, None)),
Err(e) => return Err(e),
};
Ok(match repo.commit_state_blocking(&key)? {
CommitState::Normal => {
let field = related::parse_dependencies(&bytes).and_then(|entries| {
related::checked_entries(RelatedField::Dependencies, Some(key), entries)
});
(Local::Held(Commit::parse_link(&bytes)?), Some(field))
}
CommitState::Partial => (Local::Partial, None),
})
})
.await?;
commits.local.insert(*checksum, local);
if let Some(field) = field {
commits.record(*checksum, field);
}
Ok(local)
}
}
pub(super) fn check_tag_names(tags: &[String]) -> Result<()> {
let mut seen = HashSet::new();
for tag in tags {
crate::validate_refspec(tag)?;
if tag.contains(':') || ostrya_core::is_checksum_shaped(tag) {
return Err(Error::InvalidRefspec(tag.clone()));
}
if !seen.insert(tag.as_str()) {
return Err(invalid(format!("the tag '{tag}' is named twice")));
}
}
Ok(())
}
fn check_tags(
tags: &[String],
targets: &[PushTarget],
sources: &[(Checksum, Commit)],
) -> Result<()> {
if tags.is_empty() {
return Ok(());
}
let dsts: HashSet<&str> = targets.iter().map(|t| t.dst.as_str()).collect();
if let Some(tag) = tags.iter().find(|tag| dsts.contains(tag.as_str())) {
return Err(invalid(format!(
"the tag '{tag}' is also the destination of a refspec"
)));
}
let (checksum, commit) = match sources {
[] => return Err(invalid("a tag needs a refspec that is not a delete")),
[source] => source,
_ => {
return Err(invalid(format!(
"a tag needs one source commit, and the refspecs give {}",
sources.len()
)));
}
};
let bindings = commit.ref_bindings();
let bound: HashSet<&str> = bindings.iter().copied().collect();
for tag in tags {
if !bound.contains(tag.as_str()) {
return Err(Error::Remote(crate::remote::Error::BindingMismatch(
format!(
"commit {checksum} is bound to the refs {bindings:?}, which do not hold the \
tag '{tag}'"
),
)));
}
}
Ok(())
}
pub(super) fn collection_id_refusal(id: &str) -> Option<String> {
if id.len() > MAX_COLLECTION_ID_LEN {
Some(format!(
"the collection id of {} bytes is longer than {MAX_COLLECTION_ID_LEN} bytes",
id.len()
))
} else if !ostrya_core::is_collection_id(id) {
Some(format!("invalid collection id '{id}'"))
} else {
None
}
}
pub(super) fn hello_collection(
requested: Option<&str>,
sources: &[(Checksum, Option<String>)],
) -> Result<Option<String>> {
let mut bound: Option<(&Checksum, &str)> = None;
for (checksum, binding) in sources {
let Some(binding) = binding.as_deref() else {
continue;
};
match bound {
Some((first, id)) if id != binding => {
return Err(binding_mismatch(format!(
"commit {checksum} is bound to the collection '{binding}', and commit \
{first} to the collection '{id}'"
)));
}
Some(_) => {}
None => {
if let Some(reason) = collection_id_refusal(binding) {
return Err(invalid(format!(
"commit {checksum} has a collection binding that a push cannot name: \
{reason}"
)));
}
bound = Some((checksum, binding));
}
}
}
match (requested, bound) {
(Some(requested), Some((checksum, id))) if requested != id => Err(binding_mismatch(
format!("commit {checksum} is bound to the collection '{id}', not '{requested}'"),
)),
(Some(requested), _) => Ok(Some(requested.to_owned())),
(None, bound) => Ok(bound.map(|(_, id)| id.to_owned())),
}
}
fn check_namespace(server: &ServerInfo, sources: &[(Checksum, Option<String>)]) -> Result<()> {
check_bindings(
server.collection.as_deref(),
server.binding_collection(),
sources,
)
}
pub(super) fn check_bindings(
collection: Option<&str>,
binding: Option<&str>,
sources: &[(Checksum, Option<String>)],
) -> Result<()> {
let namespace = match collection {
Some(id) => format!("the collection '{id}'"),
None => "the local refs".to_owned(),
};
for (checksum, bound) in sources {
match (bound.as_deref(), binding) {
(Some(bound), Some(id)) if bound == id => {}
(Some(bound), _) => {
return Err(binding_mismatch(format!(
"commit {checksum} is bound to the collection '{bound}', and the push \
writes {namespace}"
)));
}
(None, _) if collection.is_some() => {
return Err(binding_mismatch(format!(
"commit {checksum} has no collection binding, and the push writes \
{namespace}"
)));
}
(None, _) => {}
}
}
Ok(())
}
fn binding_mismatch(message: String) -> Error {
Error::Remote(crate::remote::Error::BindingMismatch(message))
}
pub(super) fn check_ref_binding(checksum: &Checksum, commit: &Commit, dst: &str) -> Result<()> {
let bindings = commit.ref_bindings();
let bare = dst.split_once(':').map_or(dst, |(_, bare)| bare);
if bindings.is_empty() || bindings.contains(&bare) {
return Ok(());
}
Err(Error::Remote(crate::remote::Error::BindingMismatch(
format!("commit {checksum} is bound to the refs {bindings:?}, which do not hold '{bare}'"),
)))
}
impl Plan {
fn session_options(&self, opts: &RepoPushOptions) -> SessionOptions {
SessionOptions {
collection: self.collection.clone(),
progress: opts.progress.clone(),
..SessionOptions::default()
}
}
async fn run(mut self, session: PushSession, opts: &RepoPushOptions) -> Result<PushOutcome> {
match self.negotiate(&session, opts).await {
Ok(updates) => Ok(session.commit(&updates, opts.force).await?),
Err(e) => {
let _ = session.abort().await;
Err(e)
}
}
}
async fn negotiate(
&mut self,
session: &PushSession,
opts: &RepoPushOptions,
) -> Result<Vec<RefUpdate>> {
let server = session.server();
check_namespace(server, &self.sources)?;
if let Some((tag, current)) = opts
.tags
.iter()
.find_map(|tag| server.tip(tag).map(|tip| (tag, tip)))
{
return Err(Error::Remote(crate::remote::Error::RefMismatch {
message: format!("ref '{tag}' is at {current}"),
name: tag.clone(),
current: Some(current),
}));
}
let chains = std::mem::take(&mut self.chains);
let mut offered: HashSet<Checksum> = HashSet::new();
let mut names = Vec::new();
for (target, chain) in self.targets.iter().zip(&chains) {
let Some(source) = target.commit else {
continue;
};
let history = offered_history(opts.depth, server.tip(&target.dst), chain);
for commit in std::iter::once(&source).chain(history) {
if offered.insert(*commit) {
names.push(ObjectName::new(*commit, ObjectType::Commit));
}
}
}
drop(chains);
if opts.depth.is_none() {
let offer = names.iter().map(|name| &name.checksum);
self.commits.check_dependencies(&self.repo, offer).await?;
}
let resolved = names.len();
for at in 0..resolved {
let commit = names[at].checksum;
for dependency in self.commits.dependencies_of(&commit) {
if offered.insert(dependency) {
names.push(ObjectName::new(dependency, ObjectType::Commit));
}
}
}
drop(offered);
let commits = std::mem::take(&mut self.commits);
if !names.is_empty() {
let missing_commits = session.missing(&names).await?;
drop(names);
let lacking: HashSet<Checksum> = missing_commits.iter().map(|n| n.checksum).collect();
let sources: HashSet<Checksum> = self.sources.iter().map(|(c, _)| *c).collect();
let walked = self
.sources
.iter()
.map(|(c, _)| *c)
.chain(
missing_commits
.iter()
.map(|n| n.checksum)
.filter(|c| !sources.contains(c)),
)
.collect::<Vec<_>>();
let mut seen = HashSet::new();
let mut tree_names = Vec::new();
for commit in &walked {
let Local::Held(link) = commits.local[commit] else {
unreachable!("an offered commit is held");
};
self.repo
.collect_tree_strict(
link.root_dirtree,
link.root_dirmeta,
&mut seen,
&mut tree_names,
)
.await?;
}
drop(commits);
drop(seen);
let repo = self.repo.clone();
let images = ostrya_rt::unblock(move || -> Result<Vec<ObjectName>> {
let mut images = Vec::new();
for commit in walked {
if repo.has_object_blocking(ObjectType::ComposefsImage, &commit)? {
images.push(ObjectName::new(commit, ObjectType::ComposefsImage));
}
}
Ok(images)
})
.await?;
tree_names.extend(images);
let missing_trees = session.missing(&tree_names).await?;
drop(tree_names);
let mut needed = missing_commits;
needed.extend(missing_trees);
let mut metadata: Vec<Checksum> = needed
.iter()
.filter(|n| n.ty == ObjectType::Commit)
.map(|n| n.checksum)
.collect();
metadata.extend(
self.sources
.iter()
.map(|(c, _)| *c)
.filter(|c| !lacking.contains(c)),
);
let source = RepoSource::new(self.repo.clone(), RelatedRule::default());
session
.send(&source, &needed, &metadata, opts.compression)
.await?;
}
let tags = opts.tags.iter().map(|tag| RefUpdate {
name: tag.clone(),
expected: Expected::Absent,
new: self.sources.first().map(|(c, _)| *c),
});
Ok(self
.targets
.iter()
.map(|target| RefUpdate {
name: target.dst.clone(),
expected: match (opts.force, server.tip(&target.dst)) {
(true, _) => Expected::Any,
(false, Some(tip)) => Expected::Commit(tip),
(false, None) => Expected::Absent,
},
new: target.commit,
})
.chain(tags)
.collect())
}
}
pub(super) fn offered_history(
depth: Option<i32>,
tip: Option<Checksum>,
chain: &[Checksum],
) -> &[Checksum] {
match (depth, tip) {
(Some(_), _) => chain,
(None, Some(tip)) => match chain.iter().position(|c| *c == tip) {
Some(at) => &chain[..at],
None => &[],
},
(None, None) => &[],
}
}
#[cfg(test)]
mod tests {
use super::*;
fn csum(byte: u8) -> Checksum {
Checksum::from_bytes([byte; 32])
}
fn sources(bindings: &[Option<&str>]) -> Vec<(Checksum, Option<String>)> {
bindings
.iter()
.enumerate()
.map(|(i, b)| (csum(i as u8 + 1), b.map(str::to_owned)))
.collect()
}
fn mismatch<T: std::fmt::Debug>(result: Result<T>) -> String {
match result {
Err(Error::Remote(crate::remote::Error::BindingMismatch(message))) => message,
other => panic!("expected BindingMismatch, got {other:?}"),
}
}
fn server(collection_id: Option<&str>, collection: Option<&str>) -> ServerInfo {
ServerInfo {
version: 1,
mode: "archive".into(),
collection_id: collection_id.map(str::to_owned),
collection: collection.map(str::to_owned),
max_frame: 1 << 20,
max_have: 16_384,
encodings: Vec::new(),
parallel_uploads: 1,
refs: Vec::new(),
}
}
#[test]
fn the_hello_collection_comes_from_the_request_or_the_bindings() {
let os = Some("org.example.Os");
assert_eq!(hello_collection(None, &sources(&[])).unwrap(), None);
assert_eq!(
hello_collection(None, &sources(&[None, None])).unwrap(),
None
);
for bindings in [&[os][..], &[os, os], &[None, os], &[os, None]] {
assert_eq!(
hello_collection(None, &sources(bindings))
.unwrap()
.as_deref(),
os,
"{bindings:?}"
);
assert_eq!(
hello_collection(os, &sources(bindings)).unwrap().as_deref(),
os,
"{bindings:?}"
);
}
assert_eq!(
hello_collection(os, &sources(&[None])).unwrap().as_deref(),
os
);
}
#[test]
fn disagreeing_bindings_are_refused() {
let message = mismatch(hello_collection(
None,
&sources(&[Some("org.example.A"), None, Some("org.example.B")]),
));
assert!(message.contains("'org.example.B'"), "{message}");
assert!(message.contains("'org.example.A'"), "{message}");
let message = mismatch(hello_collection(
Some("org.example.B"),
&sources(&[Some("org.example.A")]),
));
assert!(message.contains("not 'org.example.B'"), "{message}");
}
#[test]
fn a_binding_that_names_no_namespace_is_invalid_input() {
let longest = format!("org.{}", "a".repeat(251));
let over = format!("org.{}", "a".repeat(252));
assert_eq!(collection_id_refusal(&longest), None);
assert_eq!(
hello_collection(None, &sources(&[Some(&longest)]))
.unwrap()
.as_deref(),
Some(longest.as_str())
);
for (binding, needle) in [("no-dot", "'no-dot'"), (over.as_str(), "256 bytes")] {
for requested in [None, Some(binding)] {
match hello_collection(requested, &sources(&[None, Some(binding)])) {
Err(Error::Remote(crate::remote::Error::InvalidInput(message))) => {
assert!(message.contains(needle), "{message}");
assert!(message.contains(&csum(2).to_string()), "{message}");
}
other => panic!("{binding}: expected InvalidInput, got {other:?}"),
}
}
assert!(
collection_id_refusal(binding).is_some_and(|reason| reason.contains(needle)),
"{binding}"
);
}
}
#[test]
fn the_reported_namespace_must_agree_with_each_binding() {
let os = Some("org.example.Os");
let own = server(os, None);
let mirror = server(None, os);
let plain = server(None, None);
check_namespace(&own, &sources(&[os, None])).unwrap();
check_namespace(&mirror, &sources(&[os, os])).unwrap();
check_namespace(&plain, &sources(&[None])).unwrap();
let message = mismatch(check_namespace(&mirror, &sources(&[os, None])));
assert!(message.contains("no collection binding"), "{message}");
let message = mismatch(check_namespace(&plain, &sources(&[os])));
assert!(message.contains("the local refs"), "{message}");
mismatch(check_namespace(
&server(Some("org.example.B"), None),
&sources(&[os]),
));
}
#[test]
fn the_bindings_must_agree_with_the_namespace_of_the_push() {
let a = Some("org.example.A");
let b = Some("org.example.B");
check_bindings(None, None, &sources(&[None])).unwrap();
let message = mismatch(check_bindings(None, None, &sources(&[a])));
assert!(
message.contains("and the push writes the local refs"),
"{message}"
);
check_bindings(None, a, &sources(&[a, None])).unwrap();
mismatch(check_bindings(None, a, &sources(&[b])));
check_bindings(b, b, &sources(&[b, b])).unwrap();
let message = mismatch(check_bindings(b, b, &sources(&[None])));
assert!(message.contains("no collection binding"), "{message}");
assert!(
message.contains("the collection 'org.example.B'"),
"{message}"
);
mismatch(check_bindings(b, b, &sources(&[a])));
}
#[test]
fn the_offered_history_ends_before_the_tip() {
let chain = [csum(1), csum(2), csum(3)];
assert_eq!(offered_history(Some(0), Some(csum(2)), &chain), chain);
assert_eq!(
offered_history(None, Some(csum(3)), &chain),
[csum(1), csum(2)]
);
assert_eq!(offered_history(None, Some(csum(1)), &chain), []);
assert!(offered_history(None, Some(csum(9)), &chain).is_empty());
assert!(offered_history(None, None, &chain).is_empty());
}
#[test]
fn the_bucket_fields_are_refused_for_a_session_push() {
refuse_bucket_fields(&RepoPushOptions::default()).unwrap();
for (opts, name) in [
(
RepoPushOptions {
break_lock: true,
..RepoPushOptions::default()
},
"break_lock",
),
(
RepoPushOptions {
part_size: Some(5 << 20),
..RepoPushOptions::default()
},
"part_size",
),
] {
match refuse_bucket_fields(&opts) {
Err(Error::Remote(crate::remote::Error::InvalidInput(message))) => {
assert_eq!(
message,
format!("{name} applies to a push to an s3:// address")
);
}
other => panic!("{name}: {other:?}"),
}
}
}
}