Maintaining custom patches on third party code

2019-01-15 21:21发布

I'm building a web application that uses a third party JavaScript library (TinyMCE).

My application has some specific needs which require me to patch the library in a few places. The patches are easy (less than a dozen lines), but since they are specific to our use case and not bugs.

I'd like to be able to update when new versions of the library itself are released, which would overwrite our changes in our Git repository.

I need a way to ensure our patches are always applied before pushing the updated library to a production server. Since the changes are very small, it wouldn't be an issue to apply them manually.

How can I ensure my patches to third party code are applied in our repository when updating the third party code?

2条回答
来,给爷笑一个
2楼-- · 2019-01-15 21:47

If you storing TinyMCE in a Git repo, then you could use a Git post-commit-hook to perform the patches after you get a new version of TinyMCE (then commit those patches).

The workflow would be something like:

[get new version of TinyMCE]
["git commit -a" to update all tracked files]
[post-commit-hook patches TinyMCE]
["git commit -a" to pick up all of the changes from the patches]
查看更多
家丑人穷心不美
3楼-- · 2019-01-15 21:51

Create a repository for tracking the third-party code, and put your patches in a separate branch. When you need the latest release fetch the changes and rebase your branch.

For example:

$ git clone --origin github https://github.com/tinymce/tinymce.git
$ cd tinymce/
$ git remote add origin git@myrepo.example.org:tinymce

Then make your patches and push to your repository:

$ git commit -m "my patches to tinymce"
$ git push --set-upstream origin master

At this point your repository looks like this:

(0) --- (1) --- ... (n) --- (X)
                             |
                           master

Where X is your patch.

Now set a branch to fetch new revisions from the github remote:

$ git branch tinymce_import github/master
$ git checkout tinymce_import
$ git pull --ff-only

So your repository becomes like this (git branch is smart enough to use as the origin the last revision in the github remote):

                           master
                             |
                     +----- (X)
                     |
(0) --- (1) --- ... (n) --- (n+1) --- ... (n+m)
                                            |
                                      tinymce_import

At last rebase your master branch on tinymce_import:

$ git checkout master
$ git rebase tinymce_import

                                                  master
                                                    |
                                            +----- (X)
                                            |
(0) --- (1) --- ... (n) --- (n+1) --- ... (n+m)
                                            |
                                      tinymce_import
查看更多
登录 后发表回答