use std::path::Path;
use crate::branch::{self, Verb};
use crate::error::{Error, Result};
use crate::host::Hosting;
use crate::publish::{PublishOutcome, Subject};
use crate::registry::Registry;
use crate::rules::MergePolicy;
use crate::stream::Stream;
pub fn run(
registry: &Registry,
repo: &Path,
branch: &str,
title: Option<Subject>,
policy: Option<MergePolicy>,
hosting: &dyn Hosting,
stream: &mut Stream,
) -> Result<PublishOutcome> {
let landing = branch::prepare(registry, Verb::PublishBranch, repo, branch, policy)?;
let unattested = landing.unattested()?;
if !unattested.is_empty() {
return Err(Error::Invalid {
reason: format!(
"branch {branch:?} carries incomplete provenance ({} unattested marker(s)): a \
step stopped before it finished, and publishing it means attesting that a green \
gate cleared what stopped. `publish-branch` publishes completed work; land this \
one with `{}`, which runs the gate and writes that attestation",
unattested.len(),
landing.command_for(Verb::Recover),
),
});
}
if let Some(prefix) = landing.unrecognized()?.first() {
return Err(Error::Invalid {
reason: landing.unreadable_prefix(prefix),
});
}
landing.sync_change_base(stream)?;
landing.publish(title, hosting, stream)
}