From a637cfa52e963a89c46beb030a085a7c075db646 Mon Sep 17 00:00:00 2001 From: Niels Basjes Date: Fri, 22 Mar 2024 23:53:30 +0100 Subject: [PATCH] fix: Bug in new directory handling --- CHANGELOG.md | 4 ++++ .../main/java/nl/basjes/gitignore/GitIgnoreFileSet.java | 2 +- .../test/java/nl/basjes/gitignore/TestGitIgnoreFiles.java | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e92129f..fd0cada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ This is intended as an overview of the major changes +v1.5.1 +=== +- Fix bug in new directory handling + v1.5.0 === - Handle filenames better (project relative vs full path) diff --git a/gitignore-reader/src/main/java/nl/basjes/gitignore/GitIgnoreFileSet.java b/gitignore-reader/src/main/java/nl/basjes/gitignore/GitIgnoreFileSet.java index 3432de1..c5a2d1d 100644 --- a/gitignore-reader/src/main/java/nl/basjes/gitignore/GitIgnoreFileSet.java +++ b/gitignore-reader/src/main/java/nl/basjes/gitignore/GitIgnoreFileSet.java @@ -121,7 +121,7 @@ public void add(final GitIgnore gitIgnore) { */ public void addGitIgnoreFile(final File gitIgnoreFile) { try { - add(new GitIgnore(gitIgnoreFile.getParent(), gitIgnoreFile)); + add(new GitIgnore(getProjectRelative(gitIgnoreFile.getParent()), gitIgnoreFile)); } catch (IOException e) { LOG.error("Cannot read {} due to {}. Will skip this file.", gitIgnoreFile, e.getMessage()); } diff --git a/gitignore-reader/src/test/java/nl/basjes/gitignore/TestGitIgnoreFiles.java b/gitignore-reader/src/test/java/nl/basjes/gitignore/TestGitIgnoreFiles.java index 45f89e0..4c81ef7 100644 --- a/gitignore-reader/src/test/java/nl/basjes/gitignore/TestGitIgnoreFiles.java +++ b/gitignore-reader/src/test/java/nl/basjes/gitignore/TestGitIgnoreFiles.java @@ -69,7 +69,7 @@ private void checkIgnoredList(List ignore) { void testIsIgnoredFile() throws IOException { GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(testTree) // .setVerbose(true) - .setAssumeProjectRelativeQueries(true); + .assumeQueriesIncludeProjectBaseDir(); assertFalse(gitIgnoreFileSet.isEmpty(), "Unable to load any .gitignore files"); @@ -100,7 +100,7 @@ void testIsIgnoredFile() throws IOException { void testIgnoreFile() throws IOException { GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(testTree) .setVerbose(true) - .setAssumeProjectRelativeQueries(true); + .assumeQueriesIncludeProjectBaseDir(); assertFalse(gitIgnoreFileSet.isEmpty(), "Unable to load any .gitignore files"); @@ -175,7 +175,7 @@ private List recursivelyFindFiles(GitIgnoreFileSet gitIgnoreFileSet, File @Test void testFileFilter() throws IOException { - GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(testTree).assumeQueriesAreProjectRelative(); + GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(testTree).assumeQueriesIncludeProjectBaseDir(); try (Stream projectFiles = Files.find(testTree.toPath(), 128, (filePath, fileAttr) -> fileAttr.isRegularFile() && gitIgnoreFileSet.ignoreFile(filePath.toString()))) { List ignored = projectFiles @@ -272,7 +272,7 @@ void testErrorHandlingNosuchDirectory() { @Test void testErrorHandlingNosuchFile() { GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(new File("src/test/resources/"), false); - gitIgnoreFileSet.addGitIgnoreFile(new File("/no-such-file-really")); + gitIgnoreFileSet.addGitIgnoreFile(new File("src/test/resources/no-such-file-really")); assertTrue(gitIgnoreFileSet.isEmpty()); }