Community
    • Login

    Applying Diff patches?

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 4 Posters 115 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pbarneyP
      pbarney
      last edited by

      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.

      PeterJonesP Mark OlsonM EkopalypseE 3 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @pbarney
        last edited by PeterJones

        @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 work

        cd "$(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.

        1 Reply Last reply Reply Quote 5
        • Mark OlsonM
          Mark Olson @pbarney
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse @pbarney
            last edited by

            @pbarney

            Using PS3 and an installed pygit2 library
            you can do something like

            import 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
            1 Reply Last reply Reply Quote 2
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors