Skip to content

Add feature to merge .bib files into current bib #13320

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void mergeBibFilesIntoCurrentBib(Path directory, BibDatabaseContext conte
try {
result = OpenDatabase.loadDatabase(path, preferences.getImportFormatPreferences(), fileUpdateMonitor);
} catch (IOException e) {
LOGGER.error("Could not load file '{}': {}", path, e.getMessage());
LOGGER.error("Could not load file '{}': {}", path, e.getMessage(), e);
continue;
}
for (BibEntry toMergeEntry : result.getDatabase().getEntries()) {
Expand Down Expand Up @@ -167,7 +167,7 @@ private List<Path> getAllBibFiles(Path directory, Path databasePath) {
)) {
return stream.collect(Collectors.toList());
} catch (IOException e) {
LOGGER.error("Error finding .bib files in '{}': {}", directory.getFileName(), e.getMessage());
LOGGER.error("Error finding .bib files in '{}': {}", directory.getFileName(), e.getMessage(), e);
}
return List.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void sameCitationKeyMergeTest() {
);

action.execute();
assertEquals(1, mockedMergeEntriesAction.constructed().size(), "MergeEntriesAction was not created as expected");
assertEquals(1, mockedMergeEntriesAction.constructed().size(), "Expected 1 MergeEntriesAction instance but found");
}
}

Expand Down Expand Up @@ -250,14 +250,12 @@ public void sameCitationKeyNoMergePreferenceTest() {
@Test
public void duplicateMergeTest() {
BibEntry currentEntry = new BibEntry(StandardEntryType.Article)
.withCitationKey("DIFFERENTCITATIONKEY")
.withCitationKey("DIFFERENT CITATION KEY")
Copy link
Member

@calixtus calixtus Jun 20, 2025

Choose a reason for hiding this comment

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

I don't think bibtex or biblatex allow multiple words as citation keys. The documentation does not say anything about this, but there are hints. I was looking into the source of biber but was not able to quickly locate the parser for citation keys (https://github.com/plk/biber/blob/dev/lib/Biber.pm).
But anyways, please remove whitespaces from the citation key, just to make sure.

Copy link
Member

Choose a reason for hiding this comment

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

Its possible with BibLaTeX: https://tex.stackexchange.com/a/37646/9075

However, it is very seldomly used and we have no proper UI support in JabRef for it.

Copy link
Member

Choose a reason for hiding this comment

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

Neither spaces nor commans are allowed in the key references: https://tex.stackexchange.com/a/271520/9075

.withField(StandardField.AUTHOR, "Foo Bar")
.withField(StandardField.TITLE, "First Article")
.withField(StandardField.JOURNAL, "International Journal of Something")
.withField(StandardField.YEAR, "2023");

currentEntry.setCommentsBeforeEntry("%% Very important paper.\n");

BibDatabase currentDatabase = new BibDatabase();
currentDatabase.insertEntry(currentEntry);
BibDatabaseContext currentContext = new BibDatabaseContext(currentDatabase);
Expand All @@ -277,7 +275,7 @@ public void duplicateMergeTest() {
);

action.execute();
assertEquals(1, mockedMergeEntriesAction.constructed().size(), "MergeEntriesAction was not created as expected");
assertEquals(1, mockedMergeEntriesAction.constructed().size(), "Expected 1 MergeEntriesAction instance but found");
}
}

Expand All @@ -286,14 +284,12 @@ public void duplicateNoMergePreferenceTest() {
when(mergeBibFilesIntoCurrentBibPreferences.shouldMergeSameKeyEntries()).thenReturn(false);
when(mergeBibFilesIntoCurrentBibPreferences.shouldMergeDuplicateEntries()).thenReturn(false);
BibEntry currentEntry = new BibEntry(StandardEntryType.Article)
.withCitationKey("DIFFERENTCITATIONKEY")
.withCitationKey("DIFFERENT CITATION KEY")
.withField(StandardField.AUTHOR, "Foo Bar")
.withField(StandardField.TITLE, "First Article")
.withField(StandardField.JOURNAL, "International Journal of Something")
.withField(StandardField.YEAR, "2023");

currentEntry.setCommentsBeforeEntry("%% Very important paper.\n");

BibDatabase currentDatabase = new BibDatabase();
currentDatabase.insertEntry(currentEntry);
BibDatabaseContext currentContext = new BibDatabaseContext(currentDatabase);
Expand All @@ -316,7 +312,7 @@ public void duplicateNoMergePreferenceTest() {
assertEquals(1, entries.size(), "Should still have one entry");

BibEntry entry1 = entries.stream()
.filter(e -> "DIFFERENTCITATIONKEY".equals(e.getCitationKey().orElse("")))
.filter(e -> "DIFFERENT CITATION KEY".equals(e.getCitationKey().orElse("")))
.findFirst()
.orElseThrow(() -> new AssertionError("Entry 'test1' not found"));

Expand Down