Skip to content

Honor argument order for --type-add and --type-clear to match ripgrep #201

Closed

Description

@wuliangtdi

Summary

tgrep always applies every --type-clear before every --type-add, regardless of their order on the command line. ripgrep applies these operations in argument order.

For --type-add 'rust:*.txt' --type-clear rust -t rust, ripgrep removes the type and reports it as undefined, while tgrep adds it back and searches .txt files.

The current tgrep help explicitly describes clearing before adding. This is therefore a request for ripgrep compatibility, rather than a claim that tgrep violates that help text.

Reproduce

mkdir repro-type-definitions && cd repro-type-definitions
mkdir data
printf 'needle\n' > data/a.rs
printf 'needle\n' > data/a.txt

tgrep --no-index --type-add 'rust:*.txt' --type-clear rust -t rust -l -- needle data
rg               --type-add 'rust:*.txt' --type-clear rust -t rust -l -- needle data
Tool Stdout Stderr Exit code
tgrep 1.2.0 data/a.txt No error 0
rg 15.1.0 Empty rg: unrecognized file type: rust 2

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

tgrep-cli/src/search.rs:2233 receives separate add/clear lists, clears all requested types first, then applies all additions. The original interleaving is discarded.

Possible fix

Retain and replay the ordered type-definition operations for search and --type-list. Update the help text if this compatibility change is adopted.

A regression could cover both add-then-clear and clear-then-add sequences, with content search and type listing.

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