Skip to content

Add simple git support #12817

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

Closed
wants to merge 160 commits into from
Closed

Conversation

SihasA
Copy link
Contributor

@SihasA SihasA commented Mar 24, 2025

Closes #12350
We have implemented code here in 3 working packages (denoted 'WP' here).
WP1 - check if a .bib file (used in bibliography management) is inside a Git
repository. If it is, it tags the file as “versioned” and performs a git pull to fetch the latest
updates from the repository.

WP2 - Display the status of synchronisation with the file name.
Screenshot 2025-03-24 at 9 17 52 PM

WP3 - Allow the user to enable an auto push on save functionality via the general preferences as well as enable manual git support for simple git pull/push functionality. With appropriate dialogs for each instance.
Screenshot 2025-03-24 at 9 18 49 PM

Screenshot 2025-03-24 at 9 56 12 PM Screenshot 2025-03-24 at 9 22 19 PM

The changes we have made on a class by class basis:
GitHandler

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [] Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • [.] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [.] Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

RapidShotzz and others added 30 commits February 26, 2025 13:09
Update GitHandler constructor to optionally not create a repository if
none exists
…d-pull' into library-under-version-control-and-pull

# Conflicts:
#	src/test/java/org/jabref/gui/importer/actions/CheckForVersionControlActionTest.java
removed the logic that required the download of additional libraries/dependencies
…d-pull' into library-under-version-control-and-pull

# Conflicts:
#	src/main/java/org/jabref/logic/preferences/CliPreferences.java
@koppor
Copy link
Member

koppor commented Mar 26, 2025

where jabref could not parse the file with conflict markers.

You can go to the previous commits. We discussed that shortly in the meeting, but did not have time to dig deeper.

@koppor
Copy link
Member

koppor commented Mar 26, 2025

In my view, we first have to get #12678 in, then #12773, and then this one?

Yes you are right-

OK, then let's focus on the PRs in that order.

After a PR is squash-merged, you can follow the howto on flupp.de on how to merge main in this PR.

I ask you to work on #12678 to get the unit tests fixed. Our maintainers do all of this in their spare time - and like more to work on pull requests with green tests.


boolean result = action.isActionNecessary(parserResult, dialogService, cliPreferences);

assertTrue(result);
Copy link

Choose a reason for hiding this comment

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

Assertion statements should not include the message parameter, and the method name should already convey the expected behavior. This violates the guideline for assertion statements.


boolean result = action.isActionNecessary(parserResult, dialogService, cliPreferences);

assertFalse(result);
Copy link

Choose a reason for hiding this comment

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

Assertion statements should not include the message parameter, and the method name should already convey the expected behavior. This violates the guideline for assertion statements.


action.isActionNecessary(parserResult, dialogService, cliPreferences);

assertDoesNotThrow(() -> action.performAction(parserResult, dialogService, cliPreferences));
Copy link

Choose a reason for hiding this comment

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

Assertion statements should not include the message parameter, and the method name should already convey the expected behavior. This violates the guideline for assertion statements.

Jiewu (jack deng) Deng and others added 7 commits March 26, 2025 11:58
- Create NotificationService interface in Logic layer
- Implement DialogNotificationService adapter in GUI layer
- Replace direct DialogService dependency with NotificationService in GitClientHandler
- Update all call sites to use the new adapter pattern
- Add missing localization keys for Git operations
- Remove obsolete localization key

This change resolves architectural layering violations while maintaining
enhanced error handling and user feedback for Git operations. It properly
separates Logic and GUI layers, following the dependency inversion principle.
@SihasA
Copy link
Contributor Author

SihasA commented Mar 26, 2025

I ask you to work on #12678 to get the unit tests fixed. Our maintainers do all of this in their spare time - and like more to work on pull requests with green tests.

alright! Understood- we are submitting our university project today, will follow up with fixing the unit testing

Merge remote-tracking branch 'origin/Add-Simple-Git-Support' into Add-Simple-Git-Support
@@ -396,7 +409,8 @@ private boolean isDatabaseReadyForBackup(BibDatabaseContext context) {
* <p>
* Example: *jabref-authors.bib – testbib
*/
public void updateTabTitle(boolean isChanged) {

public void updateTabTitle(boolean isModified) {
Copy link

Choose a reason for hiding this comment

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

The method updateTabTitle has been modified but lacks JavaDoc to explain its purpose and behavior, especially after the changes related to Git integration.

@@ -53,6 +53,9 @@ public class GeneralTab extends AbstractPreferenceTabView<GeneralTabViewModel> i
@FXML private CheckBox alwaysReformatBib;
@FXML private CheckBox autosaveLocalLibraries;
@FXML private Button autosaveLocalLibrariesHelp;
@FXML private TextField gitHubUsernameField;
Copy link

Choose a reason for hiding this comment

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

The new UI elements for GitHub integration, such as gitHubUsernameField, should have their labels localized using Localization.lang(). This ensures consistency with other UI elements.

@@ -440,4 +451,16 @@ private Optional<Integer> getPortAsInt(String value) {
return Optional.empty();
}
}

public BooleanProperty autoPushEnabledProperty() {
Copy link

Choose a reason for hiding this comment

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

The method 'autoPushEnabledProperty' returns a BooleanProperty, which can potentially be null. New public methods should not return null and should use java.util.Optional instead.

return gitPreferences.getAutoPushEnabledProperty();
}

public StringProperty gitHubUsernameProperty() {
Copy link

Choose a reason for hiding this comment

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

The method 'gitHubUsernameProperty' returns a StringProperty, which can potentially be null. New public methods should not return null and should use java.util.Optional instead.

return gitPreferences.gitHubUsernameProperty();
}

public StringProperty gitHubPasskeyProperty() {
Copy link

Choose a reason for hiding this comment

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

The method 'gitHubPasskeyProperty' returns a StringProperty, which can potentially be null. New public methods should not return null and should use java.util.Optional instead.

try {
pushCommitsToRemoteRepository();
} catch (IOException e) {
LOGGER.error("Failed to push");
Copy link

Choose a reason for hiding this comment

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

The exception is not logged using exception logging capabilities, which would provide more context about the error. It should include the exception object.

} catch (IOException e) {
LOGGER.error("Failed to get latest commit");
}
return null;
Copy link

Choose a reason for hiding this comment

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

Returning null from a method is discouraged. Instead, java.util.Optional should be used to avoid potential NullPointerExceptions.

* @param repositoryPath The root of the initialized git repository
* @param createRepo If true, initializes a repository if the file path does not contain a repository
*/
public GitHandler(Path repositoryPath, boolean createRepo) {
Copy link

Choose a reason for hiding this comment

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

The constructor has a boolean parameter 'createRepo'. Boolean parameters should be avoided in public methods. Consider creating two distinct methods for clarity.

} catch (GitAPIException e) {
LOGGER.info("Failed to push");
LOGGER.error("Failed to push: {}", e.getMessage(), e);
Copy link

Choose a reason for hiding this comment

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

The logging statement should use exception logging capabilities directly without concatenating the exception message.

} catch (GitAPIException e) {
LOGGER.info("Failed to push");
LOGGER.error("Failed to pull", e);
Copy link

Choose a reason for hiding this comment

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

The logging statement should use exception logging capabilities directly without concatenating the exception message.

@jabref-machine
Copy link
Collaborator

JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

@SihasA SihasA closed this Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add (simple) git support
6 participants