Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sync with GitHub repo. #43

Open
DavidBerdik opened this issue Apr 5, 2022 · 6 comments
Open

Support for sync with GitHub repo. #43

DavidBerdik opened this issue Apr 5, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@DavidBerdik
Copy link

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.

@moritzgloeckl
Copy link
Owner

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 moritzgloeckl added the enhancement New feature or request label Apr 5, 2022
@DavidBerdik
Copy link
Author

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!

@thevinter
Copy link

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 :)

@DavidBerdik
Copy link
Author

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.

@thevinter
Copy link

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)

@DavidBerdik
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants