overleaf-sync icon indicating copy to clipboard operation
overleaf-sync copied to clipboard

Support for sync with GitHub repo.

Open DavidBerdik opened this issue 3 years ago • 6 comments

Thanks for making this really cool project!

I was wondering if the developer would be interested in adding support for syncing between Overleaf and a GitHub repo? This would be really useful. Overleaf technically already has support for this, but it is behind a paywall.

DavidBerdik avatar Apr 05 '22 03:04 DavidBerdik

Hi!

Interesting idea, how would you like this to work? Git is pretty complicated and feature-rich itself, so I'm not sure if this is within the scope of this project. How about you map this project inside a script and execute the git commands yourself?

moritzgloeckl avatar Apr 05 '22 17:04 moritzgloeckl

Interesting idea, how would you like this to work?

Thanks! Ideally, it would be nice to have a way to allow for a Git repository and an Overleaf project to be kept in sync so that when changes are made to the Git repository's master branch, the changes are added to the Overleaf project, and when changes are made to an Overleaf project, the changes are committed and pushed to the Git repo as well.

Some problems that come to mind with trying to do this:

  1. Keeping Overleaf and Git in sync would require actively watching for changes to both platforms. This is trivial to achieve by setting a cron job to run once every minute, but perhaps there is value in building this monitoring directly in to the application?
  2. How would merge conflicts be handled?
  3. Even if no merge conflicts are present, how would we handle merging changes from Overleaf and Git at the same time without overwriting each other?
  4. Even if issues 2 and 3 are solved, how would we handle syncing changes to the Git repository? When the Overleaf document is actively being edited, we probably don't want to keeping making new commits once every minute, as that would be quite messy. We also probably don't want to commit changes straight to master either.

The only solution I can think of is to sync Overleaf changes to Git by making new commits once every minute to a temporary branch with a name like pending_changes or something like that. The idea would be that this branch will hold changes made to the Overleaf document while it is actively being edited. If the branch does not exist, it would be created from the current head of master, and if it exists, the timestamp of the last commit to it would be checked once every minute as well. After a defined period of time passes (let's say 1 hour), all of the commits made to pending_changes would be squashed to a single commit, and if no merge conflicts are present, the branch would be merged and deleted automatically. If merge conflicts are present, the merge would not be automatically performed, and if we want to be GitHub-specific, an automated PR could be generated to allow for the conflict to be resolved. As far as syncing Git changes to Overleaf is concerned, I would suggest keeping Overleaf in sync with the state of the pending_changes branch if it exists, and if it doesn't exist, keep it in sync with master. Obviously, this means that a delay would be introduced to Overleaf picking up the changes made in the Git repo, but it would at least allow for Git to be used for managing the merge process. I am aware that even this solution has flaws, but I think it's a step in the right direction?

Git is pretty complicated and feature-rich itself, so I'm not sure if this is within the scope of this project. How about you map this project inside a script and execute the git commands yourself?

I wasn't sure if it was within the scope of this project either, but I figured it wouldn't hurt to share the idea with you in case you thought it has value. If you decide that it is indeed outside the scope of this project, I may end up doing just that!

DavidBerdik avatar Apr 06 '22 00:04 DavidBerdik

Hello! You can use a pre-commit hook to automate it one way.

Create .git/hooks/pre-commit with

#!bin/sh 
osl sync
git add -A
git commit -m "Remote changes from Overleaf"

This will allow you to get the remote changes and add them to your next commit.

Sadly syncing from overleaf to github dynamically doesn't seem feasible to me unless you do it with cron :)

thevinter avatar Apr 17 '22 11:04 thevinter

Hello! Wouldn't using a pre-commit hook run the risk of overwriting data in the case of merge conflicts though?

Also, syncing using cron came to my mind as well. Either that or have the program check for updates on a separate thread.

DavidBerdik avatar Apr 17 '22 19:04 DavidBerdik

The pre-commit hook doesn't force anything so in case of conflicts it should just fail allowing you to mana the merge

(As far as I'm aware)

thevinter avatar Apr 22 '22 22:04 thevinter

@thevinter Good! Although ideally I would like to have an automated solution for syncing that wouldn't break in the case of a merge conflict, which I think means that this wouldn't work. Thoughts?

DavidBerdik avatar Apr 24 '22 05:04 DavidBerdik