Skip to content

Commit 69575b5

Browse files
committed
chore(git): Fix variable names + refactoring (moving the GitConflictResolver interface to the logic module) #12350
1 parent ac66eed commit 69575b5

File tree

22 files changed

+153
-55
lines changed

22 files changed

+153
-55
lines changed

jabgui/src/main/java/org/jabref/gui/LibraryTabContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface LibraryTabContainer {
2727
* Closes a designated libraryTab
2828
*
2929
* @param tab to be closed.
30-
* @return true if closing the tab was isSuccessful
30+
* @return true if closing the tab was successful
3131
*/
3232
boolean closeTab(@Nullable LibraryTab tab);
3333

jabgui/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void performBackup(Path backupPath) {
275275
BibDatabaseContext bibDatabaseContextClone = new BibDatabaseContext(bibDatabaseClone, bibDatabaseContext.getMetaData());
276276

277277
Charset encoding = bibDatabaseContext.getMetaData().getEncoding().orElse(StandardCharsets.UTF_8);
278-
// We want to have isSuccessful backups only
278+
// We want to have successful backups only
279279
// Thus, we do not use a plain "FileWriter", but the "AtomicFileWriter"
280280
// Example: What happens if one hard powers off the machine (or kills the jabref process) during writing of the backup?
281281
// This MUST NOT create a broken backup file that then jabref wants to "restore" from?

jabgui/src/main/java/org/jabref/gui/desktop/os/Linux.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ private void nativeOpenFile(String filePath) {
4747
String[] cmd = {"xdg-open", filePath};
4848
Runtime.getRuntime().exec(cmd);
4949
} catch (Exception e2) {
50-
LoggerFactory.getLogger(Linux.class).warn("Open operation not isSuccessful: ", e2);
50+
LoggerFactory.getLogger(Linux.class).warn("Open operation not successful: ", e2);
5151
}
5252
} catch (IOException e) {
53-
LoggerFactory.getLogger(Linux.class).warn("Native open operation not isSuccessful: ", e);
53+
LoggerFactory.getLogger(Linux.class).warn("Native open operation not successful: ", e);
5454
}
5555
});
5656
}

jabgui/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* when closing a database or quitting the applications.
5353
* <p>
5454
* The save operation is loaded off of the GUI thread using {@link BackgroundTask}. Callers can query whether the
55-
* operation was canceled, or whether it was isSuccessful.
55+
* operation was canceled, or whether it was successful.
5656
*/
5757
public class SaveDatabaseAction {
5858
private static final Logger LOGGER = LoggerFactory.getLogger(SaveDatabaseAction.class);
@@ -134,8 +134,8 @@ public void saveSelectedAsPlain() {
134134

135135
/**
136136
* @param file the new file name to save the database to. This is stored in the database context of the panel upon
137-
* isSuccessful save.
138-
* @return true on isSuccessful save
137+
* successful save.
138+
* @return true on successful save
139139
*/
140140
boolean saveAs(Path file, SaveDatabaseMode mode) {
141141
BibDatabaseContext context = libraryTab.getBibDatabaseContext();

jabgui/src/main/java/org/jabref/gui/git/GitConflictResolverViaDialog.java renamed to jabgui/src/main/java/org/jabref/gui/git/GitConflictResolverDialog.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
import org.jabref.gui.mergeentries.newmergedialog.diffhighlighter.DiffHighlighter;
99
import org.jabref.gui.mergeentries.newmergedialog.toolbar.ThreeWayMergeToolbar;
1010
import org.jabref.gui.preferences.GuiPreferences;
11+
import org.jabref.logic.git.conflicts.GitConflictResolver;
1112
import org.jabref.logic.git.conflicts.ThreeWayEntryConflict;
1213
import org.jabref.model.entry.BibEntry;
1314

1415
/**
1516
* UI wrapper
1617
* Receives a semantic conflict (ThreeWayEntryConflict), pops up an interactive GUI (belonging to mergeentries), and returns a user-confirmed BibEntry merge result.
1718
*/
18-
public class GitConflictResolverViaDialog implements GitConflictResolver {
19+
public class GitConflictResolverDialog implements GitConflictResolver {
1920
private final DialogService dialogService;
2021
private final GuiPreferences preferences;
2122

22-
public GitConflictResolverViaDialog(DialogService dialogService, GuiPreferences preferences) {
23+
public GitConflictResolverDialog(DialogService dialogService, GuiPreferences preferences) {
2324
this.dialogService = dialogService;
2425
this.preferences = preferences;
2526
}

jabgui/src/main/java/org/jabref/gui/git/GitPullAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void execute() {
5555
try {
5656
GitPullViewModel viewModel = new GitPullViewModel(
5757
guiPreferences.getImportFormatPreferences(),
58-
new GitConflictResolverViaDialog(dialogService, guiPreferences),
58+
new GitConflictResolverDialog(dialogService, guiPreferences),
5959
dialogService
6060
);
6161
MergeResult result = viewModel.pull(bibFilePath);

jabgui/src/main/java/org/jabref/gui/git/GitPullViewModel.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import org.jabref.gui.AbstractViewModel;
1010
import org.jabref.gui.DialogService;
1111
import org.jabref.logic.JabRefException;
12+
import org.jabref.logic.git.GitConflictResolver;
1213
import org.jabref.logic.git.GitHandler;
14+
import org.jabref.logic.git.conflicts.GitConflictResolver;
1315
import org.jabref.logic.git.conflicts.SemanticConflictDetector;
1416
import org.jabref.logic.git.conflicts.ThreeWayEntryConflict;
1517
import org.jabref.logic.git.io.GitBibParser;
@@ -29,31 +31,30 @@
2931
import org.eclipse.jgit.api.errors.GitAPIException;
3032
import org.eclipse.jgit.revwalk.RevCommit;
3133

32-
/**
33-
* ViewModel responsible for coordinating UI-bound Git Pull workflow,
34-
* including conflict resolution.
35-
*/
3634
public class GitPullViewModel extends AbstractViewModel {
3735
private final ImportFormatPreferences importFormatPreferences;
3836
private final GitConflictResolver conflictResolver;
3937
private final DialogService dialogService;
38+
private final GitHandler gitHandler;
39+
private final GitStatusViewModel gitStatusViewModel;
40+
private final Path bibFilePath;
4041

4142
public GitPullViewModel(ImportFormatPreferences importFormatPreferences,
42-
GitConflictResolver conflictResolver,
43-
DialogService dialogService) {
43+
GitConflictResolver conflictResolver,
44+
DialogService dialogService,
45+
GitHandler gitHandler,
46+
GitStatusViewModel gitStatusViewModel) {
4447
this.importFormatPreferences = importFormatPreferences;
4548
this.conflictResolver = conflictResolver;
4649
this.dialogService = dialogService;
50+
this.gitHandler = gitHandler;
51+
this.gitStatusViewModel = gitStatusViewModel;
52+
this.bibFilePath = gitStatusViewModel.getCurrentBibFile();
4753
}
4854

49-
public MergeResult pull(Path bibFilePath) throws IOException, GitAPIException, JabRefException {
55+
public MergeResult pull() throws IOException, GitAPIException, JabRefException {
5056
// Open the Git repository from the parent folder of the .bib file
51-
Git git = Git.open(bibFilePath.getParent().toFile());
52-
53-
// Fetch latest changes from remote
54-
// TODO: Temporary — GitHandler should be injected from GitStatusViewModel once centralized git status is implemented.
55-
GitHandler gitHandler = GitHandler.fromAnyPath(bibFilePath)
56-
.orElseThrow(() -> new IllegalStateException("Not inside a Git repository"));
57+
Git git = Git.open(gitHandler.getRepositoryPathAsFile());
5758

5859
gitHandler.fetchOnCurrentBranch();
5960

@@ -66,12 +67,12 @@ public MergeResult pull(Path bibFilePath) throws IOException, GitAPIException, J
6667
RevCommit remoteCommit = triple.remote();
6768

6869
// Ensure file is inside the Git working tree
69-
Path bibPath = bibFilePath.toRealPath();
70-
Path workTree = git.getRepository().getWorkTree().toPath().toRealPath();
71-
if (!bibPath.startsWith(workTree)) {
72-
throw new IllegalStateException("Given .bib file is not inside repository");
70+
Path repoRoot = gitHandler.getRepositoryPathAsFile().toPath().toRealPath();
71+
Path resolvedBibPath = bibFilePath.toRealPath();
72+
if (!resolvedBibPath.startsWith(repoRoot)) {
73+
throw new JabRefException("The provided .bib file is not inside the Git repository.");
7374
}
74-
Path relativePath = workTree.relativize(bibPath);
75+
Path relativePath = repoRoot.relativize(resolvedBibPath);
7576

7677
// 1. Load three versions
7778
String baseContent = GitFileReader.readFileFromCommit(git, baseCommit, relativePath);
@@ -112,6 +113,8 @@ public MergeResult pull(Path bibFilePath) throws IOException, GitAPIException, J
112113

113114
// Create Git commit for the merged result
114115
gitHandler.createCommitOnCurrentBranch("Auto-merged by JabRef", true);
116+
117+
gitStatusViewModel.updateStatusFromPath(bibFilePath);
115118
return MergeResult.success();
116119
}
117120
}

jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBaseConnect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public String toString() {
173173
* <p>
174174
* If there is a single document to choose from, selects that. If there are more than one, shows selection dialog. If there are none, throws NoDocumentFoundException
175175
* <p>
176-
* After isSuccessful selection connects to the selected document and extracts some frequently used parts (starting points for managing its content).
176+
* After successful selection connects to the selected document and extracts some frequently used parts (starting points for managing its content).
177177
* <p>
178178
* Finally initializes this.xTextDocument with the selected document and parts extracted.
179179
*/

jabgui/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
/**
3636
* This offers the user to connect to a remove SQL database.
37-
* Moreover, it directly opens the shared database after isSuccessful connection.
37+
* Moreover, it directly opens the shared database after successful connection.
3838
*/
3939
public class SharedDatabaseLoginDialogView extends BaseDialog<Void> {
4040
@FXML private ComboBox<DBMSType> databaseType;

jablib/src/main/java/org/jabref/logic/bibtex/comparator/EntryComparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public int compare(BibEntry e1, BibEntry e2) {
8686
try {
8787
int i1 = Integer.parseInt((String) f1);
8888
int i2 = Integer.parseInt((String) f2);
89-
// Ok, parsing was isSuccessful. Update f1 and f2:
89+
// Ok, parsing was successful. Update f1 and f2:
9090
f1 = i1;
9191
f2 = i2;
9292
} catch (NumberFormatException ex) {

0 commit comments

Comments
 (0)