conan-io / python-patch-ng

Library to parse and apply unified diffs

Home Page:https://pypi.org/project/patch-ng

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Offsetted (relatively to sources) patches apply to wrong lines

KOLANICH opened this issue · comments

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.