Skip to content

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

Closed
NEOFIT-dev wants to merge 1 commit into
rtk-ai:developfrom
NEOFIT-dev:fix/git-log-reverse-oldest-first
Closed

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

Conversation

@NEOFIT-dev

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

Copy link
Copy Markdown

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
@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

@rtk-release-bot rtk-release-bot Bot closed this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk git log silently truncates output to 50 commits, ignoring --reverse and losing historical data

1 participant