Skip to content

fix(git): fix --reverse showing newest commits instead of oldest#1302

Open
NEOFIT-dev wants to merge 1 commit intortk-ai:developfrom
NEOFIT-dev:fix/git-log-reverse-oldest-first
Open

fix(git): fix --reverse showing newest commits instead of oldest#1302
NEOFIT-dev wants to merge 1 commit intortk-ai:developfrom
NEOFIT-dev:fix/git-log-reverse-oldest-first

Conversation

@NEOFIT-dev
Copy link
Copy Markdown

@NEOFIT-dev NEOFIT-dev commented Apr 14, 2026

Summary

  • RTK was injecting -50 into git before --reverse, so git log -50 --reverse picked the 50 most-recent commits then reversed them — users saw 2025 data instead of historical commits from 2022
  • Fix: skip default -N injection when --reverse is present; git streams all commits oldest-first and RTK caps output at the normal limit (50 with --format, 10 plain) → user gets the N oldest commits
  • Add stderr warning when output is truncated so users know to pass -N

Closes #1296

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • test_build_log_command_reverse_does_not_inject_n — regression guard at the actual bug site
  • test_build_log_command_reverse_with_explicit_n_respects_user_limit-n 200, --max-count=200 workarounds from the issue
  • test_reverse_truncation_warning_multiline_commits — warning counts commits not lines
  • test_reverse_token_savings_plain_fixture — ≥60% savings on real fixture
  • Manual: rtk git log --reverse in a repo with 100+ commits shows oldest commits first

RTK was injecting -50 into git before --reverse, causing `git log -50 --reverse`
to pick the 50 most-recent commits then reverse them. Users saw 2025 data instead
of historical commits from 2022.

Fix: extract build_log_command() so the -N injection decision is testable.
When --reverse is present without an explicit -N, RTK skips the default -N
injection entirely. Git streams all commits oldest-first; RTK caps output at
the normal limit (50 with --format, 10 plain) so the user gets the N oldest
commits. A stderr warning fires when the output is truncated.

Tests:
- build_log_command: verify -N is not injected for --reverse (regression guard
  at the actual bug site, not just the post-processor)
- build_log_command: --reverse + explicit -N respects user limit
- build_log_command: without --reverse, default -N injection still works
- warning path: truncation fires when raw_count > limit, silent otherwise
- token savings: ≥60% verified against a real git log --reverse fixture

Closes rtk-ai#1296
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.

1 participant