Skip to content

Commit

Permalink
profile: make --all exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvanderlinden committed Mar 6, 2024
1 parent 8efccb4 commit 93020f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/nix/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,15 @@ class MixProfileElementMatchers : virtual Args, virtual StoreCommand
throw UsageError("No packages specified.");
}

if (std::find_if(_matchers.begin(), _matchers.end(), [](const Matcher & m) { return m.name == "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<std::string> result;
for (auto & matcher : _matchers) {
bool foundMatch = false;
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/nix-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 from profile.
Expand Down

0 comments on commit 93020f0

Please sign in to comment.