Skip to content

sort: let --check take precedence over --merge - #15381

Merged
RenjiSann merged 1 commit into
uutils:mainfrom
emirmrkaljevic:sort-check-merge-precedence
Oct 16, 2026
Merged

RenjiSann merged 1 commit into
uutils:mainfrom
emirmrkaljevic:sort-check-merge-precedence

Conversation

@emirmrkaljevic

Copy link
Copy Markdown
Contributor

Summary

When both --check (-c) and --merge (-m) are given with a single input, GNU sort still checks that the input is ordered. uutils preferred the merge path, printed the file, and exited 0 even when the input was disordered.

$ printf 'b\na\n' > unsorted.txt
$ sort -c -m unsorted.txt          # GNU → exit 1, disorder diagnostic
$ ./sort -c -m unsorted.txt        # uutils before → printed b\\na, exit 0

exec() now runs the check path when settings.check is set, matching GNU. Multiple-file -c rejection is unchanged.

Closes #15380

Test plan

  • cargo test --features "feat_common_core sort" --no-default-features test_check_with_merge_still_checks — pass
  • Manual: printf 'b\na\n' | sort -c -m → exit 1 / disorder; sorted input → exit 0
  • Recorded GNU case replayed with behave against the fixed binary — 1/1 pass

Found with behave.

When both -c/--check and -m/--merge were set, exec() preferred merge
and printed the input instead of checking order. GNU still checks.
With one disordered file this wrongly exited 0.

Fixes uutils#15380
@RenjiSann
RenjiSann merged commit dccea81 into uutils:main Oct 16, 2026
100 checks passed
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.

sort: --check --merge ignores --check and merges instead

2 participants