Skip to main content

Fixes erroneous git apply patches to the best of its ability.

Project description

patch-fixer

So you asked an LLM to generate a code diff, tried to apply it with git apply, and got a bunch of malformed patch errors? Well fear no more, patch_fixer.py is here to save the day... more or less.

Installation

# Make sure you're using at least python 3.10
python -m venv .venv/
source .venv/bin/activate
pip install patch-fixer

Usage

API:

>>> from patch_fixer import fix_patch
>>>
>>> patch_file = "/path/to/broken.patch"
>>> original = "/path/to/original/state"    # file or directory being patched
>>> with open(patch_file, encoding="utf-8") as f:
...     patch_lines = f.readlines()
...     
>>> fixed_lines = fix_patch(patch_lines, original)
>>> output_file = "/path/to/fixed.patch"
>>>
>>> with open(output_file, 'w', encoding='utf-8') as f:
...     f.writelines(fixed_lines)
>>>

Command line:

python patch_fixer/patch_fixer.py original broken.patch fixed.patch

where original is the file or directory you were trying to patch, broken.patch is the malformed patch generated by the LLM, and fixed.patch is the output file containing the (hopefully) fixed patch.

Local Testing

git clone https://github.com/ajcm474/patch-fixer.git
cd patch-fixer
pip install -e .[test]
pytest

Note that some test failures are expected as this project is in the early alpha stage. Please only report test failures if the same test passed in a previous version.

License

This is free and open source software, released under the Apache 2.0 License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

patch_fixer-0.2.3.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

patch_fixer-0.2.3-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file patch_fixer-0.2.3.tar.gz.

File metadata

  • Download URL: patch_fixer-0.2.3.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for patch_fixer-0.2.3.tar.gz
Algorithm Hash digest
SHA256 15d27408ff12a080a2607c71b500c9e8679102a7dad5bf29ce4d0e19f0d796e5
MD5 e7f472fc54f3d9a47622e86a75b56149
BLAKE2b-256 0f7dde9ebe1c6f3a3f051b7ade2612aefc584f0bb9911a89dc939e2b77816cfd

See more details on using hashes here.

File details

Details for the file patch_fixer-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: patch_fixer-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for patch_fixer-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 defc3e2ecf2a709ae8f2288b95cc0cc710c861a67d7ae0c1fee1283f5550cfe1
MD5 ade8e059edf024a2f00c9f1f1cf547ae
BLAKE2b-256 71eb6a576261c45cb606aa23a04cb99e5d9f1cca09296667c694a0325f00b889

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page