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

Add git support #10586

Closed
wants to merge 52 commits into from
Closed

Add git support #10586

wants to merge 52 commits into from

Conversation

lbenicio
Copy link

@lbenicio lbenicio commented Oct 25, 2023

Fixes https://github.com/koppor/jabref/issues/578

  • SSH auth method
  • Username/password dialog box auth method
  • Username/password env variables auth method
  • Store username/password in JabRef preferences
  • Fail silently
  • Support for local and remote git repositories
credentialsDialog preferencesPanel

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • 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.

@lbenicio
Copy link
Author

We are migrating our implementation to use java key ring, we were not using it. Now we see the problem. The diff dialog is still under heavy issues (I added the files from the database diff but still difficulty to navigate how to change it to git diffs). It seems more challenging them what we have thought.

@koppor
Copy link
Member

koppor commented Nov 27, 2023

@lbenicio you can replace the whole diff dialog by using JabRefs own feature to compare two libraries (bib files). Remember, the is the "file changed on disk" feature of JabRef. Maybe, you simply write out the file of the remote to the disk and then let JabRef do it's magic. The magic includes a) displaying all diffs and b) guiding the user through accepting, rejecting, and merging changes.

@lbenicio
Copy link
Author

@koppor We thought, as a v1, we could just create a text dialog with the diff output from the user and let the user decide

@koppor
Copy link
Member

koppor commented Nov 28, 2023

@lbenicio As I understand you, the dialog does not work. What I say: Remove that code, add approx. three lines of code and let JabRef do its magic. For sure, you can train your JavaFX skills with your dialog. Then please add screenshots!

@lbenicio
Copy link
Author

I don't quite understand how that will work as the class uses bib files, but i will try.

@marcelojunior1
Copy link

@lbenicio you can replace the whole diff dialog by using JabRefs own feature to compare two libraries (bib files). Remember, the is the "file changed on disk" feature of JabRef. Maybe, you simply write out the file of the remote to the disk and then let JabRef do it's magic. The magic includes a) displaying all diffs and b) guiding the user through accepting, rejecting, and merging changes.

I tried to pull before save the bib file, but i think file monitor is more slow than save action. Is it possible to check in file monitor if a conflict happened and if user resolved it ?

@koppor
Copy link
Member

koppor commented Dec 4, 2023

I tried to pull before save the bib file, but i think file monitor is more slow than save action.

The file monitor monitors the file on the disk. Thus, it cannot be slower than the save action.

Is it possible to check in file monitor if a conflict happened and if user resolved it ?

No. There are other listeners taking care of the work. For the first "MVP", it is enough to save the pulled file and let the user to the work - without going back the path of the save call. The handling of conflicts will be done in another independent thread then.

@koppor
Copy link
Member

koppor commented Jan 2, 2024

Happy new year! 🎉

This PR could take longer to be finished. Do you still have some time?

If yes, I would ask you to check the CI output: Checkstyle complains and some other checkers, too. Please check their output. Especially reconfigure IntelliJ to follow JabRef's code style. See https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html for details. You can then use Ctrl+Alt+L to reformat your classes.

@marcelojunior1
Copy link

marcelojunior1 commented Jan 14, 2024

I make the changes, but I don't understand this changelog.md error.

@koppor
Copy link
Member

koppor commented Jan 14, 2024

I make the changes, but I don't understand this changelog.md error.

Not sure, how I should explain.

You know software releases? You know that for each version, there is a section in CHANGELOG.md. Thus, for each released version, there is a section.

What if updates to the software come? Are older releases changed? No, new releases are made! - What about the CHANGELOG.md sections of older releases? Do new features go into these sections? No, a new section unreleased is used.

Now, let's check your patch:

image

The patch is in section of version 5.11 of JabRef. It adds a new feature to 5.11. BUT - hey, JabRef 5.11 is already released. See the release date in the heading and the releases at https://github.com/JabRef/jabref/releases.

Thus, this patch should NOT go into 5.11, but into the unreleased section of CHANGELOG.md

@marcelojunior1
Copy link

All right, and this last one, is it related to what we did?

@koppor
Copy link
Member

koppor commented Jan 22, 2024

All right, and this last one, is it related to what we did?

I don't understand, where "last one" refers to...

@marcelojunior1
Copy link

These Fetcher tests.

@Siedlerchr
Copy link
Member

Siedlerchr commented Jan 22, 2024 via email

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Some small comments. Still need to try it thoroughly...

try {
return Files.createDirectories(sshDir).toFile();
} catch (IOException e) {
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

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

JabRef should not crash completely if something goes wrong when using SSH. Better really throw the exception and handle at the caller.

}
} catch (GitAPIException | IOException e) {
LOGGER.error("Failed to force git pull", e);
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

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

JabRef should not be stopped (data loss!!) if some communication goes wrong. Handle differently.

try (Git git = Git.open(this.repositoryPathAsFile)) {
return git.getRepository().getBranch();
} catch (IOException ex) {
LOGGER.info("Failed get current branch");
return String.valueOf(Optional.empty());
Copy link
Member

Choose a reason for hiding this comment

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

What is this? You can return the empty string (""), but a string of Optional.empty is really strange.

@@ -482,6 +487,7 @@ public class JabRefPreferences implements PreferencesService {
private ColumnPreferences searchDialogColumnPreferences;
private JournalAbbreviationPreferences journalAbbreviationPreferences;
private FieldPreferences fieldPreferences;
private GitPreferences gitPreferences;
Copy link
Member

Choose a reason for hiding this comment

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

What I meant that multiple providers should be supported. See #10936 for an example for API keys (which are different for different providers). Maybe, this is a follow-up thing.

Note that GitHub supports both HTTP and SSH:

image

@@ -1614,12 +1626,27 @@ private String getProxyPassword() {
} catch (PasswordAccessException ex) {
LOGGER.warn("JabRef uses proxy password from key store but no password is stored");
} catch (Exception ex) {
LOGGER.warn("JabRef could not open the key store");
LOGGER.warn("JabRef could not open the git key store");
Copy link
Member

Choose a reason for hiding this comment

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

Wrong change. JabRef also stores other credentials there. Please revert.

Comment on lines +1293 to +1294
Git\ password=Git password
Git\ username=Git username
Copy link
Member

Choose a reason for hiding this comment

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

Maybe, one can get rid of this and only use "Username" and "Password", which should already exist here?

LOGGER.info("Git credentials error");
} catch (GitAPIException e) {
LOGGER.info("Failed to pull");
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

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

Do not crash complete JabRef on an error.

LOGGER.info("No remote repository detected");
} catch (DetachedHeadException e) {
dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("Git detached head"));
LOGGER.info("Git detached head");
Copy link
Member

Choose a reason for hiding this comment

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

Why not returning "false" if something goes wrong?

dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("Local repository is out of date, please review the library and save again"));
LOGGER.info("Failed to pull");
return false;
} catch (NoRemoteRepositoryException e) {
Copy link
Member

Choose a reason for hiding this comment

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

I think, all exceptions can be merged into one, because there is no "real" different behavior.

NoRemoteRepositoryException | DetachedHeadException etc..

Please use notifications instead of dialogs. Reason: The flow of the user should not be disturbed while working with git.

repository.incrementOpen();
return repository;
}
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't there be an exception?

@marcelojunior1
Copy link

Unfortunately, my classes started a few days ago and I will not be able to continue this project. If there is someone else who can continue this issue, you can pass it on.

@calixtus
Copy link
Member

calixtus commented Mar 1, 2024

Ok, yes, we will look into it. Thanks for your work on enhancing JabRef.

@koppor koppor marked this pull request as draft March 4, 2024 19:47
@lbenicio lbenicio closed this Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants