Verified Owner
Top Description Fields Constructors Methods
org.jabref.gui.git

public Class GitAutoSync

extends Object
Class Inheritance
Annotations
@NullMarked
Imports
java.io.IOException, java.nio.file.Path, java.util.List, .Optional, java.util.function.BooleanSupplier, org.jabref.gui.DialogService, .StateManager, org.jabref.gui.preferences.GuiPreferences, org.jabref.logic.JabRefException, org.jabref.logic.git.GitHandler, .GitSyncService, org.jabref.logic.git.conflicts.ThreeWayEntryConflict, org.jabref.logic.git.io.GitFileWriter, org.jabref.logic.git.model.BookkeepingResult, .MergePlan, .PullPlan, org.jabref.logic.git.status.GitStatusChecker, org.jabref.logic.git.util.GitHandlerRegistry, org.jabref.logic.l10n.Localization, org.jabref.logic.util.BackgroundTask, .TaskExecutor, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, org.eclipse.jgit.api.errors.GitAPIException, org.jspecify.annotations.NullMarked, org.slf4j.Logger, .LoggerFactory

Runs the Git operations configured in the library properties.

Same operations as GitCommitAction and GitPushAction, but started by a save or a timer instead of the user. Failures are reported as notifications rather than dialogs. A conflict during the pull before an auto-push still prompts, because the user is present for the save that started it; a scheduled pull runs unattended and stays silent.

Field Summary

Modifier and TypeField and Description
private final DialogService
private final GitHandlerRegistry
private final GuiPreferences
private static final Logger
private final StateManager
private final TaskExecutor

Constructor Summary

AccessConstructor and Description
public
GitAutoSync(DialogService dialogService, GitHandlerRegistry gitHandlerRegistry, TaskExecutor taskExecutor, GuiPreferences guiPreferences, StateManager stateManager)

Method Summary

Modifier and TypeMethod and Description
private void
applyCleanMerge(Path bibFilePath, BibDatabaseContext databaseContext, PullPlan pullPlan, BooleanSupplier hasUnsavedChanges)

private void
applyMerge(Path bibFilePath, BibDatabaseContext databaseContext, PullPlan pullPlan)

public void
commit(Path bibFilePath, BibDatabaseContext databaseContext)

Commits the library if it is inside a Git repository.

private void
commit(Path bibFilePath, BibDatabaseContext databaseContext, boolean pushAfterCommit)

public void
commitAndPush(Path bibFilePath, BibDatabaseContext databaseContext)

Commits the library if it is inside a Git repository, and pushes afterwards.

private boolean
doCommit(GitHandler gitHandler, Path bibFilePath)

private Optional<PullPlan>
preparePull(GitHandler gitHandler, BibDatabaseContext databaseContext, Path bibFilePath)

public void
pull(Path bibFilePath, BibDatabaseContext databaseContext, BooleanSupplier hasUnsavedChanges)

Pulls remote changes if the library is inside a Git repository.

private void
pullThenPush(Path bibFilePath, BibDatabaseContext databaseContext)

private void
push(Path bibFilePath, BibDatabaseContext databaseContext)

private void
private void
private void
showPullResult(BookkeepingResult bookkeepingResult, MergePlan autoPlan)

Reports what a scheduled pull changed, and stays quiet when it changed nothing.

private void
private GitSyncService
private org.jabref.logic.util.BackgroundTask<BookkeepingResult>
writeAndFinalize(Path bibFilePath, BibDatabaseContext databaseContext, PullPlan pullPlan)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dialogServiceback to summary
private final DialogService dialogService
gitHandlerRegistryback to summary
private final GitHandlerRegistry gitHandlerRegistry
guiPreferencesback to summary
private final GuiPreferences guiPreferences
LOGGERback to summary
private static final Logger LOGGER
stateManagerback to summary
private final StateManager stateManager
taskExecutorback to summary
private final TaskExecutor taskExecutor

Constructor Detail

GitAutoSyncback to summary
public GitAutoSync(DialogService dialogService, GitHandlerRegistry gitHandlerRegistry, TaskExecutor taskExecutor, GuiPreferences guiPreferences, StateManager stateManager)

Method Detail

applyCleanMergeback to summary
private void applyCleanMerge(Path bibFilePath, BibDatabaseContext databaseContext, PullPlan pullPlan, BooleanSupplier hasUnsavedChanges)
applyMergeback to summary
private void applyMerge(Path bibFilePath, BibDatabaseContext databaseContext, PullPlan pullPlan)
commitback to summary
public void commit(Path bibFilePath, BibDatabaseContext databaseContext)

Commits the library if it is inside a Git repository. does nothing if the library file is unchanged

commitback to summary
private void commit(Path bibFilePath, BibDatabaseContext databaseContext, boolean pushAfterCommit)
commitAndPushback to summary
public void commitAndPush(Path bibFilePath, BibDatabaseContext databaseContext)

Commits the library if it is inside a Git repository, and pushes afterwards. does nothing if the library file is unchanged

doCommitback to summary
private boolean doCommit(GitHandler gitHandler, Path bibFilePath) throws org.jabref.logic.JabRefException, GitAPIException, IOException
preparePullback to summary
private Optional<PullPlan> preparePull(GitHandler gitHandler, BibDatabaseContext databaseContext, Path bibFilePath) throws org.jabref.logic.JabRefException, GitAPIException, IOException
pullback to summary
public void pull(Path bibFilePath, BibDatabaseContext databaseContext, BooleanSupplier hasUnsavedChanges)

Pulls remote changes if the library is inside a Git repository. Skips quietly when there are uncommitted changes or the merge has conflicts, because no user started this operation.

pullThenPushback to summary
private void pullThenPush(Path bibFilePath, BibDatabaseContext databaseContext)
pushback to summary
private void push(Path bibFilePath, BibDatabaseContext databaseContext)
showCommitErrorback to summary
private void showCommitError(Exception exception)
showPullErrorback to summary
private void showPullError(Exception exception)
showPullResultback to summary
private void showPullResult(BookkeepingResult bookkeepingResult, MergePlan autoPlan)

Reports what a scheduled pull changed, and stays quiet when it changed nothing.

showPushErrorback to summary
private void showPushError(Exception exception)
syncServiceback to summary
private GitSyncService syncService()
writeAndFinalizeback to summary
private org.jabref.logic.util.BackgroundTask<BookkeepingResult> writeAndFinalize(Path bibFilePath, BibDatabaseContext databaseContext, PullPlan pullPlan)