Skip to content

Commit

Permalink
fix: Bug in new directory handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbasjes committed Mar 22, 2024
1 parent c82b8da commit a637cfa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void checkIgnoredList(List<String> ignore) {
void testIsIgnoredFile() throws IOException {
GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(testTree)
// .setVerbose(true)
.setAssumeProjectRelativeQueries(true);
.assumeQueriesIncludeProjectBaseDir();

assertFalse(gitIgnoreFileSet.isEmpty(), "Unable to load any .gitignore files");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -175,7 +175,7 @@ private List<File> recursivelyFindFiles(GitIgnoreFileSet gitIgnoreFileSet, File

@Test
void testFileFilter() throws IOException {
GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(testTree).assumeQueriesAreProjectRelative();
GitIgnoreFileSet gitIgnoreFileSet = new GitIgnoreFileSet(testTree).assumeQueriesIncludeProjectBaseDir();

try (Stream<Path> projectFiles = Files.find(testTree.toPath(), 128, (filePath, fileAttr) -> fileAttr.isRegularFile() && gitIgnoreFileSet.ignoreFile(filePath.toString()))) {
List<String> ignored = projectFiles
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit a637cfa

Please sign in to comment.