fix(git): empty `git log` range emits a blank line instead of empty output — breaks `| wc -l` counting

Open
#3,365 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
git, rust
Domain
cli

Research direction

Start by reproducing rtk git log --oneline HEAD..HEAD and rtk proxy git log --oneline HEAD..HEAD, comparing their byte output with raw git. Trace the git log filtering entry point and add coverage for an empty range while preserving the existing non-empty behavior. Done means the empty range emits 0 bytes, so | wc -l reports 0.

Written by the indexing model from the issue text.

Description

area:cli bug good first issue priority:high

Summary

When a git log range contains zero commits, rtk's filter emits a single blank line (\n, 1 byte) where raw git emits nothing (0 bytes). Any consumer that counts lines — the classic | wc -l — reads 1 instead of 0.

Minimal repro

$ rtk git log --oneline HEAD..HEAD | od -c
0000000   \n
0000001

$ rtk proxy git log --oneline HEAD..HEAD | od -c
$            # empty, as raw git

Non-empty ranges are filtered correctly.

Why it matters for rtk's audience

rtk's primary users are LLM coding agents, and git log <upstream>..HEAD | wc -l is the idiomatic "how many unpushed commits" check they emit constantly. Under the hook, a compound command starting with a rewritten command (e.g. git push … ; git log … | wc -l) goes through the filter and the agent concludes "1 unpushed commit" on a fully pushed branch — then wastes turns re-pushing or investigating phantom state. That's how we found it.

Workarounds we use meanwhile: git rev-list --count <range> (emits a number, not lines) or rtk proxy git log ….

Environment

  • rtk 0.42.3 (Homebrew), macOS (Darwin 27.0.0)
  • Changelog through v0.44.1 shows no related fix, and no existing issue matches (closest: #2305, #3028 — commit-dropping in non-empty logs, different defect).

Expected

Empty range in → empty output out (0 bytes), matching raw git.

Dominant language
Rust
Stars
81.1k
Forks
5.1k
Avg merge
4d 11h
Merged PRs (30d)
40

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rtk-ai/rtk

All issues in rtk-ai/rtk

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.