Skip to content

Commit

Permalink
Fix default origin repo not respecting --when
Browse files Browse the repository at this point in the history
As discussed in #1087 reuse the same logic for configuring the implicit
"origin" repo as any explicitly enabled repos.

Also fix a problem from the pre-#1087 code where any explicitly
enabled "origin" (with custom pin) would be replaced by the implicit one.

Signed-off-by: J Robert Ray <jrray@jrray.org>
  • Loading branch information
jrray committed Aug 4, 2024
1 parent 542679f commit fa1e025
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions crates/spk-cli/common/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use spk_schema::foundation::option_map::OptionMap;
use spk_schema::foundation::spec_ops::Named;
use spk_schema::foundation::version::CompatRule;
use spk_schema::ident::{parse_ident, AnyIdent, PkgRequest, Request, RequestedBy, VarRequest};
use spk_schema::ident_ops::NormalizedTagStrategy;
use spk_schema::option_map::HOST_OPTIONS;
use spk_schema::{Recipe, SpecRecipe, SpecTemplate, Template, TemplateExt, TestStage, VariantExt};
#[cfg(feature = "statsd")]
Expand Down Expand Up @@ -958,20 +957,38 @@ impl Repositories {
if self.local_repo_only {
return Ok(repos);
}
for (name, ts) in enabled.into_iter() {
for (name, ts, is_default_origin) in enabled
.into_iter()
.map(|(name, ts)| (name, ts, false))
.chain([("origin", None, true)])
{
if disabled.contains(name) {
continue;
}
if let Some(i) = repos.iter().position(|(n, _)| n == name) {
// we favor the last instance of an --enable-repo flag
// over any previous one in the case of duplicates
// We favor the last instance of an --enable-repo flag
// over any previous one in the case of duplicates, except
// any explicit "origin" overrides the default.
if is_default_origin {
// Keep the explicitly enabled "origin" repo.
continue;
}
repos.remove(i);
}

let mut repo = match name {
// Allow `--enable-repo local` to work to enable the local repo.
"local" => storage::local_repository().await,
name => storage::remote_repository(name).await,
name => match storage::remote_repository(name).await {
Err(spk_storage::Error::SPFS(spfs::Error::UnknownRemoteName(_)))
if is_default_origin =>
{
// "origin" is not required to exist when attempting to
// add it as a default
continue;
}
other => other,
},
}?;
if let Some(ts) = ts.as_ref().or(self.when.as_ref()) {
repo.pin_at_time(ts);
Expand All @@ -981,21 +998,6 @@ impl Repositories {
}
repos.push((name.into(), repo.into()));
}
let has_origin = repos.iter().any(|(n, _)| n == "origin");
if !disabled.contains("origin") && !has_origin {
// the origin repo is considered a default and specifically
// added at the very end of any command line flags if needed
match storage::remote_repository::<_, NormalizedTagStrategy>("origin").await {
Err(spk_storage::Error::SPFS(spfs::Error::UnknownRemoteName(_))) => {}
Err(err) => return Err(err.into()),
Ok(mut origin) => {
if self.legacy_spk_version_tags {
origin.set_legacy_spk_version_tags(true);
}
repos.push(("origin".into(), origin.into()));
}
}
}
Ok(repos)
}
}
Expand Down

0 comments on commit fa1e025

Please sign in to comment.