From b977f592b8ccfd3136d74cbf402f32161829afbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Mon, 7 Oct 2024 10:31:51 +0200 Subject: [PATCH] Recommend --use-host-config if --installroot is used and not all repositories can be enabled It was reported that --installroot with an explicit --repo option does not recognize given repository despite the repository is defined under /etc: $ dnf --installroot /tmp/dnf5/ --releasever rawhide --repo koji makecache No matching repositories for "*, koji". Add "--help" for more information about the arguments. That's a feature, but a difference from DNF4. This patchs recommeds using --use-host-config in that case. We already have a similar recommendation in main.cpp in case of no --repo option is used. This patch also fixes formatting of the list of repository identifiers with respect to localization. The code duplicates throws because libdnf5 exception construtors do not accept nonstatic arguments. Resolves #1756 --- dnf5/context.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dnf5/context.cpp b/dnf5/context.cpp index 303458ca4..c9aa91682 100644 --- a/dnf5/context.cpp +++ b/dnf5/context.cpp @@ -265,8 +265,16 @@ void Context::Impl::apply_repository_setopts() { } if (!missing_repo_ids.empty()) { - throw libdnf5::cli::ArgumentParserError( - M_("No matching repositories for \"{}\""), libdnf5::utils::string::join(missing_repo_ids, ", ")); + auto missing_repo_ids_string = libdnf5::utils::string::join(missing_repo_ids, _(", ")); + if (base.get_config().get_installroot_option().get_value() != "/" && + !base.get_config().get_use_host_config_option().get_value()) { + throw libdnf5::cli::ArgumentParserError( + M_("No matching repositories for {}. To use repositories from a host system, pass --use-host-config " + "option"), + missing_repo_ids_string); + } else { + throw libdnf5::cli::ArgumentParserError(M_("No matching repositories for {}"), missing_repo_ids_string); + } } }