|
1 | 1 | # GitHub Sync Service |
2 | 2 |
|
3 | | -Overleaf Github Sync Service, @Ayaka-notes. |
| 3 | +Overleaf Github Sync Service, @Ayaka-notes. |
| 4 | + |
| 5 | +## Service Overview |
| 6 | +This service is only responsible for 2 things: |
| 7 | +- export existing Overleaf projects to GitHub repositories |
| 8 | +- export existing overleaf changes and merge changes from GitHub repositories to Overleaf projects |
| 9 | + |
| 10 | +## How we do sync bewtween Overleaf and GitHub |
| 11 | +We use `sync point` to track the last synced commit in GitHub and the last synced version in Overleaf, which is stored in the mongodb. A `sync point` means a version in overleaf and a commit in github, they are totally the same content. |
| 12 | + |
| 13 | +When we do sync, we will first check the last overleaf version and current overleaf version, if they are different, we will export the changes from overleaf to github, **as a branch**, we call it `overleaf branch` in the later. |
| 14 | + |
| 15 | +Then we will try to merge this branch to the default branch. However, in GitHub, there are 2 kinds of merge: |
| 16 | +- fast forward merge: if there is no new commit in the default branch, we can directly merge the branch to the default branch, and update the sync point. |
| 17 | +- normal merge: if there are new commits in the default branch, we need to create a merge commit to merge the branch to the default branch, and update the sync point. |
| 18 | + |
| 19 | +Now we have the new commits in the default branch (called newSha in the code), we will try to merge the new commits to overleaf. |
| 20 | + |
| 21 | +Since GitHub stored all the files in the repository, we can get the changed files between the last synced commit and the new commit, we only return changes files with URLs, then web service will download the changed files and update the overleaf project. |
| 22 | + |
| 23 | +## What if there are conflicts? |
| 24 | +If there are conflicts, we will not merge the branch to the default branch, and we will return error to the web service, then web service will get sync status and show the conflict to the user, and ask the user to resolve the conflict in GitHub. |
| 25 | + |
| 26 | +If user merge that conflict branch to the default branch, then we will update the sync point and merge the changes to overleaf. |
| 27 | + |
| 28 | +> How we detect if a branch is merged to the default branch? |
| 29 | +> |
| 30 | +> We will use GitHub API to diff the default branch and the `overleaf branch`, if the default falls behind the branch, it means the branch is not merged, if the default branch is ahead of the branch, it means the branch is merged. |
| 31 | +> |
| 32 | +> In a corner case, if the overleaf branch is merged but deleted, we will use the latest commit in the default branch as the new sync point, and merge the changes to overleaf. |
| 33 | +
|
| 34 | + |
| 35 | +## Copyright |
| 36 | +Copyright (C) 2026 Ayaka-notes. |
0 commit comments