From 91f068c19309091b85f18fb5fc10ab3644642d50 Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Wed, 6 Mar 2024 22:46:47 +0100 Subject: [PATCH] profile: make --all exclusive --- src/nix/profile.cc | 9 +++++++++ tests/functional/nix-profile.sh | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 701c5cb29..d9455b4ee 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -554,6 +554,15 @@ public: throw UsageError("No packages specified."); } + if (std::find_if(_matchers.begin(), _matchers.end(), [](const Matcher & m) { return m.type == MatcherType::All; }) != _matchers.end() && _matchers.size() > 1) { + throw UsageError("--all cannot be used with package names or regular expressions."); + } + + if (manifest.elements.empty()) { + warn("There are no packages in the profile."); + return {}; + } + std::set result; for (auto & matcher : _matchers) { bool foundMatch = false; diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index b8513ac02..58fdce411 100644 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -84,6 +84,12 @@ nix profile upgrade --all nix profile rollback printf 1.0 > $flake1Dir/version +# Test --all exclusivity. +assertStderr nix --offline profile upgrade --all foo << EOF +error: --all cannot be used with package names or regular expressions. +Try 'nix --help' for more information. +EOF + # Test matching no packages using literal package name. assertStderr nix --offline profile upgrade this_package_is_not_installed << EOF warning: Package name 'this_package_is_not_installed' does not match any packages in the profile.