From 372e04dcf3679a72ec9519ae848f672779a0d8be Mon Sep 17 00:00:00 2001 From: Marc Strapetz Date: Sat, 17 Feb 2018 13:20:46 +0100 Subject: [PATCH] CGitIgnoreTest: also test untracked files Change-Id: I21a4ebd63eaaa85aa2e68f99ef58c141189bdab4 Signed-off-by: Marc Strapetz --- .../eclipse/jgit/ignore/CGitIgnoreTest.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java index ee8191ffc5..aa42e4943b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java @@ -118,20 +118,41 @@ public class CGitIgnoreTest extends RepositoryTestCase { } } - private LinkedHashSet 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 ignored, + LinkedHashSet untracked) throws IOException { // Do a tree walk that does descend into ignored directories and return // a list of all ignored files - LinkedHashSet 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 ignored) throws Exception { @@ -150,9 +171,13 @@ public class CGitIgnoreTest extends RepositoryTestCase { } private void assertSameAsCGit(String... notIgnored) throws Exception { - LinkedHashSet ignored = jgitIgnored(); + LinkedHashSet ignored = new LinkedHashSet<>(); + LinkedHashSet 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)); -- 2.39.5