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

From version 0.3.0 onward (at least until version 1.0), some test failures are expected in bugfix versions as I like to use test-driven development to build out new features. Please only report test failures if the same test passed in the most recent 0.x.0 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.3.0.tar.gz (12.8 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.3.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: patch_fixer-0.3.0.tar.gz
  • Upload date:
  • Size: 12.8 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.3.0.tar.gz
Algorithm Hash digest
SHA256 54cff67d8c21c33c5e7970ea9422790c91a06ce7b52331c26db0b04b2d676d36
MD5 691bfe21c228c242c6c9515c88b06a45
BLAKE2b-256 5b80bb71a3ab59b7b90fa1f79a02973a710cbc0975ef04516849e9ab115bba3c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: patch_fixer-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94a8986ac23c948098e81f419c581dcf95a8949aa310a5dac508d7437c989b86
MD5 f8f66369cdf4c24e746eb1485d2558a2
BLAKE2b-256 1e4a949a89ee2a19923c75f2b9938adb399c8f6cbbfaf00725aad540d0b17cb8

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