Claudenw commented on code in PR #433: URL: https://github.com/apache/creadur-rat/pull/433#discussion_r2111851813
########## apache-rat-core/src/test/java/org/apache/rat/config/exclusion/fileProcessors/GitIgnoreBuilderTest.java: ########## @@ -125,13 +135,56 @@ public void test_RAT_335() { DocumentName candidate = DocumentName.builder() .setName("/home/claude/apache/creadur-rat/apache-rat-core/target/test-classes/GitIgnoreBuilderTest/src/dir1/file1.log") .setBaseName("home/claude/apache/creadur-rat/apache-rat-core/target/test-classes/GitIgnoreBuilderTest/src/").build(); - System.out.println("Decomposition for "+candidate); + System.out.println("Decomposition for " + candidate); Review Comment: Remove these lines. They are junk I missed before. ########## apache-rat-core/src/test/java/org/apache/rat/config/exclusion/fileProcessors/GitIgnoreBuilderTest.java: ########## @@ -125,13 +135,56 @@ public void test_RAT_335() { DocumentName candidate = DocumentName.builder() .setName("/home/claude/apache/creadur-rat/apache-rat-core/target/test-classes/GitIgnoreBuilderTest/src/dir1/file1.log") .setBaseName("home/claude/apache/creadur-rat/apache-rat-core/target/test-classes/GitIgnoreBuilderTest/src/").build(); - System.out.println("Decomposition for "+candidate); + System.out.println("Decomposition for " + candidate); assertThat(matcher.toString()).isEqualTo("matcherSet(or('included dir1/.gitignore', 'included .gitignore'), or('excluded dir1/.gitignore', **/.gitignore, 'excluded .gitignore'))"); - List<String> notMatching = Arrays.asList("README.txt", "dir1/dir1.md", "dir2/dir2.txt", "dir3/file3.log", "dir1/file1.log"); + // files that should be checked: + List<String> notMatching = Arrays.asList("README.txt", "dir1/dir1.md", "dir2/dir2.txt", "dir3/file3.log", "dir1/file1.log", "local-should-precede-global.xml"); + + // files that should be ignored: + List<String> matching = Arrays.asList(".gitignore", "root.md", "dir1/.gitignore", "dir1/dir1.txt", "dir2/dir2.md", "dir3/dir3.log", "local-should-precede-global.md"); + + assertCorrect(matcherSets, documentName.getBaseDocumentName(), matching, notMatching); + } + + /** + * Test that exclusions from a global gitignore are also applied + * + * https://issues.apache.org/jira/browse/RAT-473 + */ + @Test + public void test_global_gitignore() { + GitIgnoreBuilder underTest = new GitIgnoreBuilder() { + @Override + protected Optional<File> globalGitIgnore() { + URL globalGitIgnoreUrl = GitIgnoreBuilderTest.class.getClassLoader().getResource("GitIgnoreBuilderTest/global-gitignore"); + String globalGitIgnore = globalGitIgnoreUrl.getFile(); + + return Optional.of(new File(globalGitIgnore)); + } + }; + URL url = GitIgnoreBuilderTest.class.getClassLoader().getResource("GitIgnoreBuilderTest/src/"); + File file = new File(url.getFile()); + + DocumentName documentName = DocumentName.builder(file).build(); + List<MatcherSet> matcherSets = underTest.build(documentName); + DocumentNameMatcher matcher = MatcherSet.merge(matcherSets).createMatcher(); + + DocumentName candidate = DocumentName.builder() + .setName("/home/claude/apache/creadur-rat/apache-rat-core/target/test-classes/GitIgnoreBuilderTest/src/dir1/file1.log") + .setBaseName("home/claude/apache/creadur-rat/apache-rat-core/target/test-classes/GitIgnoreBuilderTest/src/").build(); + System.out.println("Decomposition for " + candidate); Review Comment: Remove these lines. They are junk I missed deleting before. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@creadur.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org