Add auto-commit, push & pull features for Git - #16651
Conversation
PR Summary by QodoAdd per-library Git auto commit/push/pull and new Git preferences tab
AI Description
Diagram
High-Level Assessment
Files changed (30)
|
Code Review by Qodo
1. GitPullScheduler catches Exception
|
| try { | ||
| if (bibDatabaseContext.getMetaData().isGitAutoPull()) { | ||
| bibDatabaseContext.getDatabasePath().ifPresent(path -> gitAutoSync.pull(path, bibDatabaseContext)); | ||
| } |
There was a problem hiding this comment.
7. Auto-pull ignores unsaved edits 🐞 Bug ☼ Reliability
GitPullScheduler can trigger GitAutoSync.pull based only on metadata and Git working-tree status, without checking whether the JabRef library has unsaved in-memory changes. This allows a scheduled pull to apply merge changes into the live BibDatabaseContext and write to disk while the user is editing, risking overwriting/confusing local unsaved work.
Agent Prompt
### Issue description
Scheduled auto-pull currently runs whenever `metaData.isGitAutoPull()` is true and the Git working tree is clean. It does **not** check JabRef’s “dirty” state (unsaved edits tracked via the undo manager / changed flag), so merges can be applied to the in-memory model (and written to disk) during active editing.
### Issue Context
- `GitPullScheduler.pull(...)` only checks `metaData.isGitAutoPull()`.
- `GitAutoSync.preparePull(...)` only checks `GitStatusSnapshot.uncommittedChanges()`.
- JabRef tracks unsaved edits via the LibraryTab undo manager (`undoManager.hasChanged()`), which is independent from Git’s working tree status.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/git/GitPullScheduler.java[48-55]
- jabgui/src/main/java/org/jabref/gui/git/GitAutoSync.java[128-155]
- jabgui/src/main/java/org/jabref/gui/LibraryTab.java[595-601]
### Suggested change
- Add an additional guard to scheduled pulls: skip if the associated LibraryTab has unsaved changes (e.g., `undoManager.hasChanged()` / tab changed property) or if the tab is currently saving.
- A clean way is to extend `GitPullScheduler.start(...)` to accept a `BooleanSupplier isSafeToPull` captured from the owning `LibraryTab`, so the scheduler can query the correct dirty/saving state per library before invoking `gitAutoSync.pull(...)`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Yeah, this already fixed
…to git-integration-slr
|
Hi Loay, any changes pending here you wish to do? or rfr? |
All good, it is ready for review, i think i addressed all the previous reviews and i comments on ones that was need for decision |
|
|
||
| public SaveResult save(SaveDatabaseMode mode) { | ||
| return save(libraryTab.getBibDatabaseContext(), mode); | ||
| return save(mode, AutoCommit.ENABLED); |
There was a problem hiding this comment.
Qn: why are we passing ENABLED here always?
There was a problem hiding this comment.
it iss the default for the existing signature, so callers that do not care keep the previous behaviour.
also the two that do care pass explicitly like GitCommitAction uses DISABLED so the commit action's own save doesnot commit twice, and AutosaveUiManager uses DISABLED for the autosave case koppor raised above
subhramit
left a comment
There was a problem hiding this comment.
Needs one final review.
All the requirements discussed seem to have been satisfied.
|
|
||
| public static final String GIT_AUTO_PULL = "gitAutoPull"; | ||
| public static final String GIT_AUTO_COMMIT = "gitAutoCommit"; | ||
| public static final String GIT_AUTO_PUSH = "gitAutoPush"; |
There was a problem hiding this comment.
This is an interesting questions. I think for now we can leave like this, and then decide later
Signed-off-by: subhramit <subhramit.bb@live.in>
I have a similar idea about OpenOffice, since now its preferences are also divided across the panel settings and preferences tab. |
| preferences, | ||
| stateManager, | ||
| taskExecutor, | ||
| Injector.instantiateModelOrService(GitHandlerRegistry.class), |
There was a problem hiding this comment.
these take a lot of time later when working on something else so id rather do it now
There was a problem hiding this comment.
okay, then work, then approve and mergy!
There was a problem hiding this comment.
Okay I see why gpt missed it - this is a big one
Signed-off-by: subhramit <subhramit.bb@live.in>
subhramit
left a comment
There was a problem hiding this comment.
This was immense effort @LoayTarek5. Thank you for this.
|
Yeahhhh🚀🎉. |

Summary
Adds a git section to the library properties with three per-library settings: automatically commit when the library is saved, push after committing, and regularly pull remote changes.
uses the same semantic merge as the File > Git menu actions rather than a plain JGit pull.
Git configuration was also moved out of the Network preferences and the Share to GitHub dialog into its own preferences tab, where it gained the pull interval.
Steps to test
1-Put a .bib library inside a Git repository with a remote.
2- Set the repository URL, username and PAT in Preferences > Git.
3- Open the library > Library properties > Git then tick "Automatically commit when library is saved".
4-Edit an entry and save, then a commit named "Update references" appears in the repository.
5-Tick "Automatically push changes after committing" and save again, the commit reaches the remote.
6. Tick "Regularly pull remote changes", push a change from another clone, and wait for the pull interval.
SLR_GIT_TEST.mp4
Related issues and pull requests
Closes #12630
AI usage
Claude Sonnet 5 to investigate some files and review my code, also helped me to generate tests and some UI stuff, all ai-generated code was reviewed by myself
Checklist
CHANGELOG.mddescribing the change from the user's point of view (if the change is visible to the user)