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 existed and 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.1.tar.gz (14.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.3.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: patch_fixer-0.3.1.tar.gz
  • Upload date:
  • Size: 14.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.3.1.tar.gz
Algorithm Hash digest
SHA256 c35a2f26357f5efba01a4026c65908bca7e54f60c122afaa5405414f9e1deea2
MD5 aa914003a3fba96415667aa697e972b0
BLAKE2b-256 2170fd51fe7819bc8dc9413368ee724619b16f559fedcd7acb3ab7714f2dbd83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: patch_fixer-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c312072c0b83ec0dacb40a2dab63088751ad91ce28314cc8d0f64ddadac6b5ff
MD5 735638164a939178163e6f72b5244d91
BLAKE2b-256 c31305ea39ad18020ef247ebc49f33e516319005349e680442f39ab67e3033fa

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