conan-io / python-patch-ng

Library to parse and apply unified diffs
https://pypi.org/project/patch-ng
Other
19 stars 8 forks source link

Offsetted (relatively to sources) patches apply to wrong lines #21

Open KOLANICH opened 2 years ago

KOLANICH commented 2 years ago

patch -p 1 < patchFile.patch (GNU patch) works fine.

def applyPatch(fileText: str, patchFile: Path):
    with patchFile.open("rb") as psf:
        ps = patch.PatchSet(psf)
        ps.parse(psf)

    p = ps.items[0]

    with BytesIO(fileText.encode("utf-8")) as sF:
        return b"".join(ps.patch_stream(sF, p.hunks)).decode("utf-8")

produces the wrong results.

uilianries commented 3 months ago

Hello @KOLANICH ! Sorry the big delay! Could you please elaborate a bit more your case? Is it possible to provide a reproducible example? Please, take a look in the issue #19 as reference, that's good way to reproduce the case. Regards.