Skip to content

sort: reject mixing silent and diagnosing --check modes - #15735

Open
komal0000 wants to merge 3 commits into
uutils:mainfrom
komal0000:fix/sort-repeated-check-modes
Open

komal0000 wants to merge 3 commits into
uutils:mainfrom
komal0000:fix/sort-repeated-check-modes

Conversation

@komal0000

Copy link
Copy Markdown

sort keeps only the last --check value, so a silent and a diagnosing check mode given together are not rejected:

$ sort --check=silent --check=diagnose-first check_fail.txt
sort: check_fail.txt:6: disorder: 5

GNU sort rejects this with sort: options '-cC' are incompatible (exit 2), as it already does for -c -C. The reverse case was wrong too: --check=quiet -C was rejected even though both modes are silent, and GNU accepts it.

With this change, --check collects all of its values (a bare -c/--check counts as diagnose-first). The check is silent if -C or any --check=silent|quiet is given, and diagnosing if any bare -c or --check=diagnose-first is given. Having both is rejected with the -cC error, and repeating the same mode is fine. I compared these cases against GNU sort 8.32:

args GNU before after
--check=silent --check=diagnose-first -cC incompatible, 2 disorder message, 1 -cC incompatible, 2
-c --check=quiet -cC incompatible, 2 silent, 1 -cC incompatible, 2
--check=quiet -C silent, 1 -cC incompatible, 2 silent, 1
--check=quiet --check=silent silent, 1 silent, 1 silent, 1
--check=diagnose-first -c disorder message, 1 disorder message, 1 disorder message, 1

-c=VALUE itself (with a short option) is still accepted. I left that out because it's clap's require_equals behavior for the shared -c/--check argument.

Fixes #15595

Tests: added test_check_repeated_modes. It fails on main (--check=silent --check=diagnose-first exits 1 with the disorder message) and passes with this change. cargo test --features sort --no-default-features -- test_sort:: gives 193 passed, 6 failed on Windows. The 6 failures (test_compress_fail, test_ext_sort_preserves_long_lines, test_merge_batch_size, test_merge_batches, test_output_is_input, test_unterminated_file_not_fused_across_chunk_boundary) fail the same way on main on my Windows machine. cargo fmt --check and cargo clippy -p uu_sort -- -D warnings are clean.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 10:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Comment thread tests/by-util/test_sort.rs
Copilot AI balanced review requested due to automatic review settings October 26, 2026 03:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@komal0000

Copy link
Copy Markdown
Author

Added in ed025f5: ["-c=silent", "-c=diagnose-first"] is now in test_check_repeated_modes, so the exact case from the issue is covered. Thanks for the review!

Copilot AI balanced review requested due to automatic review settings October 26, 2026 03:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(sort): alternative -c= specific uutils syntax allows duplicates

3 participants