Skip to content

fix: normalize rename-only diff paths#194

Merged
benvinegar merged 1 commit into
mainfrom
fix/normalize-rename-only-paths
Apr 11, 2026
Merged

fix: normalize rename-only diff paths#194
benvinegar merged 1 commit into
mainfrom
fix/normalize-rename-only-paths

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Summary

  • strip parser-added trailing newlines from parsed diff paths
  • normalize rename-only labels in loaders, file labels, and the OpenTUI diff adapter
  • add regression coverage for cross-directory pure renames

Problem

@pierre/diffs can return prevName with a trailing newline for pure rename patches. That made Hunk render rename-only headers inconsistently, including cases where the old path and -> new/path appeared on separate lines instead of one old/path -> new/path header.

Testing

  • bun run typecheck
  • bun test
  • bun run test:tty-smoke

This PR description was generated by Pi using OpenAI GPT-5

@greptile-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a rendering bug where @pierre/diffs returns prevName with a trailing newline for pure rename patches, causing the old path and -> new/path to appear on separate header lines. The fix centralizes path sanitization in a new diffPaths.ts helper and applies it consistently at the loader, OpenTUI adapter, and UI helper layers, with targeted regression coverage.

Confidence Score: 5/5

Safe to merge — targeted bug fix with no logic regressions and good test coverage at both integration and unit levels.

All findings are P2 or lower. Normalization is applied at the right layers (source in the loader, defensively in UI helpers and the OpenTUI adapter). The early-return optimization in normalizeDiffMetadataPaths is correct. Regression coverage covers both the end-to-end loader path and the standalone UI helper path.

No files require special attention.

Important Files Changed

Filename Overview
src/core/diffPaths.ts New helper module introducing normalizeDiffPath and normalizeDiffMetadataPaths; clean implementation with efficient early-return when no normalization is needed.
src/core/loaders.ts Applies normalizeDiffMetadataPaths in buildDiffFile and normalizeDiffPath in findPatchChunk and resolvedPreviousPath; normalization is now at the source so all downstream consumers receive clean paths.
src/core/loaders.test.ts Adds an integration regression test for a cross-directory pure rename patch verifying that both path and previousPath are free of trailing newlines end-to-end.
src/opentui/HunkDiffView.tsx Adds normalization in toInternalDiffFile so the public OpenTUI component adapter also strips trailing newlines from paths received from external callers.
src/ui/lib/files.ts Adds defensive normalizeDiffPath calls in sidebarFileName, fileLabelParts, filterReviewFiles, and buildSidebarEntries to handle any DiffFile objects that arrive with non-normalized paths.
src/ui/lib/files.test.ts Adds unit test for fileLabelParts with a raw \n-suffixed previousPath, directly exercising the defensive normalization in the UI helpers.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["@pierre/diffs parsePatchFiles()\nreturns prevName with \\n"] --> B["loaders.ts buildDiffFile()\nnormalizeDiffMetadataPaths()"]
    B --> C["DiffFile.path / previousPath\n(clean, no trailing newlines)"]
    C --> D["files.ts UI helpers\nsidebarFileName / fileLabelParts\n(defensive normalizeDiffPath)"]
    C --> E["App renders correct\nold/path -> new/path header"]
    F["HunkDiffView.tsx (OpenTUI)\nExternal diff input"] --> G["toInternalDiffFile()\nnormalizeDiffMetadataPaths()\nnormalizeDiffPath()"]
    G --> C
    H["findPatchChunk()\npath matching"] --> I["normalizeDiffPath on candidates\nbefore chunk lookup"]
Loading

Reviews (1): Last reviewed commit: "fix: normalize rename-only diff paths" | Re-trigger Greptile

@benvinegar
benvinegar merged commit 1c2686e into main Apr 11, 2026
3 checks passed
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