Metadata-Version: 2.4
Name: patch-fixer
Version: 0.3.0
Summary: Fixes erroneous git apply patches to the best of its ability.
Maintainer-email: Alex Mueller <amueller474@gmail.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/ajcm474/patch-fixer
Project-URL: Issues, https://github.com/ajcm474/patch-fixer/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: GitPython
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: requests; extra == "test"
Dynamic: license-file

# 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
```bash
# Make sure you're using at least python 3.10
python -m venv .venv/
source .venv/bin/activate
pip install patch-fixer
```

## Usage
### API:
```python
>>> 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:
```bash
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
```bash
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.
