diff options
author | Marc Strapetz <marc.strapetz@syntevo.com> | 2018-02-17 13:20:46 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2018-02-21 14:50:50 -0500 |
commit | 372e04dcf3679a72ec9519ae848f672779a0d8be (patch) | |
tree | b857b4161ee22ee42ea316210f942147bbf1bc47 | |
parent | d0fbaf502e5d46c9f19b2c0c5e94ad68b3557670 (diff) | |
download | jgit-372e04dcf3679a72ec9519ae848f672779a0d8be.tar.gz jgit-372e04dcf3679a72ec9519ae848f672779a0d8be.zip |
CGitIgnoreTest: also test untracked files
Change-Id: I21a4ebd63eaaa85aa2e68f99ef58c141189bdab4
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java | 35 |
1 files 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<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)); |