Community
    • Login

    Applying Diff patches?

    Scheduled Pinned Locked Moved General Discussion
    5 Posts 4 Posters 2.3k Views 2 Watching
    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 Offline
      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 Online
        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.

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

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • EkopalypseE Offline
            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
            • PeterJonesP Online
              PeterJones @PeterJones
              last edited by

              @PeterJones said in Applying Diff patches?:

              I commented on that Issue to request that apply patch be considered alongside create patch.

              as mentioned here, as of ComparePlus v2.0.0, the plugin can generate and apply standard patch files; see also the release notes. Thanks to @pnedev for the update.

              (Until it makes it into the Plugins Admin, the new version can be manually installed from the zipfiles found on the v2.0.0 release page)

              1 Reply Last reply Reply Quote 2

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors