pygit2
pygit2 copied to clipboard
[question] How to apply a patch in a cloned repository
Hi!
I would like to apply a regular patch file, but without a git repo. Is it possible using this project? For instance:
$ cd myproject/
$ patch < 0001-regular-fix.patch
I found two methods, but I'm not sure if they are what I want:
pygit2.Patch.create_from
pygit2.Diff.parse_diff
Actually I didn't find some easy to apply them. My idea was something like:
def apply_patch(working_folder, patch_file):
with open(patch_file, 'rb') as fd:
patch_content = fd.read()
diff = pygit2.Diff.parse_diff(patch_content)
repo = pygit2.init_repository(working_folder, bare=True)
repo.apply(diff)
Regards!