Skip to content

Include file paths in --diff output to enable patch -p0 application#150

Draft
Copilot wants to merge 2 commits into
developfrom
copilot/format-diff-for-patch
Draft

Include file paths in --diff output to enable patch -p0 application#150
Copilot wants to merge 2 commits into
developfrom
copilot/format-diff-for-patch

Conversation

Copilot AI commented May 1, 2026

Copy link
Copy Markdown

--diff output lacked fromfile/tofile headers in the unified diff, making it unusable with patch.

Changes

  • print_diff: Added file_path: pathlib.Path parameter; passes a cwd-relative path (falling back to absolute) as both fromfile and tofile in difflib.unified_diff
  • apply_changes: Threads file_path through to print_diff

Result

--- tests/classes/kw_only_test.py
+++ tests/classes/kw_only_test.py
@@ -10,3 +10,11 @@
         """Initialize the class."""
         self.name = name  # pragma: no cover
         self.age = age  # pragma: no cover
+
+    def __repr__(self) -> str:
...

The output can now be applied directly:

crepr add tests/classes/*.py --diff > changes.patch
patch -p0 < changes.patch

@semanticdiff-com

semanticdiff-com Bot commented May 1, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crepr/crepr.py  61% smaller

Copilot AI changed the title [WIP] Format diff to enable application with patch command Include file paths in --diff output to enable patch -p0 application May 1, 2026
Copilot AI requested a review from cleder May 1, 2026 13:17
Copilot finished work on behalf of cleder May 1, 2026 13:17
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.

Format Diff to be able to be applied with patch -s -p0 < file.patch

2 participants