Skip to content

fix(rg): sort metadata across explicit paths - #1958

Merged
chaliy merged 1 commit into
mainfrom
2026-06-05-propose-fix-for-rg-metadata-sorting-issue
Jun 5, 2026
Merged

chaliy merged 1 commit into
mainfrom
2026-06-05-propose-fix-for-rg-metadata-sorting-issue

Conversation

@chaliy

@chaliy chaliy commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • Metadata-based --sort/--sortr modes were only applied to recursive candidate batches, so explicit file/argument paths and the --files explicit-path branch were not ordered by metadata as intended.
  • The change ensures behavior matches ripgrep parity: metadata sorts should order all file candidates (recursive + explicit) consistently.

Description

  • Collect explicit path arguments as RgFileCandidate entries (preserving metadata) instead of appending bare explicit inputs, so they can participate in a single global candidate sort.
  • Add display_override and explicit fields to RgFileCandidate and centralize display logic via candidate_display_path(...) to preserve explicit-file display semantics.
  • Apply sort_rg_candidates(...) over the aggregated candidate list (honoring --sort/--sortr and --sort none) before reading files, and update --files to render sorted candidate displays via the same helper.
  • Add timed differential test cases for metadata sorting across explicit file arguments and for --files --sort modified with explicit files.
  • All changes confined to crates/bashkit/src/builtins/rg/mod.rs and aim to be minimal while preserving existing explicit-file behavior (binary handling, display formatting).

Testing

  • Ran cargo fmt --check and cargo fmt to normalize formatting; check passed.
  • Ran cargo test -p bashkit builtins::rg::tests::diff_rg_matches_real_rg_cases and the suite passed.
  • Ran cargo test -p bashkit builtins::rg::tests::real_rg_binary_is_available_for_differential_tests and it passed.
  • Unit tests executed successfully for the modified code paths (no failures reported).

Codex Task

Copilot AI review requested due to automatic review settings June 5, 2026 19:50
@chaliy chaliy added the aardvark label Jun 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes rg metadata-based sorting (--sort / --sortr) so it applies consistently across all file candidates, including explicit file arguments and the --files explicit-path branch, matching ripgrep’s behavior more closely.

Changes:

  • Represent explicit file arguments as RgFileCandidate (with metadata) so they can be globally sorted together with recursively discovered files.
  • Add display_override + explicit to RgFileCandidate and centralize display formatting in candidate_display_path(...) to preserve explicit-path display semantics.
  • Add differential test cases covering metadata sorting across explicit file arguments and --files --sort modified with explicit files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 67638f3 Commit Preview URL Jun 05 2026, 08:28 PM

@chaliy
chaliy merged commit 5c49f51 into main Jun 5, 2026
36 checks passed
@chaliy
chaliy deleted the 2026-06-05-propose-fix-for-rg-metadata-sorting-issue branch June 5, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants