]> source.dussan.org Git - jgit.git/commitdiff
CGitIgnoreTest: also test untracked files 83/117583/3
authorMarc Strapetz <marc.strapetz@syntevo.com>
Sat, 17 Feb 2018 12:20:46 +0000 (13:20 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 21 Feb 2018 19:50:50 +0000 (14:50 -0500)
Change-Id: I21a4ebd63eaaa85aa2e68f99ef58c141189bdab4
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java

index ee8191ffc57cdd067107c6f276859a09af021107..aa42e4943b329883635998424fef72dc00740f15 100644 (file)
@@ -118,20 +118,41 @@ public class CGitIgnoreTest extends RepositoryTestCase {
                }
        }
 
-       private LinkedHashSet<String> jgitIgnored() throws IOException {
+       private String[] cgitUntracked() throws Exception {
+               FS fs = db.getFS();
+               ProcessBuilder builder = fs.runInShell("git",
+                               new String[] { "ls-files", "--exclude-standard", "-o" });
+               builder.directory(db.getWorkTree());
+               builder.environment().put("HOME", fs.userHome().getAbsolutePath());
+               ExecutionResult result = fs.execute(builder,
+                               new ByteArrayInputStream(new byte[0]));
+               String errorOut = toString(result.getStderr());
+               assertEquals("External git failed", "exit 0\n",
+                               "exit " + result.getRc() + '\n' + errorOut);
+               try (BufferedReader r = new BufferedReader(new InputStreamReader(
+                               new BufferedInputStream(result.getStdout().openInputStream()),
+                               Constants.CHARSET))) {
+                       return r.lines().toArray(String[]::new);
+               }
+       }
+
+       private void jgitIgnoredAndUntracked(LinkedHashSet<String> ignored,
+                       LinkedHashSet<String> untracked) throws IOException {
                // Do a tree walk that does descend into ignored directories and return
                // a list of all ignored files
-               LinkedHashSet<String> result = new LinkedHashSet<>();
                try (TreeWalk walk = new TreeWalk(db)) {
                        walk.addTree(new FileTreeIterator(db));
                        walk.setRecursive(true);
                        while (walk.next()) {
                                if (walk.getTree(WorkingTreeIterator.class).isEntryIgnored()) {
-                                       result.add(walk.getPathString());
+                                       ignored.add(walk.getPathString());
+                               } else {
+                                       // tests of this class won't add any files to the index,
+                                       // hence everything what is not ignored is untracked
+                                       untracked.add(walk.getPathString());
                                }
                        }
                }
-               return result;
        }
 
        private void assertNoIgnoredVisited(Set<String> ignored) throws Exception {
@@ -150,9 +171,13 @@ public class CGitIgnoreTest extends RepositoryTestCase {
        }
 
        private void assertSameAsCGit(String... notIgnored) throws Exception {
-               LinkedHashSet<String> ignored = jgitIgnored();
+               LinkedHashSet<String> ignored = new LinkedHashSet<>();
+               LinkedHashSet<String> untracked = new LinkedHashSet<>();
+               jgitIgnoredAndUntracked(ignored, untracked);
                String[] cgit = cgitIgnored();
+               String[] cgitUntracked = cgitUntracked();
                assertArrayEquals(cgit, ignored.toArray());
+               assertArrayEquals(cgitUntracked, untracked.toArray());
                for (String notExcluded : notIgnored) {
                        assertFalse("File " + notExcluded + " should not be ignored",
                                        ignored.contains(notExcluded));