SIGN IN SIGN UP

fix(grep): match GNU exit status for -L (#332)

`grep -L` computed its exit status from whether it had printed any
filenames, which is the inverse of GNU grep for the homogeneous cases.
GNU's status reports whether a *line was selected*, never whether a
*name was printed*, so `-L` shares the ordinary rule: 0 if any input
matched, 1 if none did, 2 on error.

Measured against GNU grep 3.12, cross-checked against BSD grep
2.6.0-FreeBSD, which agrees:

  all files match    -> prints nothing,    exit 0  (was 1)
  no file matches    -> prints every name, exit 1  (was 0)
  mixed input        -> prints the misses, exit 0  (unchanged)
  missing operand    -> diagnostic,        exit 2  (unchanged)
  -q, nothing found  -> prints nothing,    exit 1  (was 0)
  empty file         -> prints its name,   exit 1  (was 0)

`-c`, `-n`, `-o`, `-m` and `--files-without-match` route through the
same rule and were wrong in the same way. ripgrep 15.1.0's
--files-without-match genuinely does invert the status, so
src/commands/rg keeps the opposite rule and is left alone apart from a
comment recording the measurement, so neither side gets "fixed" into
agreeing with the other.

The two BusyBox spec cases covering this encode BusyBox's deliberate
inversion -- its own comment in the test file says as much -- so both
now disagree with just-bash rather than one; the skip list records the
measured GNU and BSD output for each.


Claude-Session: https://claude.ai/code/session_019DayCPuYZEmv4VszJXTHT3

Signed-off-by: Lars Trieloff <lars@trieloff.net>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
L
Lars Trieloff committed
4f9bdec02edb9eb72511546b759cb7e20bc2e27e
Parent: eaedb5b
Committed by GitHub <noreply@github.com> on 8/6/2026, 2:04:04 AM