Skip to content

Conflicting -i, -s, and -S use fixed precedence instead of the last case flag #197

Closed

Description

@wuliangtdi

Summary

tgrep resolves conflicting case flags using fixed precedence (-i above -s above -S) regardless of argument order. ripgrep uses the last case flag. This can either admit unwanted matches or silently omit expected matches.

This is separate from #183: the patterns themselves now participate in smart-case analysis, but conflicting flags still resolve incorrectly.

Reproduce

mkdir repro-case-order && cd repro-case-order
mkdir data
printf 'foo\nFOO\n' > data/a.txt

tgrep --no-index -I -i -s -- foo data
rg               -I -i -s -- foo data

tgrep --no-index -I -i -S -- FOO data
rg               -I -i -S -- FOO data

tgrep --no-index -I -s -S -- foo data
rg               -I -s -S -- foo data

# Passing control: the last flag is -i
tgrep --no-index -I -s -i -- foo data
rg               -I -s -i -- foo data
Query Actual: tgrep 1.2.0 Expected: rg 15.1.0
-i -s -- foo foo\nFOO\n foo\n
-i -S -- FOO foo\nFOO\n FOO\n
-s -S -- foo foo\n foo\nFOO\n
Control: -s -i -- foo foo\nFOO\n foo\nFOO\n

All commands exit 0.

The content-search cases reproduce with --no-index, an on-disk index, and tgrep serve --no-watch.

To repeat the indexed cases, run tgrep index data, remove --no-index, and keep the directory path data. For the server cases, start tgrep serve --no-watch data in another terminal and repeat those directory searches. --stats was used in the Windows harness to verify the selected backend, including (via server).

Environment

  • tgrep 1.2.0, official Windows x86_64 release.
  • Source inspected at release commit 3ba6ee02537281b68ee1366bb40df9f8b7cc54f0.
  • Windows; test harness run with PowerShell 7.
  • ripgrep 15.1.0 (af60c2de9d).
  • Verified on 2026-10-12. The shell examples describe the same fixture bytes and arguments tested on Windows.

Cause

The three flags are independent global booleans in tgrep-cli/src/main.rs:54. tgrep-cli/src/search.rs:227 returns immediately for ignore-case, then case-sensitive, then smart-case, which fixes their precedence regardless of CLI order.

Possible fix

Resolve the most recent case flag before computing smart-case and constructing matchers or query plans. Preserve that resolution across explicit search subcommands as well.

A regression could cover all three failing sequences and the passing reverse-order control across the three search backends.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions