Skip to content

fix(collector): record real file paths and Git's own change status - #22

Merged
markhazleton merged 1 commit into
mainfrom
001-work-ps-001-accurate-file
Nov 22, 2026
Merged

markhazleton merged 1 commit into
mainfrom
001-work-ps-001-accurate-file

Conversation

@markhazleton

Copy link
Copy Markdown
Owner

Summary

Every file change in a report now names the real file and the status Git reports.

  • Renames: git log --numstat abbreviates renames that share part of a path as dir/{old => new}/file. The collector split that on =>, recording paths like new}/file and old paths like dir/{old. In this repository 110 of 134 renames were affected, skewing hotspots, file counts, file types, and file ownership.
  • Status: status was guessed from line counts, so an append-only edit was reported as added and a removal-only edit as deleted.

Approach

  • Add --raw to the same single git log call. Git emits raw entries (status letter plus full old/new paths) in the same order as numstat entries, so the two are paired by position: status and paths from raw, line counts from numstat.
  • If the counts ever differ, keep the numstat entries with brace-form rename expansion and record a collector warning (never seen on this repository's full history).
  • Pass -c core.quotePath=false, decode Git's C-quoted paths, and decode stdout as a UTF-8 stream so non-ASCII filenames keep their real names even when a character spans two chunks.
  • Path helpers live in a new internal module, src/core/git-paths.ts, so they are not added to the public API via export *.
  • FileChange keeps its shape; only its values become correct. Spawn arguments remain a fixed array.

Out of scope: --follow and merging a renamed file's history with its old path.

Verification

  • New test/file-change-records.test.ts against a real Git repo: added non-ASCII filename, append-only edit (modified), brace-form rename (full path/oldPath), delete, no braces or arrows in any path, plus unit tests for rename expansion and path unquoting. 4 of its tests fail on the previous collector.
  • Full suite: 26 suites, 364 tests pass; coverage 80.77% branches, 95.55% lines.
  • Lint, type-check (TypeScript 7), build pass; changed files are Prettier-clean.
  • This repository's full history (228 commits, 2,777 file changes): 0 paths containing {, } or =>; all 134 renames carry full paths; 0 fallback warnings.

Release note

Status counts in reports shift (appends are now modified). JSON values change, not the schema; choose patch or minor at release. CHANGELOG [Unreleased] has the entries.

Roadmap: ps-001 (accurate per-file change records).

🤖 Generated with Claude Code

git log --numstat abbreviates renames as dir/{old => new}/file, and the
collector split that on ' => ', recording corrupted paths for 110 of this
repository's 134 renames. Status was also guessed from line counts, so an
append-only edit was reported as an added file.

Add --raw to the same git log call and pair its entries (status letter
plus full old/new paths) with numstat line counts, which Git emits in the
same order. On a count mismatch, fall back to numstat with brace
expansion and record a warning. Pass core.quotePath=false and decode the
stream as UTF-8 so non-ASCII filenames keep their real names.

Refs ps-001.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@markhazleton
markhazleton merged commit 52bef7f into main Nov 22, 2026
11 checks passed
@markhazleton
markhazleton deleted the 001-work-ps-001-accurate-file branch November 22, 2026 06:15
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