-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add git support #10586
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
Closed
Add git support #10586
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
10a4779
test: push
marcelojunior1 2c25b5f
fix build error
lbenicio 91a12f1
test: push
marcelojunior1 1126bc2
fix build error
lbenicio f3ae12e
refactor
marcelojunior1 c312817
fix: commit and push
marcelojunior1 7ffe7f1
code refactoring
marcelojunior1 905eda9
add silent exception on git pull and push
lbenicio b104b99
add username and password git credentials input
lbenicio bf33ca0
fix style and git logic to add one file only
lbenicio 375e689
add git preferences files
lbenicio d3a8014
inject dialog service
lbenicio a1e8ca0
add initial support to git credentials dialog view
lbenicio e4dd331
fix: git failed silently and style
marcelojunior1 4c81e54
fix git http push
lbenicio df3e4bb
refactor git credentials dialog to single dialog with two inputs
lbenicio 298d86e
user and password menu without Keyring
marcelojunior1 6109741
refact credentials view to other file
lbenicio 27b95bf
fix git pref panel
lbenicio e935882
user git preferences when pushing new commits
lbenicio 344775b
remove custom method used for validation
lbenicio 7d0b6db
git preferences and test
marcelojunior1 f3313b1
add unit test for commiting creating
lbenicio 6686905
unit test git prefernces and credentials
lbenicio a102257
push without auth
marcelojunior1 a2a5a71
add test git push with credentials
lbenicio fdebffa
git push without write on disk
marcelojunior1 45cd433
fix: start server
marcelojunior1 35949a9
fix: contextPath and req name
marcelojunior1 72c7532
fix: pushSingleFile
marcelojunior1 c184846
code style
lbenicio 6dfac3f
add changelog
lbenicio f4941a0
Merge branch 'main' into fix-578
lbenicio c2e5d74
cleanup code
lbenicio a6682a0
organize imports
lbenicio b0351ab
fix code style, add git preferences to control workflow, add files to…
lbenicio dff72dd
init developing resolve conflicts
lbenicio bbf1829
resolve all erros from file init
lbenicio a6021ea
Merge branch 'main' into fix-578
koppor 6b8700f
fix build error
lbenicio cfdd3c8
fix: git key store
marcelojunior1 f9abb2c
fix: git key store
marcelojunior1 75bce3c
Style
marcelojunior1 596275a
conflict resolution with file monitor
marcelojunior1 ce2e1d3
fix: push when status is clean
marcelojunior1 18a3373
fix: comments and forceGitPull
marcelojunior1 4ebfd85
fix: set credentials on test and style
marcelojunior1 0379fad
Merge branch 'main' into fix-578
marcelojunior1 ceab32c
fix: keys in language file and mock on SaveDatabaseActionTest
marcelojunior1 873a5cc
Merge branch 'main' into fix-578
marcelojunior1 bc0fd86
fix: changelog
marcelojunior1 6b5d9e1
Update src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
koppor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.pdf.search.PdfIndexerManager; | ||
|
|
@@ -45,6 +46,11 @@ | |
| import org.jabref.model.metadata.SelfContainedSaveOrder; | ||
| import org.jabref.preferences.PreferencesService; | ||
|
|
||
| import org.eclipse.jgit.api.errors.CheckoutConflictException; | ||
| import org.eclipse.jgit.api.errors.DetachedHeadException; | ||
| import org.eclipse.jgit.api.errors.GitAPIException; | ||
| import org.eclipse.jgit.api.errors.TransportException; | ||
| import org.eclipse.jgit.errors.NoRemoteRepositoryException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -239,14 +245,26 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) { | |
|
|
||
| boolean success = saveDatabase(targetPath, false, encoding, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, getSaveOrder()); | ||
|
|
||
| if (preferences.getGitPreferences().getAutoSync()) { | ||
| success = automaticGitPull(targetPath); | ||
| } | ||
|
|
||
| if (preferences.getGitPreferences().getAutoCommit()) { | ||
| boolean commited = automaticGitCommit(targetPath); | ||
| if (commited && preferences.getGitPreferences().getAutoSync()) { | ||
| automaticGitPush(targetPath); | ||
| } | ||
| } | ||
|
|
||
| if (success) { | ||
| libraryTab.getUndoManager().markUnchanged(); | ||
| libraryTab.resetChangedProperties(); | ||
| } | ||
| dialogService.notify(Localization.lang("Library saved")); | ||
|
|
||
| return success; | ||
| } catch (SaveException ex) { | ||
| LOGGER.error(String.format("A problem occurred when trying to save the file %s", targetPath), ex); | ||
| LOGGER.error("A problem occurred when trying to save the file {}", targetPath, ex); | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Save library"), Localization.lang("Could not save file."), ex); | ||
| return false; | ||
| } finally { | ||
|
|
@@ -316,4 +334,67 @@ private void saveWithDifferentEncoding(Path file, boolean selectedOnly, Charset | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param filePath of library | ||
| * @return true on successful git pull | ||
| */ | ||
| public boolean automaticGitPull(Path filePath) { | ||
| GitHandler git = new GitHandler(filePath.getParent(), preferences.getGitPreferences()); | ||
| try { | ||
| git.pullOnCurrentBranch(); | ||
| } catch (CheckoutConflictException e) { | ||
| git.forceGitPull(); | ||
| 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) { | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("No remote repository detected")); | ||
| LOGGER.info("No remote repository detected"); | ||
| } catch (DetachedHeadException e) { | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("Git detached head")); | ||
| LOGGER.info("Git detached head"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not returning "false" if something goes wrong? |
||
| } catch (TransportException e) { | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("Git credentials error")); | ||
| LOGGER.info("Git credentials error"); | ||
| } catch (GitAPIException e) { | ||
| LOGGER.info("Failed to pull"); | ||
| throw new RuntimeException(e); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not crash complete JabRef on an error. |
||
| } catch (IOException e) { | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("Failed to open repository")); | ||
| LOGGER.info("Failed to open repository"); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @param filePath of library | ||
| * @return true on successful git commit | ||
| */ | ||
| public boolean automaticGitCommit(Path filePath) { | ||
| GitHandler git = new GitHandler(filePath.getParent(), preferences.getGitPreferences()); | ||
| String automaticCommitMsg = "Automatic update via JabRef"; | ||
| if (preferences.getGitPreferences().getAutoCommit()) { | ||
| try { | ||
| return git.createCommitWithSingleFileOnCurrentBranch(filePath.getFileName().toString(), automaticCommitMsg); | ||
| } catch (GitAPIException | IOException e) { | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("Failed to open repository")); | ||
| LOGGER.info("Failed to open repository"); | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * @param filePath of library | ||
| */ | ||
| public void automaticGitPush(Path filePath) { | ||
| GitHandler git = new GitHandler(filePath.getParent(), preferences.getGitPreferences()); | ||
| try { | ||
| git.pushCommitsToRemoteRepository(); | ||
| } catch (IOException e) { | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Git"), Localization.lang("Failed to push file in remote repository")); | ||
| LOGGER.info("Failed to push file in remote repository"); | ||
| } | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
src/main/java/org/jabref/gui/git/GitCredentialsDialogView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package org.jabref.gui.git; | ||
|
|
||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.ButtonBar; | ||
| import javafx.scene.control.ButtonType; | ||
| import javafx.scene.control.DialogPane; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.PasswordField; | ||
| import javafx.scene.control.TextArea; | ||
| import javafx.scene.control.TextField; | ||
| import javafx.scene.layout.VBox; | ||
|
|
||
| import org.jabref.gui.DialogService; | ||
| import org.jabref.gui.util.BaseDialog; | ||
| import org.jabref.logic.git.GitCredential; | ||
| import org.jabref.logic.l10n.Localization; | ||
|
|
||
| import com.airhacks.afterburner.injection.Injector; | ||
|
|
||
| public class GitCredentialsDialogView extends BaseDialog<Void> { | ||
|
|
||
| @FXML private ButtonType copyVersionButton; | ||
| @FXML private TextArea textAreaVersions; | ||
| private DialogService dialogService; | ||
| private DialogPane pane; | ||
|
|
||
| private ButtonType acceptButton; | ||
| private ButtonType cancelButton; | ||
| private TextField inputGitUsername; | ||
| private PasswordField inputGitPassword; | ||
|
|
||
| public GitCredentialsDialogView() { | ||
| this.setTitle(Localization.lang("Git credentials")); | ||
| this.dialogService = Injector.instantiateModelOrService(DialogService.class); | ||
|
|
||
| this.pane = new DialogPane(); | ||
| VBox vBox = new VBox(); | ||
| this.inputGitUsername = new TextField(); | ||
| this.inputGitPassword = new PasswordField(); | ||
| this.acceptButton = new ButtonType(Localization.lang("Accept"), ButtonBar.ButtonData.APPLY); | ||
| this.cancelButton = new ButtonType(Localization.lang("Cancel"), ButtonBar.ButtonData.CANCEL_CLOSE); | ||
|
|
||
| vBox.getChildren().add(new Label(Localization.lang("Git username"))); | ||
| vBox.getChildren().add(this.inputGitUsername); | ||
| vBox.getChildren().add(new Label(Localization.lang("Git password"))); | ||
| vBox.getChildren().add(this.inputGitPassword); | ||
|
|
||
| this.pane.setContent(vBox); | ||
| } | ||
|
|
||
| public void showGitCredentialsDialog() { | ||
| dialogService.showCustomDialogAndWait(Localization.lang("Git credentials"), this.pane, this.acceptButton, this.cancelButton); | ||
| } | ||
|
|
||
| public GitCredential getCredentials() { | ||
| dialogService.showCustomDialogAndWait(Localization.lang("Git credentials"), this.pane, this.acceptButton, this.cancelButton); | ||
| GitCredential gitCredentials = new GitCredential(this.inputGitUsername.getText(), this.inputGitPassword.getText()); | ||
|
|
||
| return gitCredentials; | ||
| } | ||
|
|
||
| public String getGitPassword() { | ||
| return this.inputGitPassword.getText(); | ||
| } | ||
|
|
||
| public String getGitUsername() { | ||
| return this.inputGitUsername.getText(); | ||
| } | ||
|
|
||
| @FXML | ||
| private void initialize() { | ||
| this.setResizable(false); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <?import javafx.scene.control.Label?> | ||
| <?import javafx.scene.control.TextField?> | ||
| <?import javafx.scene.layout.HBox?> | ||
| <?import javafx.scene.layout.VBox?> | ||
| <?import javafx.scene.control.PasswordField?> | ||
| <?import javafx.scene.control.CheckBox?> | ||
| <fx:root spacing="10.0" type="VBox" | ||
| xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" | ||
| fx:controller="org.jabref.gui.preferences.git.GitTab"> | ||
| <Label styleClass="titleHeader" text="%Git"/> | ||
| <Label styleClass="sectionHeader" text="%Credential"/> | ||
| <HBox alignment="CENTER_LEFT" spacing="10.0"> | ||
| <Label text="%Email"/> | ||
| <TextField fx:id="username" minWidth="150.0" HBox.hgrow="ALWAYS"/> | ||
| <Label text="%Password"/> | ||
| <PasswordField fx:id="password" minWidth="150.0" HBox.hgrow="ALWAYS"/> | ||
| </HBox> | ||
| <HBox alignment="CENTER_LEFT" spacing="10.0"> | ||
| <CheckBox fx:id="autoCommit" text="%Enable git auto commit" /> | ||
| </HBox> | ||
| <HBox alignment="CENTER_LEFT" spacing="10.0"> | ||
| <CheckBox fx:id="autoSync" text="%Enable git auto push and merge" /> | ||
| </HBox> | ||
| </fx:root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package org.jabref.gui.preferences.git; | ||
|
|
||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.CheckBox; | ||
| import javafx.scene.control.PasswordField; | ||
| import javafx.scene.control.TextField; | ||
|
|
||
| import org.jabref.gui.preferences.AbstractPreferenceTabView; | ||
| import org.jabref.logic.l10n.Localization; | ||
|
|
||
| import com.airhacks.afterburner.views.ViewLoader; | ||
|
|
||
| public class GitTab extends AbstractPreferenceTabView<GitTabViewModel> { | ||
|
|
||
| @FXML private TextField username; | ||
| @FXML private PasswordField password; | ||
| @FXML private CheckBox autoCommit; | ||
| @FXML private CheckBox autoSync; | ||
|
|
||
| public GitTab() { | ||
| ViewLoader.view(this) | ||
| .root(this) | ||
| .load(); | ||
| initialize(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTabName() { | ||
| return Localization.lang("Git"); | ||
| } | ||
|
|
||
| @FXML | ||
| private void initialize() { | ||
| viewModel = new GitTabViewModel(preferencesService.getGitPreferences()); | ||
|
|
||
| username.textProperty().bindBidirectional(viewModel.getUsernameProperty()); | ||
| password.textProperty().bindBidirectional(viewModel.getPasswordProperty()); | ||
| autoCommit.selectedProperty().bindBidirectional(viewModel.getAutoCommitProperty()); | ||
| autoSync.selectedProperty().bindBidirectional(viewModel.getAutoSyncProperty()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Please use notifications instead of dialogs. Reason: The flow of the user should not be disturbed while working with git.