Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f3825cf
Escape literal braces when converting gitignore patterns to globs
Sandeep332005 Nov 1, 2026
fa4b71f
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 1, 2026
f071e9e
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 2, 2026
fe13413
Use JGit IgnoreNode for .gitignore filtering as suggested by reviewer
Sandeep332005 Nov 2, 2026
b96dee0
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 2, 2026
d9f54f3
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 2, 2026
95df3a2
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 3, 2026
1b3333e
Match gitignore paths using path components instead of string replace…
Sandeep332005 Nov 3, 2026
a1f5ee4
Extract default ignore rules and import stream classes
Sandeep332005 Nov 3, 2026
88b72c7
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 3, 2026
00eb285
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 3, 2026
636de64
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 3, 2026
bcc9fd2
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 3, 2026
558a899
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 3, 2026
b50de34
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 4, 2026
d008e24
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 4, 2026
0b5fb9c
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 5, 2026
f1075c3
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 5, 2026
6f8e3e6
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 6, 2026
2097521
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 6, 2026
8cf34d8
Let .gitignore negations override default ignore rules
Siedlerchr Nov 6, 2026
979e92d
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 6, 2026
e2b1df8
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 7, 2026
5627ca3
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 7, 2026
5ddc8cf
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 7, 2026
edfcd55
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 7, 2026
313c926
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 8, 2026
3312102
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 8, 2026
dd2db0a
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 8, 2026
4c8ad28
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 9, 2026
741ea56
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 9, 2026
ad9a60a
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 9, 2026
5cc306c
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 10, 2026
d0b1241
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 10, 2026
4fb9b7f
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
Siedlerchr Nov 12, 2026
7406231
fix: preserve nested ignore rules in file search
Siedlerchr Nov 12, 2026
2217d94
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 12, 2026
f080d6a
fix: correct lint violations
Siedlerchr Nov 12, 2026
6ae3fb9
Merge branch 'fix-17546-gitignore-literal-brace' of github.com:Sandee…
Siedlerchr Nov 12, 2026
f1adf20
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 13, 2026
1389916
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 13, 2026
3619f5d
test: serialize simulator model updates
Siedlerchr Nov 13, 2026
89e538e
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 13, 2026
9030714
Merge remote-tracking branch 'upstream/main' into fix-17546-gitignore…
github-actions[bot] Nov 13, 2026
b8da57d
Merge branch 'main' into fix-17546-gitignore-literal-brace
Sandeep332005 Nov 14, 2026
0e73221
Fix Markdown export fixture comparison on Windows
Siedlerchr Nov 14, 2026
a3c867d
Reuse ignore rules during unlinked file searches
Siedlerchr Nov 14, 2026
758a430
Merge branch 'fix-17546-gitignore-literal-brace' of https://github.co…
Siedlerchr Nov 14, 2026
2a0ca2e
Normalize paths when matching ignore rules
Siedlerchr Nov 14, 2026
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where the "Backup found" dialog appeared while another library's tab was selected. [#16919](https://github.com/JabRef/jabref/pull/16919)
- We fixed custom terminal and file browser commands failing when library directories contain spaces. [#12531](https://github.com/JabRef/jabref/issues/12531)
- We fixed an issue where the "Get fulltext" button showed no progress during "Search full text documents online". [#17224](https://github.com/JabRef/jabref/pull/17224)
- We fixed an issue where searching for unlinked files failed when `.gitignore` contained a literal opening brace. [#17546](https://github.com/JabRef/jabref/issues/17546)

### Removed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,68 @@
package org.jabref.gui.externalfiles;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jgit.ignore.IgnoreNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.function.Predicate.not;

public class GitIgnoreFileFilter implements DirectoryStream.Filter<Path> {

private static final Logger LOGGER = LoggerFactory.getLogger(GitIgnoreFileFilter.class);

private final Set<PathMatcher> gitIgnorePatterns;
private final IgnoreNode ignoreNode;
private final Path baseDir;

public GitIgnoreFileFilter(Path path) {
Path currentPath = path;
while ((currentPath != null) && !Files.exists(currentPath.resolve(".gitignore"))) {
currentPath = currentPath.getParent();
}

this.ignoreNode = new IgnoreNode();

if (currentPath == null) {
// we did not find any gitignore, set baseDir to provided path and use default ignores
this.baseDir = path;
gitIgnorePatterns = Set.of(".git", ".DS_Store", "desktop.ini", "Thumbs.db").stream()
// duplicate code as below
.map(line -> "glob:" + line)
.map(matcherString -> FileSystems.getDefault().getPathMatcher(matcherString))
.collect(Collectors.toSet());
// Add default ignores
try (java.io.ByteArrayInputStream input = new java.io.ByteArrayInputStream(
".git\n.DS_Store\ndesktop.ini\nThumbs.db\n.gitignore\n".getBytes(java.nio.charset.StandardCharsets.UTF_8))) {
ignoreNode.parse(input);
} catch (IOException e) {
LOGGER.info("Could not parse default ignores", e);
}
} else {
this.baseDir = currentPath;
Path gitIgnore = currentPath.resolve(".gitignore");
Set<PathMatcher> patterns;
try {
patterns = Files.readAllLines(gitIgnore).stream()
.map(String::trim)
.filter(not(String::isEmpty))
.filter(line -> !line.startsWith("#"))
// expand patterns so that leading "**/" also matches files in the base directory
.flatMap(line -> {
if (line.startsWith("**/")) {
return Stream.of(line, line.substring(3));
}
return Stream.of(line);
})
// convert to Java syntax for Glob patterns
.map(line -> "glob:" + line)
.map(matcherString -> FileSystems.getDefault().getPathMatcher(matcherString))
.collect(Collectors.toSet());
// we want to ignore ".gitignore" itself
patterns.add(FileSystems.getDefault().getPathMatcher("glob:.gitignore"));
try (InputStream input = Files.newInputStream(gitIgnore)) {
ignoreNode.parse(input);

@doraem-on doraem-on Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we keep the parent’s !desktop.ini rule active when a subdirectory has its own .gitignore

} catch (IOException e) {
LOGGER.info("Could not read .gitignore from {}", gitIgnore, e);
patterns = Set.of();
}
gitIgnorePatterns = patterns;
// Always ignore .gitignore itself and common defaults
try (java.io.ByteArrayInputStream input = new java.io.ByteArrayInputStream(
".gitignore\n.git\n.DS_Store\ndesktop.ini\nThumbs.db\n".getBytes(java.nio.charset.StandardCharsets.UTF_8))) {
Comment thread
Sandeep332005 marked this conversation as resolved.
Resolved
ignoreNode.parse(input);
} catch (IOException e) {
LOGGER.info("Could not add default ignores", e);
Comment thread
Sandeep332005 marked this conversation as resolved.
Resolved
}
}
}

@Override
public boolean accept(Path path) throws IOException {
// Match patterns relative to baseDir because .gitignore patterns are applied relative to their location
Path relative = safeRelativize(baseDir, path);
// We assume that git does not stop at a pattern, but tries all. We implement that behavior
return gitIgnorePatterns.stream().noneMatch(filter ->
// for patterns like "*.png" or ".gitignore"
filter.matches(relative.getFileName()) ||
// for patterns like "ignore/*" or "**/*.png"
filter.matches(relative));
String relativeStr = relative.toString().replace('\\', '/');
Comment thread
Sandeep332005 marked this conversation as resolved.
Resolved
if (relativeStr.isEmpty()) {
return true;
}
boolean isDirectory = Files.isDirectory(path);

@doraem-on doraem-on Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we pass LinkOption.NOFOLLOW_LINKS here so JGit gets the type of the entry itself

Boolean ignored = ignoreNode.checkIgnored(relativeStr, isDirectory);

@doraem-on doraem-on Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On Windows, *.pdf used to exclude UPPER.PDF too. The new matcher lets it through.....add the Windows behavior and cover the mixed-case extension in a test.

// checkIgnored returns Boolean.TRUE if ignored, Boolean.FALSE if explicitly not ignored, or null if no rule matched
return ignored == null || !ignored;
}

private static Path safeRelativize(Path base, Path child) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,22 @@ void checkDirectoryGitIgnoreSubDir(@TempDir Path dir) throws IOException {
GitIgnoreFileFilter gitIgnoreFileFilter = new GitIgnoreFileFilter(dir);
assertFalse(gitIgnoreFileFilter.accept(subDir.resolve("test.png")));
}

@Test
void acceptsNothingMatchingLiteralOpeningBrace(@TempDir Path dir) throws IOException {
Files.writeString(dir.resolve(".gitignore"), """
notes{draft.pdf
""");
GitIgnoreFileFilter gitIgnoreFileFilter = new GitIgnoreFileFilter(dir);
assertFalse(gitIgnoreFileFilter.accept(dir.resolve("notes{draft.pdf")));
}

@Test
void acceptsOtherFilesWhenPatternContainsLiteralOpeningBrace(@TempDir Path dir) throws IOException {
Files.writeString(dir.resolve(".gitignore"), """
notes{draft.pdf
""");
GitIgnoreFileFilter gitIgnoreFileFilter = new GitIgnoreFileFilter(dir);
assertTrue(gitIgnoreFileFilter.accept(dir.resolve("paper.pdf")));
}
}