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

[WIP] Happy days git integration wp3 #12773

Draft
wants to merge 84 commits into
base: gitintegration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
01dec74
added methods to and boolean to see if file is under version control …
Feb 26, 2025
eb1b9a8
Add CheckForVersionControlAction
11raphael Feb 26, 2025
c761db5
Added unit tests for - CheckForVersionControlAction
Ary006 Feb 26, 2025
2c9dad4
Added unit tests for - CheckForVersionControlAction
Ary006 Feb 27, 2025
ed6eb4a
added functionality for tagging as versioned and pulling only if pref…
Feb 27, 2025
9cbdd76
moved test file and amended shouldAutoPull method to test.org.jabref.…
Feb 27, 2025
62defc4
Remove RuntimeException from CheckForVersionControlAction
11raphael Mar 1, 2025
bbc6b38
Remove redundant methods from GitHandler
11raphael Mar 1, 2025
69e0f9a
modified the test cases for CheckForVersionControlAction
Ary006 Mar 1, 2025
d578bd5
Merge remote-tracking branch 'origin/library-under-version-control-an…
Ary006 Mar 1, 2025
cf32088
modified the test cases for CheckForVersionControlAction
Ary006 Mar 1, 2025
c670625
modified the test cases for CheckForVersionControlAction
Ary006 Mar 1, 2025
9026eb9
modified the test cases for CheckForVersionControlAction
Ary006 Mar 1, 2025
40cdd64
modified the test cases for CheckForVersionControlAction
Ary006 Mar 1, 2025
8db799c
Remove preference in CheckForVersionControlAction
11raphael Mar 3, 2025
af0c3c8
Add git preferences
11raphael Mar 3, 2025
1f2de0a
Add GitPreferences to CliPreferences
11raphael Mar 3, 2025
cfd46db
added autoPushEnabled attributes and set methods
Mar 3, 2025
6ecf1a8
modified tab view model to handle auto push
Mar 3, 2025
a0e2dc7
Add getGitPreferences to JabRefCliPreferences
11raphael Mar 3, 2025
c8be361
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
11raphael Mar 3, 2025
5127bca
Merge branch 'Happy-Days-Git-Integration-WP3' into library-under-vers…
11raphael Mar 3, 2025
2bf349d
Remove redundant shouldAutoPull from CliPreferences
11raphael Mar 3, 2025
bff9857
Added a rudimentary first draft preference selector under Saving in g…
SihasA Mar 3, 2025
c197264
Merge remote-tracking branch 'origin/library-under-version-control-an…
11raphael Mar 3, 2025
f7c21c4
removed duplicate boolean
Mar 4, 2025
980c748
Cleaned up UI - "Auto push" Combo Box no longer is in all Caps
SihasA Mar 5, 2025
caf405b
Added "Git" submenu with "Git Pull" and "Git Push" options
Ary006 Mar 6, 2025
4ed64cd
constructed get git preferences
Mar 9, 2025
45c453e
Merge branch 'library-under-version-control-and-pull' into Happy-Days…
11raphael Mar 9, 2025
3ff8bc3
Add autoPushMode to GitPreferences
11raphael Mar 10, 2025
63d86f1
Add git functionality on database save to GitHandler and SaveDatabase…
11raphael Mar 10, 2025
837311f
Create GitPullAction for git pull menu item
11raphael Mar 10, 2025
53286d4
Fix: Rename GitPullAction and correct GitHandler repository path in c…
11raphael Mar 12, 2025
cd6ff23
modified getGitPreferences to account for getAutoPushModeProperty() m…
Mar 12, 2025
f2fae4b
Remove redundant parameter from GeneralTabViewModel
11raphael Mar 12, 2025
7b0e930
Clean 'Failed to push' logger message
11raphael Mar 12, 2025
c28b84f
removed comments
Mar 12, 2025
0e0ddba
Fixed error regarding preferences not saving correctly
SihasA Mar 13, 2025
b9ca978
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
SihasA Mar 13, 2025
e71d3ad
Fixed error regarding preferences not saving correctly
SihasA Mar 13, 2025
27b0355
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
11raphael Mar 13, 2025
6a7e013
Update GitHandler with staging methods and add GitPullAction
11raphael Mar 13, 2025
e3885b7
Cleaned up UI Preferences
SihasA Mar 13, 2025
0fd12cc
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
11raphael Mar 13, 2025
b1458b2
Capitalization
11raphael Mar 13, 2025
98ec8a8
Remove redundant methods from GitHandler
11raphael Mar 13, 2025
d9162bc
added tests for git preferences to ensure that auto push functionalit…
Mar 13, 2025
e800a28
moved location of gitpreferences test
Mar 13, 2025
0c51c0e
Add unit tests for AutoPushMode - covering getDisplayName(), toString…
Ary006 Mar 17, 2025
5e0015c
Added Git Username and Passkey fields to preferences
SihasA Mar 17, 2025
d5b72bb
Add git credentials logic
11raphael Mar 17, 2025
2586df7
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
11raphael Mar 17, 2025
bed8cc7
Fix preferences in GitHandler
11raphael Mar 17, 2025
4b71771
demo
11raphael Mar 17, 2025
d52d62a
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
SihasA Mar 17, 2025
f232305
Fixed merge conflicts and added github passkey and username to prefer…
SihasA Mar 17, 2025
4d91985
Revert "Added Git Username and Passkey fields to preferences"
SihasA Mar 17, 2025
2ea0d72
Fixed Preferences and finished GitFunctionality for basic pull and push
SihasA Mar 17, 2025
2fe1066
Implement auto push on database save
11raphael Mar 17, 2025
8f683f0
Removed Manually option from combobox, will remove combobox in future.
SihasA Mar 17, 2025
cdb4c76
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
SihasA Mar 17, 2025
1884dd7
Revert "Implement auto push on database save"
SihasA Mar 17, 2025
bde293a
Revert "Revert "Implement auto push on database save""
SihasA Mar 17, 2025
37e0b92
Fix various issues
11raphael Mar 18, 2025
f87ab7a
Fixed/ Looked into Bot Comments
SihasA Mar 18, 2025
dcc5a06
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
11raphael Mar 18, 2025
b11f155
Fixed CheckStyleIssues and Bot Issue
SihasA Mar 18, 2025
854af5c
Fixing Bot Comments
SihasA Mar 18, 2025
95197c2
Reverted changes to module-info.java and build.gradle.
SihasA Mar 19, 2025
51e6fd6
Refactor git client functionality into GitClientHandler
11raphael Mar 19, 2025
f1fe7f5
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
11raphael Mar 19, 2025
e3fc84e
Corrected issue - "Method violates fail-fast principle by nesting all…
Ary006 Mar 19, 2025
3070087
Corrected issue - "Method violates fail-fast principle by nesting all…
Ary006 Mar 19, 2025
4e1c577
Corrected issue - "Method violates fail-fast principle by nesting all…
Ary006 Mar 19, 2025
5b278aa
Ran rewriteRun and fixed bot comments
SihasA Mar 19, 2025
c305e53
Added localisation and fixed logger issues.
SihasA Mar 19, 2025
9b0bf8f
Fixed one failing test case and removed problematic test + Bot commen…
SihasA Mar 19, 2025
493775b
Add test cases for Git repository detection
arp-23 Mar 19, 2025
92df862
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
arp-23 Mar 19, 2025
0c0a094
Refactor postSaveDatabaseAction and GitClientHandler
11raphael Mar 19, 2025
6e731cf
Merge remote-tracking branch 'origin/Happy-Days-Git-Integration-WP3' …
11raphael Mar 19, 2025
355ff89
Update postSaveDatabaseAction JavaDoc
11raphael Mar 19, 2025
86edd20
Removed line in build.gradle
SihasA Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ repositories {

// Required for one.jpro.jproutils:tree-showing
maven { url 'https://sandec.jfrog.io/artifactory/repo' }
mavenCentral()
}

configurations {
Expand All @@ -160,6 +161,8 @@ dependencies {
// Include all jar-files in the 'lib' folder as dependencies
implementation fileTree(dir: 'lib', includes: ['*.jar'])

implementation 'de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does an AI bot create these empty lines?

I would recommend to review a commit using git gui!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My accident actually! A member of my team had accidentally added a few dependencies and removed some when trying to add the git functionality to the main menu (He wanted to add an icon next to "Git"). I was removing these dependencies manually and left a line. Will fix that and review the changes properly next time, thank you.

def pdfbox = "3.0.4"
implementation ("org.apache.pdfbox:pdfbox:$pdfbox") {
exclude group: 'commons-logging'
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
requires java.sql.rowset;

// region JavaFX
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;
requires javafx.web;
requires javafx.fxml;

Expand Down Expand Up @@ -193,5 +190,6 @@
requires mslinks;
requires org.antlr.antlr4.runtime;
requires org.libreoffice.uno;
requires de.jensd.fx.glyphs.fontawesome;
// endregion
}
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ public enum StandardActions implements Action {
GROUP_ENTRIES_ADD(Localization.lang("Add selected entries to this group")),
GROUP_ENTRIES_REMOVE(Localization.lang("Remove selected entries from this group")),

GIT(Localization.lang("Git")),
GIT_PULL(Localization.lang("Git Pull")),
GIT_PUSH(Localization.lang("Git Push")),

CLEAR_EMBEDDINGS_CACHE(Localization.lang("Clear embeddings cache"));

private String text;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.git.GitHandler;
import org.jabref.logic.l10n.Encodings;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.DatabaseLocation;
Expand Down Expand Up @@ -237,6 +238,7 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) {
if (success) {
libraryTab.getUndoManager().markUnchanged();
libraryTab.resetChangedProperties();
new GitHandler(targetPath.getParent(), false).postSaveDatabaseAction(preferences.getGitPreferences());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating and executing GitHandler in the save method violates single responsibility principle. Git operations should be handled separately from database saving logic.

}
dialogService.notify(Localization.lang("Library saved"));
return success;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jabref/gui/frame/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import org.jabref.gui.push.PushToApplicationCommand;
import org.jabref.gui.search.RebuildFulltextSearchIndexAction;
import org.jabref.gui.shared.ConnectToSharedDatabaseCommand;
import org.jabref.gui.shared.GitPullAction;
import org.jabref.gui.shared.GitPushAction;
import org.jabref.gui.shared.PullChangesFromSharedAction;
import org.jabref.gui.sidepane.SidePane;
import org.jabref.gui.sidepane.SidePaneType;
Expand Down Expand Up @@ -157,6 +159,12 @@ private void createMenu() {

new SeparatorMenuItem(),

factory.createSubMenu(StandardActions.GIT,
factory.createMenuItem(StandardActions.GIT_PUSH, new GitPushAction(preferences, dialogService, stateManager)),
factory.createMenuItem(StandardActions.GIT_PULL, new GitPullAction(preferences, dialogService, stateManager))),

new SeparatorMenuItem(),

factory.createSubMenu(StandardActions.IMPORT,
factory.createMenuItem(StandardActions.IMPORT_INTO_CURRENT_LIBRARY, new ImportCommand(frame, ImportCommand.ImportMethod.TO_EXISTING, preferences, stateManager, fileUpdateMonitor, taskExecutor, dialogService)),
factory.createMenuItem(StandardActions.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(frame, ImportCommand.ImportMethod.AS_NEW, preferences, stateManager, fileUpdateMonitor, taskExecutor, dialogService))),
Expand Down Expand Up @@ -387,3 +395,5 @@ private Menu createSendSubMenu(ActionFactory factory,
return sendMenu;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jabref.gui.importer.actions;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;

import org.jabref.gui.DialogService;
import org.jabref.logic.git.GitHandler;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.preferences.CliPreferences;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This action checks whether this BIB file is contained in a Git repository. If so,
* then the file is tagged as "versioned" in BibDatabaseContext and a git pull is
* attempted.
*/
public class CheckForVersionControlAction implements GUIPostOpenAction {
private static final Logger LOGGER = LoggerFactory.getLogger(CheckForVersionControlAction.class);
private GitHandler gitHandler;

@Override
public boolean isActionNecessary(ParserResult parserResult, DialogService dialogService, CliPreferences preferences) {
Optional<Path> path = parserResult.getDatabaseContext().getDatabasePath();
if (path.isEmpty()) {
return false;
}
this.gitHandler = new GitHandler(path.get());
return gitHandler.isGitRepository();
}

@Override
public void performAction(ParserResult parserResult, DialogService dialogService, CliPreferences preferencesService) {
parserResult.getDatabaseContext().setVersioned(true);

try {
this.gitHandler.pullOnCurrentBranch();
} catch (IOException e) {
LOGGER.error("Failed to pull.", e);
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@
</padding>
</HBox>

<HBox spacing="10">
<Label text="GitHub Username:"/>
<TextField fx:id="gitHubUsernameField"/>
</HBox>

<HBox spacing="10">
<Label text="GitHub Passkey:"/>
<TextField fx:id="gitHubPasskeyField"/>
</HBox>
<HBox alignment="CENTER_LEFT" spacing="4.0">
<CheckBox fx:id="autoPushCheckbox" text="Auto Push"/>
<ComboBox fx:id="autoPushModeComboBox"/>
</HBox>

<HBox alignment="CENTER_LEFT" spacing="10.0">
<CheckBox fx:id="createBackup" text="%Create backup"/>
<TextField fx:id="backupDirectory" HBox.hgrow="ALWAYS"/>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/gui/preferences/general/GeneralTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Language;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preferences.AutoPushMode;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.FileUpdateMonitor;
Expand Down Expand Up @@ -51,6 +52,10 @@ public class GeneralTab extends AbstractPreferenceTabView<GeneralTabViewModel> i
@FXML private CheckBox alwaysReformatBib;
@FXML private CheckBox autosaveLocalLibraries;
@FXML private Button autosaveLocalLibrariesHelp;
@FXML private TextField gitHubUsernameField;
@FXML private TextField gitHubPasskeyField;
@FXML private CheckBox autoPushCheckbox;
@FXML private ComboBox<AutoPushMode> autoPushModeComboBox;
@FXML private CheckBox createBackup;
@FXML private TextField backupDirectory;
@FXML private CheckBox remoteServer;
Expand Down Expand Up @@ -128,6 +133,14 @@ public void initialize() {

alwaysReformatBib.selectedProperty().bindBidirectional(viewModel.alwaysReformatBibProperty());
autosaveLocalLibraries.selectedProperty().bindBidirectional(viewModel.autosaveLocalLibrariesProperty());

gitHubUsernameField.textProperty().bindBidirectional(viewModel.gitHubUsernameProperty());
gitHubPasskeyField.textProperty().bindBidirectional(viewModel.gitHubPasskeyProperty());

autoPushCheckbox.selectedProperty().bindBidirectional(viewModel.autoPushEnabledProperty());
autoPushModeComboBox.setItems(viewModel.autoPushModeListProperty());
autoPushModeComboBox.valueProperty().bindBidirectional(viewModel.autoPushModeProperty());

ActionFactory actionFactory = new ActionFactory();
actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE, dialogService, preferences.getExternalApplicationsPreferences()), autosaveLocalLibrariesHelp);
actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.REMOTE, dialogService, preferences.getExternalApplicationsPreferences()), remoteHelp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.FilePreferences;
import org.jabref.logic.LibraryPreferences;
import org.jabref.logic.git.GitPreferences;
import org.jabref.logic.l10n.Language;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.ssl.TrustStoreManager;
import org.jabref.logic.preferences.AutoPushMode;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.RemoteUtil;
import org.jabref.logic.remote.server.RemoteListenerServerManager;
Expand Down Expand Up @@ -64,6 +66,10 @@ public class GeneralTabViewModel implements PreferenceTabViewModel {
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(ThemeTypes.values()));
private final ObjectProperty<ThemeTypes> selectedThemeProperty = new SimpleObjectProperty<>();

private final ReadOnlyListProperty<AutoPushMode> autoPushModeListProperty =
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(AutoPushMode.values()));
private final ObjectProperty<AutoPushMode> autoPushModeProperty = new SimpleObjectProperty<>();

private final BooleanProperty themeSyncOsProperty = new SimpleBooleanProperty();

// init with empty string to avoid npe in accessing
Expand Down Expand Up @@ -92,6 +98,7 @@ public class GeneralTabViewModel implements PreferenceTabViewModel {
private final LibraryPreferences libraryPreferences;
private final FilePreferences filePreferences;
private final RemotePreferences remotePreferences;
private final GitPreferences gitPreferences;

private final Validator fontSizeValidator;
private final Validator customPathToThemeValidator;
Expand All @@ -110,6 +117,7 @@ public GeneralTabViewModel(DialogService dialogService, GuiPreferences preferenc
this.workspacePreferences = preferences.getWorkspacePreferences();
this.libraryPreferences = preferences.getLibraryPreferences();
this.filePreferences = preferences.getFilePreferences();
this.gitPreferences = preferences.getGitPreferences();
this.remotePreferences = preferences.getRemotePreferences();
this.fileUpdateMonitor = fileUpdateMonitor;
this.entryTypesManager = entryTypesManager;
Expand Down Expand Up @@ -191,6 +199,11 @@ public void setValues() {
alwaysReformatBibProperty.setValue(libraryPreferences.shouldAlwaysReformatOnSave());
autosaveLocalLibraries.setValue(libraryPreferences.shouldAutoSave());

autoPushEnabledProperty().setValue(gitPreferences.getAutoPushEnabled());
autoPushModeProperty().setValue(gitPreferences.getAutoPushMode());
gitHubUsernameProperty().setValue(gitPreferences.getGitHubUsername());
gitHubPasskeyProperty().setValue(gitPreferences.getGitHubPasskey());

createBackupProperty.setValue(filePreferences.shouldCreateBackup());
backupDirectoryProperty.setValue(filePreferences.getBackupDirectory().toString());

Expand Down Expand Up @@ -231,6 +244,11 @@ public void storeSettings() {
libraryPreferences.setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue());
libraryPreferences.setAutoSave(autosaveLocalLibraries.getValue());

gitPreferences.setAutoPushEnabled(autoPushEnabledProperty().get());
gitPreferences.setAutoPushMode(autoPushModeProperty().get());
gitPreferences.setGitHubUsername(gitHubUsernameProperty().get());
gitPreferences.setGitHubPasskey(gitHubPasskeyProperty().get());

filePreferences.createBackupProperty().setValue(createBackupProperty.getValue());
filePreferences.backupDirectoryProperty().setValue(Path.of(backupDirectoryProperty.getValue()));

Expand Down Expand Up @@ -426,4 +444,24 @@ private Optional<Integer> getPortAsInt(String value) {
return Optional.empty();
}
}

public BooleanProperty autoPushEnabledProperty() {
return gitPreferences.getAutoPushEnabledProperty();
}

public ReadOnlyListProperty<AutoPushMode> autoPushModeListProperty() {
return this.autoPushModeListProperty;
}

public ObjectProperty<AutoPushMode> autoPushModeProperty() {
return this.autoPushModeProperty;
}

public StringProperty gitHubUsernameProperty() {
return gitPreferences.gitHubUsernameProperty();
}

public StringProperty gitHubPasskeyProperty() {
return gitPreferences.gitHubPasskeyProperty();
}
}
57 changes: 57 additions & 0 deletions src/main/java/org/jabref/gui/shared/GitPullAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.jabref.gui.shared;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.git.GitHandler;
import org.jabref.model.database.BibDatabaseContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GitPullAction extends SimpleCommand {
private static final Logger LOGGER = LoggerFactory.getLogger(GitPullAction.class);

private final GuiPreferences preferences;
private final DialogService dialogService;
private final StateManager stateManager;

public GitPullAction(
GuiPreferences preferences,
DialogService dialogService,
StateManager stateManager) {
this.preferences = preferences;
this.dialogService = dialogService;
this.stateManager = stateManager;
}

@Override
public void execute() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method lacks JavaDoc despite being a public method that performs complex Git operations. Complex public methods should have comprehensive documentation.

BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get();
if (stateManager.getActiveDatabase().isEmpty()) {
return;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential NPE as get() is called before isEmpty() check. The code retrieves the database before checking if it exists, violating the fail-fast principle and risking exceptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still valid comment


Optional<Path> path = databaseContext.getDatabasePath();
if (path.isEmpty()) {
return;
}

GitHandler gitHandler = new GitHandler(path.get().getParent(), false);
if (gitHandler.isGitRepository()) {
try {
gitHandler.updateCredentials(preferences.getGitPreferences());
gitHandler.pullOnCurrentBranch();
} catch (IOException e) {
dialogService.showErrorDialogAndWait(e);
}
} else {
LOGGER.info("Not a git repository at path: {}", path.get());
}
}
}
59 changes: 59 additions & 0 deletions src/main/java/org/jabref/gui/shared/GitPushAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.jabref.gui.shared;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.git.GitHandler;
import org.jabref.model.database.BibDatabaseContext;

import org.eclipse.jgit.api.errors.GitAPIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GitPushAction extends SimpleCommand {
private static final Logger LOGGER = LoggerFactory.getLogger(GitPushAction.class);

private final GuiPreferences preferences;
private final DialogService dialogService;
private final StateManager stateManager;

public GitPushAction(
GuiPreferences preferences,
DialogService dialogService,
StateManager stateManager) {
this.preferences = preferences;
this.dialogService = dialogService;
this.stateManager = stateManager;
}

@Override
public void execute() {
if (stateManager.getActiveDatabase().isEmpty()) {
return;
}
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get();

Optional<Path> path = databaseContext.getDatabasePath();
if (path.isEmpty()) {
return;
}

GitHandler gitHandler = new GitHandler(path.get().getParent(), false);
if (gitHandler.isGitRepository()) {
try {
gitHandler.createCommitOnCurrentBranch("Automatic update via JabRef", false);
gitHandler.updateCredentials(preferences.getGitPreferences());
gitHandler.pushCommitsToRemoteRepository();
} catch (IOException | GitAPIException e) {
dialogService.showErrorDialogAndWait(e);
}
} else {
LOGGER.info("Not a git repository at path: {}", path.get());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message directly calls path.get() without checking if the value is present, which could lead to NoSuchElementException. The Optional should be handled properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-03-18 at 3 56 16 PM

As per intelliJ's response when trying to set a condition, it can be said that there will always be a path and hence this comment is irrelevant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just log path, will appear properly. Try it out!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you that works!

}
}
}
Loading
Loading