Applying Diff patches?
-
Does anyone know if NPP has the ability to apply diff patches to code? I didn’t see anything in the Plugins Admin, nor in the docs.
I’d be interested to know if anyone has attempted a homebrew solution using NppExec or Pythonscript as well.
-
@pbarney ,
If you have git, the
git apply
can apply patches even when the target isn’t under git control (according to my web search results, anyway; I’ve never tried it myself). So putting the patch file in the right directory, and using the NppExec to just run something like the following should workcd "$(CURRENT_DIRECTORY)" git apply "$(FILE_NAME)"
Alternately, I would say the most natural plugin for that feature to exist in would be the ComparePlus plugin. Unfortunately, the request for generating patchfiles has been un-implemented since 2019, so a new FR to also be able to apply a patch would likely not be implemented anytime soon.
update: who knows if it will do any good, but I commented on that Issue to request that apply patch be considered alongside create patch.
-
This post is deleted! -
Using PS3 and an installed pygit2 library
you can do something likeimport pygit2 repo = pygit2.Repository(Path(notepad.getCurrentFilename()).parent) diff = pygit2.Diff.parse_diff(editor.getText()) repo.apply(diff)
This assumes that
- the patch file has been created from a git tool
- the current file open is the patch file in question
- the patch file is in the repo directory