Skip to content

fix: --path globs, --branch with --path, and dropped oldest commit - #19

Merged
markhazleton merged 2 commits into
mainfrom
fix/path-glob
Nov 21, 2026
Merged

markhazleton merged 2 commits into
mainfrom
fix/path-glob

Conversation

@markhazleton

@markhazleton markhazleton commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two bugs in the --path filter.

1. Globs were rejected. --path "src/**" failed with Path pattern is not a valid regex pattern. validateOptions checked the value as a regular expression, but the collector passes it to git log -- <path> as a Git pathspec, where ** is a valid glob. It's never compiled or run as a regex, so the regex syntax and ReDoS checks guarded against nothing.

  • Fix: validate the path as a pathspec by reusing the existing validatePathString (disallowed shell/regex characters, directory traversal, //), keeping the 500-character limit.

2. --branch was ignored when --path was set. The collector pushed the branch after --, so Git read it as a second pathspec and analyzed the current branch.

  • Fix: put the revision before --.

Tests

  • validation.test.ts: the two regex-era tests are replaced by pathspec tests. Globs (src/**, src/core/*.ts, *.md, src/?ore) are accepted; disallowed characters, traversal, and over-long patterns are rejected; old regex-style inputs are still rejected (now as disallowed characters).
  • collector-regression.test.ts: end-to-end on a temp repo. A dir/** glob keeps only the commits under dir/, and branch + path analyzes the requested branch.
  • Against the original code, 5 of the new and updated tests fail. With the fix, the full suite passes: 344 tests; coverage 80.14% branches, 96.19% functions, 94.78% lines.
  • Manual check: git-spark html --since 2026-07-01 --until 2026-09-30 --path "src/core/**" now succeeds and matches --path src/core.

3. Oldest commit dropped (second commit)

With any range or path filter, the collector could return one commit fewer than git log. Git prints the oldest commit last, and the stream-close handler took the first newline as the end of that record's header. When the oldest commit's message had a multi-line body, the header looked like it had too few fields and the commit was silently skipped.

  • Fix: one processRecord helper parses every record, ending the header at the first newline after the 7th field separator, both while streaming and at close.
  • The existing regression test already had a multi-line-body oldest commit but only asserted >= 2 of 3 commits, which hid the bug. It now asserts all 3, and a new test checks that commit's body and files. Both fail on the old code.
  • On this repo the collector now matches git log --no-merges exactly: unfiltered 221/221, src 61/61 (was 60), v1.2.0 + src/** 46/46 (was 45), test 50/50, docs 55/55.

All 345 tests pass.

🤖 Generated with Claude Code

markhazleton and others added 2 commits November 21, 2026 10:31
--path is passed to `git log -- <path>` as a Git pathspec, but
validateOptions checked it as a regular expression, so globs like
`src/**` were rejected. Validate it as a pathspec instead, reusing
validatePathString (disallowed characters, traversal, length).

The collector also put the branch after `--`, where git reads it as a
second pathspec, so --branch was silently ignored whenever --path was
set. The revision now comes before `--`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
git log emits the oldest commit last, and that record was parsed by
the stream close handler, which treated the first newline as the end of
the header. A multi-line commit body therefore looked like a header
with too few fields, and the commit was silently dropped, so any range
whose oldest commit had a detailed message lost one commit.

Parse every record with one helper that ends the header at the first
newline after the 7th field separator, both while streaming and at
close. The regression test now asserts all 3 commits instead of >= 2,
which had hidden the bug.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@markhazleton markhazleton changed the title fix(cli): accept glob patterns in --path and honor --branch with --path fix: --path globs, --branch with --path, and dropped oldest commit Nov 21, 2026
@markhazleton
markhazleton merged commit 6ec37fa into main Nov 21, 2026
11 checks passed
@markhazleton
markhazleton deleted the fix/path-glob branch November 21, 2026 18:36
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