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.2.tar.gz (18.0 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.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: patch_fixer-0.3.2.tar.gz
  • Upload date:
  • Size: 18.0 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.2.tar.gz
Algorithm Hash digest
SHA256 26e0c7d6ba954c7deb10c7ffe1893ee99a3ea5beebf3fa8ea3b5998815dcc859
MD5 c118dd73d4cdd101215d780dc21991c9
BLAKE2b-256 36338e6447d0364368d778985c1f2a7cd9798a3a5cdce52e86fd8ee504ff7447

See more details on using hashes here.

File details

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

File metadata

  • Download URL: patch_fixer-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4cbb1abecc3e3d776558dfe37cb2372a54c7d80ca36bd0c604eabf4c5022c6ef
MD5 e940ffaafbbb4868fd7784037e9b8dee
BLAKE2b-256 d0efbc02364218c20c48d3ea54981fb7021fa9f83dbb945a4c9a7a8039593b8c

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