jupyterhub / nbgitpuller

Jupyter server extension to sync a git repository one-way to a local path
https://nbgitpuller.readthedocs.io
BSD 3-Clause "New" or "Revised" License
205 stars 84 forks source link

Deal with modify/delete conflicts #269

Closed jdmansour closed 2 years ago

jdmansour commented 2 years ago

This pull request deals with the case where you have diverged branches - you delete a file remotely, and edit the same file locally, or vice versa. If the local change was committed previously, the sync will fail with CONFLICT (modify/delete). See also https://github.com/jupyterhub/nbgitpuller/issues/265.

puller: $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller merge -Xours origin/master
puller: CONFLICT (modify/delete): README.md deleted in origin/master and modified in HEAD. Version HEAD of README.md left in tree.
puller: Automatic merge failed; fix conflicts and then commit the result.

What this does is, it checks for that error, and resolves it via commit -a (keeping all the local changes). This should be in line with the sync policy. We have tested this for about a week in production and so far it seems to work well.

Please let me know if I'm adding too many tests :-) I think maybe I could squash some together if it is getting too much.

yuvipanda commented 2 years ago

@jdmansour omg no such thing as too many tests! thank you so much for this, and apologies it took a while for me to get to it.

I've pushed a change that stops using Exceptions for flow control, but otherwise this Looks Great to me. I'll leave this open for a day or two to see if you (or others) have objections to my changes, but if not I'll merge!

jdmansour commented 2 years ago

@yuvipanda No problem, and thanks for getting back to this! Your change looks good, the original code was trying to be a bit too clever with the exception.

yuvipanda commented 2 years ago

Thanks a lot, @jdmansour!