protected String CONTENT_MIXED;
- private TreeWalk walk;
-
/** work tree root .gitattributes */
private File dotGitattributes;
private void collectRepositoryState() throws Exception {
dirCache = db.readDirCache();
- walk = beginWalk();
- if (dotGitattributes != null)
- collectEntryContentAndAttributes(F, ".gitattributes", null);
- collectEntryContentAndAttributes(F, fileCRLF.getName(), entryCRLF);
- collectEntryContentAndAttributes(F, fileLF.getName(), entryLF);
- collectEntryContentAndAttributes(F, fileMixed.getName(), entryMixed);
- endWalk();
- }
-
- private TreeWalk beginWalk() throws Exception {
- TreeWalk newWalk = new TreeWalk(db);
- newWalk.addTree(new FileTreeIterator(db));
- newWalk.addTree(new DirCacheIterator(db.readDirCache()));
- return newWalk;
- }
-
- private void endWalk() throws IOException {
- assertFalse("Not all files tested", walk.next());
+ try (TreeWalk walk = new TreeWalk(db)) {
+ walk.addTree(new FileTreeIterator(db));
+ walk.addTree(new DirCacheIterator(db.readDirCache()));
+ if (dotGitattributes != null) {
+ collectEntryContentAndAttributes(walk, F, ".gitattributes",
+ null);
+ }
+ collectEntryContentAndAttributes(walk, F, fileCRLF.getName(),
+ entryCRLF);
+ collectEntryContentAndAttributes(walk, F, fileLF.getName(),
+ entryLF);
+ collectEntryContentAndAttributes(walk, F, fileMixed.getName(),
+ entryMixed);
+ assertFalse("Not all files tested", walk.next());
+ }
}
- private void collectEntryContentAndAttributes(FileMode type, String pathName,
+ private void collectEntryContentAndAttributes(TreeWalk walk, FileMode type,
+ String pathName,
ActualEntry e) throws IOException {
assertTrue("walk has entry", walk.next());
private static final FileMode F = FileMode.REGULAR_FILE;
- private TreeWalk walk;
-
@Test
public void testExpandNonMacro1() throws Exception {
setupRepo(null, null, null, "*.txt text");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("text"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("text"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testExpandNonMacro2() throws Exception {
setupRepo(null, null, null, "*.txt -text");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("-text"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("-text"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testExpandNonMacro3() throws Exception {
setupRepo(null, null, null, "*.txt !text");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs(""));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs(""));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testExpandNonMacro4() throws Exception {
setupRepo(null, null, null, "*.txt text=auto");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("text=auto"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("text=auto"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testExpandBuiltInMacro1() throws Exception {
setupRepo(null, null, null, "*.txt binary");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("binary -diff -merge -text"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt",
+ attrs("binary -diff -merge -text"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testExpandBuiltInMacro2() throws Exception {
setupRepo(null, null, null, "*.txt -binary");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("-binary diff merge text"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt",
+ attrs("-binary diff merge text"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testExpandBuiltInMacro3() throws Exception {
setupRepo(null, null, null, "*.txt !binary");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs(""));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs(""));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo(
"[attr]foo a -b !c d=e", null, null, "*.txt foo");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("foo a -b d=e"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("foo a -b d=e"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testCustomGlobalMacro2() throws Exception {
setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt -foo");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("-foo -a b d=e"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("-foo -a b d=e"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testCustomGlobalMacro3() throws Exception {
setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt !foo");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs(""));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs(""));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testCustomGlobalMacro4() throws Exception {
setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt foo=bar");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("foo=bar a -b d=bar"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("foo=bar a -b d=bar"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo("[attr]foo bar1",
"[attr]foo bar2", null, "*.txt foo");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("foo bar2"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("foo bar2"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
null,
"[attr]foo bar3", "*.txt foo");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("foo bar3"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("foo bar3"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo("[attr]foo bar1",
"[attr]foo bar2", "[attr]foo bar3", "*.txt foo");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("foo bar2"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("foo bar2"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
"[attr]foo x bar -foo",
null, null, "*.txt foo");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("foo x bar"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("foo x bar"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo(
"[attr]foo x -bar\n[attr]bar y -foo", null, null, "*.txt foo");
- walk = beginWalk();
- assertIteration(D, "sub");
- assertIteration(F, "sub/.gitattributes");
- assertIteration(F, "sub/a.txt", attrs("foo x -bar -y"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/.gitattributes");
+ assertIteration(walk, F, "sub/a.txt", attrs("foo x -bar -y"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
// apply to any of the files here. It would match for a
// further subdirectory sub/sub. The sub/ rules must match
// only for directories.
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "sub", attrs("global"));
- assertIteration(F, "sub/.gitattributes", attrs("init top_sub"));
- assertIteration(F, "sub/a.txt", attrs("init foo top top_sub"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "sub", attrs("global"));
+ assertIteration(walk, F, "sub/.gitattributes",
+ attrs("init top_sub"));
+ assertIteration(walk, F, "sub/a.txt",
+ attrs("init foo top top_sub"));
+ assertFalse("Not all files tested", walk.next());
+ }
// All right, let's see that they *do* apply in sub/sub:
writeTrashFile("sub/sub/b.txt", "b");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "sub", attrs("global"));
- assertIteration(F, "sub/.gitattributes", attrs("init top_sub"));
- assertIteration(F, "sub/a.txt", attrs("init foo top top_sub"));
- assertIteration(D, "sub/sub", attrs("init subsub2 top_sub global"));
- assertIteration(F, "sub/sub/b.txt",
- attrs("init foo subsub top top_sub"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "sub", attrs("global"));
+ assertIteration(walk, F, "sub/.gitattributes",
+ attrs("init top_sub"));
+ assertIteration(walk, F, "sub/a.txt",
+ attrs("init foo top top_sub"));
+ assertIteration(walk, D, "sub/sub",
+ attrs("init subsub2 top_sub global"));
+ assertIteration(walk, F, "sub/sub/b.txt",
+ attrs("init foo subsub top top_sub"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/b.jar", "bj");
writeTrashFile("sub/b.xml", "bx");
// On foo.xml/bar.jar we must not have 'xml'
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo.xml", attrs("xml"));
- assertIteration(F, "foo.xml/bar.jar", attrs("jar"));
- assertIteration(F, "foo.xml/bar.xml", attrs("xml"));
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(F, "sub/b.jar", attrs("jar"));
- assertIteration(F, "sub/b.xml", attrs("xml"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo.xml", attrs("xml"));
+ assertIteration(walk, F, "foo.xml/bar.jar", attrs("jar"));
+ assertIteration(walk, F, "foo.xml/bar.xml", attrs("xml"));
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, F, "sub/b.jar", attrs("jar"));
+ assertIteration(walk, F, "sub/b.xml", attrs("xml"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/b.jar", "bj");
writeTrashFile("sub/b.xml", "bx");
writeTrashFile("sub/foo/b.jar", "bf");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo", attrs("xml"));
- assertIteration(F, "foo/bar.jar", attrs("jar"));
- assertIteration(F, "foo/bar.xml");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(F, "sub/b.jar", attrs("jar"));
- assertIteration(F, "sub/b.xml");
- assertIteration(D, "sub/foo", attrs("sub xml"));
- assertIteration(F, "sub/foo/b.jar", attrs("jar"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo", attrs("xml"));
+ assertIteration(walk, F, "foo/bar.jar", attrs("jar"));
+ assertIteration(walk, F, "foo/bar.xml");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, F, "sub/b.jar", attrs("jar"));
+ assertIteration(walk, F, "sub/b.xml");
+ assertIteration(walk, D, "sub/foo", attrs("sub xml"));
+ assertIteration(walk, F, "sub/foo/b.jar", attrs("jar"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/b.xml", "bx");
writeTrashFile("sub/foo/b.jar", "bf");
// On foo.xml/bar.jar we must not have 'xml'
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(F, "foo/bar.jar", attrs("jar xml"));
- assertIteration(F, "foo/bar.xml", attrs("xml"));
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(F, "sub/b.jar", attrs("jar"));
- assertIteration(F, "sub/b.xml");
- assertIteration(D, "sub/foo");
- assertIteration(F, "sub/foo/b.jar", attrs("jar"));
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, F, "foo/bar.jar", attrs("jar xml"));
+ assertIteration(walk, F, "foo/bar.xml", attrs("xml"));
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, F, "sub/b.jar", attrs("jar"));
+ assertIteration(walk, F, "sub/b.xml");
+ assertIteration(walk, D, "sub/foo");
+ assertIteration(walk, F, "sub/foo/b.jar", attrs("jar"));
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/a.txt", "1");
writeTrashFile("foo/sext", "2");
writeTrashFile("foo/s.txt", "3");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(F, "foo/s.txt", attrs("bar"));
- assertIteration(F, "foo/sext", attrs("bar"));
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, F, "foo/s.txt", attrs("bar"));
+ assertIteration(walk, F, "foo/sext", attrs("bar"));
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
public void testPrefixMatchNot() throws Exception {
setupRepo(null, null, "sub/new bar", null);
writeTrashFile("sub/new/foo.txt", "1");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo(null, null, "s[t-v]b/n[de]w bar", null);
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("sub/ndw", "2");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(F, "sub/ndw", attrs("bar"));
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, F, "sub/ndw", attrs("bar"));
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo(null, null, "sub/new/* bar", null);
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("sub/new/lower/foo.txt", "2");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new");
- assertIteration(F, "sub/new/foo.txt", attrs("bar"));
- assertIteration(D, "sub/new/lower", attrs("bar"));
- assertIteration(F, "sub/new/lower/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new");
+ assertIteration(walk, F, "sub/new/foo.txt", attrs("bar"));
+ assertIteration(walk, D, "sub/new/lower", attrs("bar"));
+ assertIteration(walk, F, "sub/new/lower/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("sub/sub/new/foo.txt", "3");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(D, "foo/sub");
- assertIteration(D, "foo/sub/new");
- assertIteration(F, "foo/sub/new/foo.txt");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- assertIteration(D, "sub/sub");
- assertIteration(D, "sub/sub/new");
- assertIteration(F, "sub/sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, D, "foo/sub");
+ assertIteration(walk, D, "foo/sub/new");
+ assertIteration(walk, F, "foo/sub/new/foo.txt");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertIteration(walk, D, "sub/sub");
+ assertIteration(walk, D, "sub/sub/new");
+ assertIteration(walk, F, "sub/sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo(null, null, "**/sub/new/ bar", null);
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(D, "foo/sub");
- assertIteration(D, "foo/sub/new", attrs("bar"));
- assertIteration(F, "foo/sub/new/foo.txt");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, D, "foo/sub");
+ assertIteration(walk, D, "foo/sub/new", attrs("bar"));
+ assertIteration(walk, F, "foo/sub/new/foo.txt");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("sub/sub/new/foo.txt", "3");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(D, "foo/sub");
- assertIteration(D, "foo/sub/new", attrs("bar"));
- assertIteration(F, "foo/sub/new/foo.txt");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- assertIteration(D, "sub/sub");
- assertIteration(D, "sub/sub/new", attrs("bar"));
- assertIteration(F, "sub/sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, D, "foo/sub");
+ assertIteration(walk, D, "foo/sub/new", attrs("bar"));
+ assertIteration(walk, F, "foo/sub/new/foo.txt");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertIteration(walk, D, "sub/sub");
+ assertIteration(walk, D, "sub/sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("sub/sub/new/foo.txt", "3");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(D, "foo/sub");
- assertIteration(D, "foo/sub/new", attrs("bar"));
- assertIteration(F, "foo/sub/new/foo.txt");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- assertIteration(D, "sub/sub");
- assertIteration(D, "sub/sub/new", attrs("bar"));
- assertIteration(F, "sub/sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, D, "foo/sub");
+ assertIteration(walk, D, "foo/sub/new", attrs("bar"));
+ assertIteration(walk, F, "foo/sub/new/foo.txt");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertIteration(walk, D, "sub/sub");
+ assertIteration(walk, D, "sub/sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
setupRepo(null, null, "s[uv]b/n*/ bar", null);
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(D, "foo/sub");
- assertIteration(D, "foo/sub/new");
- assertIteration(F, "foo/sub/new/foo.txt");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, D, "foo/sub");
+ assertIteration(walk, D, "foo/sub/new");
+ assertIteration(walk, F, "foo/sub/new/foo.txt");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("foo/new", "3");
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(D, "foo");
- assertIteration(F, "foo/new");
- assertIteration(D, "foo/sub");
- assertIteration(D, "foo/sub/new", attrs("bar"));
- assertIteration(F, "foo/sub/new/foo.txt");
- assertIteration(D, "sub");
- assertIteration(F, "sub/a.txt");
- assertIteration(D, "sub/new", attrs("bar"));
- assertIteration(F, "sub/new/foo.txt");
- endWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, D, "foo");
+ assertIteration(walk, F, "foo/new");
+ assertIteration(walk, D, "foo/sub");
+ assertIteration(walk, D, "foo/sub/new", attrs("bar"));
+ assertIteration(walk, F, "foo/sub/new/foo.txt");
+ assertIteration(walk, D, "sub");
+ assertIteration(walk, F, "sub/a.txt");
+ assertIteration(walk, D, "sub/new", attrs("bar"));
+ assertIteration(walk, F, "sub/new/foo.txt");
+ assertFalse("Not all files tested", walk.next());
+ }
}
private static Collection<Attribute> attrs(String s) {
return new AttributesRule("*", s).getAttributes();
}
- private void assertIteration(FileMode type, String pathName)
+ private void assertIteration(TreeWalk walk, FileMode type, String pathName)
throws IOException {
- assertIteration(type, pathName, Collections.<Attribute> emptyList());
+ assertIteration(walk, type, pathName,
+ Collections.<Attribute> emptyList());
}
- private void assertIteration(FileMode type, String pathName,
+ private void assertIteration(TreeWalk walk, FileMode type, String pathName,
Collection<Attribute> expectedAttrs) throws IOException {
assertTrue("walk has entry", walk.next());
assertEquals(pathName, walk.getPathString());
newWalk.addTree(new FileTreeIterator(db));
return newWalk;
}
-
- private void endWalk() throws IOException {
- assertFalse("Not all files tested", walk.next());
- }
}
private Git git;
- private TreeWalk walk;
-
@Override
@Before
public void setUp() throws Exception {
// Adds file to index
git.add().addFilepattern(".").call();
- walk = beginWalk();
-
- assertIteration(F, ".gitattributes");
- assertIteration(F, "readme.txt", asList(EOL_LF));
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, F, "readme.txt", asList(EOL_LF));
- assertIteration(D, "src");
+ assertIteration(walk, D, "src");
- assertIteration(D, "src/config");
- assertIteration(F, "src/config/.gitattributes");
- assertIteration(F, "src/config/readme.txt", asList(DELTA_UNSET));
- assertIteration(F, "src/config/windows.file", null);
- assertIteration(F, "src/config/windows.txt", asList(DELTA_UNSET));
+ assertIteration(walk, D, "src/config");
+ assertIteration(walk, F, "src/config/.gitattributes");
+ assertIteration(walk, F, "src/config/readme.txt",
+ asList(DELTA_UNSET));
+ assertIteration(walk, F, "src/config/windows.file", null);
+ assertIteration(walk, F, "src/config/windows.txt",
+ asList(DELTA_UNSET));
- assertIteration(F, "windows.file", null);
- assertIteration(F, "windows.txt", asList(EOL_LF));
+ assertIteration(walk, F, "windows.file", null);
+ assertIteration(walk, F, "windows.txt", asList(EOL_LF));
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
/**
// Adds file to index
git.add().addFilepattern(".").call();
- walk = beginWalk();
- assertIteration(F, "l0.txt");
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, "l0.txt");
- assertIteration(D, "level1");
- assertIteration(F, "level1/l1.txt");
+ assertIteration(walk, D, "level1");
+ assertIteration(walk, F, "level1/l1.txt");
- assertIteration(D, "level1/level2");
- assertIteration(F, "level1/level2/l2.txt");
+ assertIteration(walk, D, "level1/level2");
+ assertIteration(walk, F, "level1/level2/l2.txt");
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
/**
// Adds file to index
git.add().addFilepattern(".").call();
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
- assertIteration(F, "l0.txt");
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, F, "l0.txt");
- assertIteration(D, "level1");
- assertIteration(F, "level1/l1.txt");
+ assertIteration(walk, D, "level1");
+ assertIteration(walk, F, "level1/l1.txt");
- assertIteration(D, "level1/level2");
- assertIteration(F, "level1/level2/l2.txt");
+ assertIteration(walk, D, "level1/level2");
+ assertIteration(walk, F, "level1/level2/l2.txt");
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
// Adds file to index
git.add().addFilepattern(".").call();
- walk = beginWalk();
- assertIteration(F, ".gitattributes");
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
- assertIteration(D, "levelA");
- assertIteration(F, "levelA/.gitattributes");
- assertIteration(F, "levelA/lA.txt");
+ assertIteration(walk, D, "levelA");
+ assertIteration(walk, F, "levelA/.gitattributes");
+ assertIteration(walk, F, "levelA/lA.txt");
- assertIteration(D, "levelB");
- assertIteration(F, "levelB/.gitattributes");
+ assertIteration(walk, D, "levelB");
+ assertIteration(walk, F, "levelB/.gitattributes");
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
// Adds file to index
git.add().addFilepattern(".").call();
- walk = beginWalk();
- assertIteration(F, "gitattributes");
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, "gitattributes");
- assertIteration(F, "l0.txt");
+ assertIteration(walk, F, "l0.txt");
- assertIteration(D, "levelA");
- assertIteration(F, "levelA/file.gitattributes");
- assertIteration(F, "levelA/lA.txt");
+ assertIteration(walk, D, "levelA");
+ assertIteration(walk, F, "levelA/file.gitattributes");
+ assertIteration(walk, F, "levelA/lA.txt");
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
- private void assertIteration(FileMode type, String pathName)
+ private void assertIteration(TreeWalk walk, FileMode type, String pathName)
throws IOException {
- assertIteration(type, pathName, Collections.<Attribute> emptyList());
+ assertIteration(walk, type, pathName,
+ Collections.<Attribute> emptyList());
}
- private void assertIteration(FileMode type, String pathName,
+ private void assertIteration(TreeWalk walk, FileMode type, String pathName,
List<Attribute> nodeAttrs) throws IOException {
assertTrue("walk has entry", walk.next());
assertEquals(pathName, walk.getPathString());
AttributesNode attributesNode = itr.getEntryAttributesNode(db
.newObjectReader());
- assertAttributesNode(pathName, attributesNode, nodeAttrs);
+ assertAttributesNode(walk, pathName, attributesNode, nodeAttrs);
if (D.equals(type))
walk.enterSubtree();
}
- private void assertAttributesNode(String pathName,
+ private void assertAttributesNode(TreeWalk walk, String pathName,
AttributesNode attributesNode, List<Attribute> nodeAttrs)
throws IOException {
if (attributesNode == null)
newWalk.addTree(new DirCacheIterator(db.readDirCache()));
return newWalk;
}
-
- private void endWalk() throws IOException {
- assertFalse("Not all files tested", walk.next());
- }
}
private static Attribute DELTA_UNSET = new Attribute("delta", State.UNSET);
- private TreeWalk walk;
-
@Test
public void testRules() throws Exception {
writeTrashFile("src/config/windows.file", "");
writeTrashFile("src/config/windows.txt", "");
- walk = beginWalk();
-
- assertIteration(F, ".gitattributes");
- assertIteration(F, "global.txt", asList(EOL_LF));
- assertIteration(F, "readme.txt", asList(EOL_LF));
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, F, "global.txt", asList(EOL_LF));
+ assertIteration(walk, F, "readme.txt", asList(EOL_LF));
- assertIteration(D, "src");
+ assertIteration(walk, D, "src");
- assertIteration(D, "src/config");
- assertIteration(F, "src/config/.gitattributes");
- assertIteration(F, "src/config/readme.txt", asList(DELTA_UNSET));
- assertIteration(F, "src/config/windows.file", null);
- assertIteration(F, "src/config/windows.txt", asList(DELTA_UNSET));
+ assertIteration(walk, D, "src/config");
+ assertIteration(walk, F, "src/config/.gitattributes");
+ assertIteration(walk, F, "src/config/readme.txt",
+ asList(DELTA_UNSET));
+ assertIteration(walk, F, "src/config/windows.file", null);
+ assertIteration(walk, F, "src/config/windows.txt",
+ asList(DELTA_UNSET));
- assertIteration(F, "windows.file", null);
- assertIteration(F, "windows.txt", asList(EOL_LF));
+ assertIteration(walk, F, "windows.file", null);
+ assertIteration(walk, F, "windows.txt", asList(EOL_LF));
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
/**
writeTrashFile("level1/l1.txt", "");
writeTrashFile("level1/level2/l2.txt", "");
- walk = beginWalk();
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, "l0.txt");
- assertIteration(F, "l0.txt");
+ assertIteration(walk, D, "level1");
+ assertIteration(walk, F, "level1/l1.txt");
- assertIteration(D, "level1");
- assertIteration(F, "level1/l1.txt");
+ assertIteration(walk, D, "level1/level2");
+ assertIteration(walk, F, "level1/level2/l2.txt");
- assertIteration(D, "level1/level2");
- assertIteration(F, "level1/level2/l2.txt");
-
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
/**
writeTrashFile("level1/l1.txt", "");
writeTrashFile("level1/level2/l2.txt", "");
- walk = beginWalk();
-
- assertIteration(F, ".gitattributes");
- assertIteration(F, "l0.txt");
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
+ assertIteration(walk, F, "l0.txt");
- assertIteration(D, "level1");
- assertIteration(F, "level1/l1.txt");
+ assertIteration(walk, D, "level1");
+ assertIteration(walk, F, "level1/l1.txt");
- assertIteration(D, "level1/level2");
- assertIteration(F, "level1/level2/l2.txt");
+ assertIteration(walk, D, "level1/level2");
+ assertIteration(walk, F, "level1/level2/l2.txt");
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
@Test
writeTrashFile("levelA/lA.txt", "");
- walk = beginWalk();
-
- assertIteration(F, ".gitattributes");
+ try (TreeWalk walk = beginWalk()) {
+ assertIteration(walk, F, ".gitattributes");
- assertIteration(D, "levelA");
- assertIteration(F, "levelA/.gitattributes");
- assertIteration(F, "levelA/lA.txt");
+ assertIteration(walk, D, "levelA");
+ assertIteration(walk, F, "levelA/.gitattributes");
+ assertIteration(walk, F, "levelA/lA.txt");
- assertIteration(D, "levelB");
- assertIteration(F, "levelB/.gitattributes");
+ assertIteration(walk, D, "levelB");
+ assertIteration(walk, F, "levelB/.gitattributes");
- endWalk();
+ assertFalse("Not all files tested", walk.next());
+ }
}
- private void assertIteration(FileMode type, String pathName)
+ private void assertIteration(TreeWalk walk, FileMode type, String pathName)
throws IOException {
- assertIteration(type, pathName, Collections.<Attribute> emptyList());
+ assertIteration(walk, type, pathName,
+ Collections.<Attribute> emptyList());
}
- private void assertIteration(FileMode type, String pathName,
+ private void assertIteration(TreeWalk walk, FileMode type, String pathName,
List<Attribute> nodeAttrs)
throws IOException {
assertTrue("walk has entry", walk.next());
assertNotNull("has tree", itr);
AttributesNode attributesNode = itr.getEntryAttributesNode();
- assertAttributesNode(pathName, attributesNode, nodeAttrs);
+ assertAttributesNode(walk, pathName, attributesNode, nodeAttrs);
if (D.equals(type))
walk.enterSubtree();
}
- private void assertAttributesNode(String pathName,
+ private void assertAttributesNode(TreeWalk walk, String pathName,
AttributesNode attributesNode, List<Attribute> nodeAttrs)
throws IOException {
if (attributesNode == null)
newWalk.addTree(new FileTreeIterator(db));
return newWalk;
}
-
- private void endWalk() throws IOException {
- assertFalse("Not all files tested", walk.next());
- }
}
@Override
@After
public void tearDown() throws Exception {
+ if (walk != null) {
+ walk.close();
+ }
+ if (ci_walk != null) {
+ ci_walk.close();
+ }
super.tearDown();
if (customAttributeFile != null)
customAttributeFile.delete();
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
+import org.junit.After;
import org.junit.Test;
/**
private TreeWalk walk;
+ @After
+ public void closeWalk() {
+ if (walk != null) {
+ walk.close();
+ }
+ }
+
@Test
public void testSimpleRootGitIgnoreGlobalIgnore() throws IOException {
writeIgnoreFile(".gitignore", "x");
boolean merge = twm.merge(new ObjectId[] { O, T });
assertTrue(merge);
- final TreeWalk tw = new TreeWalk(db);
- tw.setRecursive(true);
- tw.reset(twm.getResultTreeId());
+ try (TreeWalk tw = new TreeWalk(db)) {
+ tw.setRecursive(true);
+ tw.reset(twm.getResultTreeId());
- assertTrue(tw.next());
- assertEquals("a", tw.getPathString());
- assertCorrectId(treeO, tw);
+ assertTrue(tw.next());
+ assertEquals("a", tw.getPathString());
+ assertCorrectId(treeO, tw);
- assertTrue(tw.next());
- assertEquals("o", tw.getPathString());
- assertCorrectId(treeO, tw);
+ assertTrue(tw.next());
+ assertEquals("o", tw.getPathString());
+ assertCorrectId(treeO, tw);
- assertTrue(tw.next());
- assertEquals("t", tw.getPathString());
- assertCorrectId(treeT, tw);
+ assertTrue(tw.next());
+ assertEquals("t", tw.getPathString());
+ assertCorrectId(treeT, tw);
- assertFalse(tw.next());
+ assertFalse(tw.next());
+ }
}
@Test
boolean merge = twm.merge(new ObjectId[] { B, T });
assertTrue(merge);
- final TreeWalk tw = new TreeWalk(db);
- tw.setRecursive(true);
- tw.reset(twm.getResultTreeId());
+ try (TreeWalk tw = new TreeWalk(db)) {
+ tw.setRecursive(true);
+ tw.reset(twm.getResultTreeId());
- assertTrue(tw.next());
- assertEquals("a", tw.getPathString());
- assertCorrectId(treeB, tw);
+ assertTrue(tw.next());
+ assertEquals("a", tw.getPathString());
+ assertCorrectId(treeB, tw);
- assertTrue(tw.next());
- assertEquals("t", tw.getPathString());
- assertCorrectId(treeT, tw);
+ assertTrue(tw.next());
+ assertEquals("t", tw.getPathString());
+ assertCorrectId(treeT, tw);
- assertFalse(tw.next());
+ assertFalse(tw.next());
+ }
}
private static void assertCorrectId(DirCache treeT, TreeWalk tw) {
boolean merge = ourMerger.merge(new ObjectId[] { o, t });
assertTrue(merge);
- final TreeWalk tw = new TreeWalk(db);
- tw.setRecursive(true);
- tw.reset(ourMerger.getResultTreeId());
+ try (TreeWalk tw = new TreeWalk(db)) {
+ tw.setRecursive(true);
+ tw.reset(ourMerger.getResultTreeId());
- assertTrue(tw.next());
- assertEquals("Makefile", tw.getPathString());
- assertCorrectId(treeO, tw);
+ assertTrue(tw.next());
+ assertEquals("Makefile", tw.getPathString());
+ assertCorrectId(treeO, tw);
- assertTrue(tw.next());
- assertEquals("libelf-po/a", tw.getPathString());
- assertCorrectId(treeO, tw);
+ assertTrue(tw.next());
+ assertEquals("libelf-po/a", tw.getPathString());
+ assertCorrectId(treeO, tw);
- assertTrue(tw.next());
- assertEquals("libelf/c", tw.getPathString());
- assertCorrectId(treeT, tw);
+ assertTrue(tw.next());
+ assertEquals("libelf/c", tw.getPathString());
+ assertCorrectId(treeT, tw);
- assertFalse(tw.next());
+ assertFalse(tw.next());
+ }
}
@Test
boolean merge = ourMerger.merge(new ObjectId[] { o, t });
assertTrue(merge);
- final TreeWalk tw = new TreeWalk(db);
- tw.setRecursive(true);
- tw.reset(ourMerger.getResultTreeId());
+ try (TreeWalk tw = new TreeWalk(db)) {
+ tw.setRecursive(true);
+ tw.reset(ourMerger.getResultTreeId());
- assertTrue(tw.next());
- assertEquals("d/o", tw.getPathString());
- assertCorrectId(treeO, tw);
+ assertTrue(tw.next());
+ assertEquals("d/o", tw.getPathString());
+ assertCorrectId(treeO, tw);
- assertTrue(tw.next());
- assertEquals("d/t", tw.getPathString());
- assertCorrectId(treeT, tw);
+ assertTrue(tw.next());
+ assertEquals("d/t", tw.getPathString());
+ assertCorrectId(treeT, tw);
- assertFalse(tw.next());
+ assertFalse(tw.next());
+ }
}
@Test
git.add().addFilepattern("file").call();
}
DirCacheEntry dce = db.readDirCache().getEntry("file");
- TreeWalk tw = new TreeWalk(db);
- FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
- .getConfig().get(WorkingTreeOptions.KEY));
- tw.addTree(fti);
- DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
- tw.addTree(dci);
- fti.setDirCacheIterator(tw, 1);
- while (tw.next() && !tw.getPathString().equals("file")) {
- //
- }
- assertEquals(MetadataDiff.EQUAL, fti.compareMetadata(dce));
- ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
- assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
- fromRaw.getName());
- try (ObjectReader objectReader = db.newObjectReader()) {
- assertFalse(fti.isModified(dce, false, objectReader));
+ try (TreeWalk tw = new TreeWalk(db)) {
+ FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(),
+ db.getConfig().get(WorkingTreeOptions.KEY));
+ tw.addTree(fti);
+ DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
+ tw.addTree(dci);
+ fti.setDirCacheIterator(tw, 1);
+ while (tw.next() && !tw.getPathString().equals("file")) {
+ //
+ }
+ assertEquals(MetadataDiff.EQUAL, fti.compareMetadata(dce));
+ ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
+ assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
+ fromRaw.getName());
+ try (ObjectReader objectReader = db.newObjectReader()) {
+ assertFalse(fti.isModified(dce, false, objectReader));
+ }
}
}
assertEquals(1, tree1.getEntryCount());
}
- final TreeWalk tw = new TreeWalk(db);
- tw.addTree(new DirCacheIterator(tree0));
- tw.addTree(new DirCacheIterator(tree1));
-
- assertModes("a", REGULAR_FILE, MISSING, tw);
- assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
- assertModes("a", MISSING, TREE, tw);
- tw.enterSubtree();
- assertModes("a/b", MISSING, REGULAR_FILE, tw);
- assertModes("a0b", SYMLINK, MISSING, tw);
+ try (TreeWalk tw = new TreeWalk(db)) {
+ tw.addTree(new DirCacheIterator(tree0));
+ tw.addTree(new DirCacheIterator(tree1));
+
+ assertModes("a", REGULAR_FILE, MISSING, tw);
+ assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
+ assertModes("a", MISSING, TREE, tw);
+ tw.enterSubtree();
+ assertModes("a/b", MISSING, REGULAR_FILE, tw);
+ assertModes("a0b", SYMLINK, MISSING, tw);
+ }
}
@Test
assertEquals(1, tree1.getEntryCount());
}
- final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
- tw.addTree(new DirCacheIterator(tree0));
- tw.addTree(new DirCacheIterator(tree1));
-
- assertModes("a", REGULAR_FILE, TREE, tw);
- assertTrue(tw.isDirectoryFileConflict());
- assertTrue(tw.isSubtree());
- tw.enterSubtree();
- assertModes("a/b", MISSING, REGULAR_FILE, tw);
- assertTrue(tw.isDirectoryFileConflict());
- assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
- assertFalse(tw.isDirectoryFileConflict());
- assertModes("a0b", SYMLINK, MISSING, tw);
- assertFalse(tw.isDirectoryFileConflict());
+ try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
+ tw.addTree(new DirCacheIterator(tree0));
+ tw.addTree(new DirCacheIterator(tree1));
+
+ assertModes("a", REGULAR_FILE, TREE, tw);
+ assertTrue(tw.isDirectoryFileConflict());
+ assertTrue(tw.isSubtree());
+ tw.enterSubtree();
+ assertModes("a/b", MISSING, REGULAR_FILE, tw);
+ assertTrue(tw.isDirectoryFileConflict());
+ assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ assertModes("a0b", SYMLINK, MISSING, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ }
}
@Test
assertEquals(2, tree1.getEntryCount());
}
- final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
- tw.addTree(new DirCacheIterator(tree0));
- tw.addTree(new DirCacheIterator(tree1));
-
- assertModes("a", REGULAR_FILE, TREE, tw);
- assertTrue(tw.isSubtree());
- assertTrue(tw.isDirectoryFileConflict());
- tw.enterSubtree();
- assertModes("a/b", MISSING, REGULAR_FILE, tw);
- assertTrue(tw.isDirectoryFileConflict());
- assertModes("a.b", EXECUTABLE_FILE, EXECUTABLE_FILE, tw);
- assertFalse(tw.isDirectoryFileConflict());
- assertModes("a0b", SYMLINK, MISSING, tw);
- assertFalse(tw.isDirectoryFileConflict());
+ try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
+ tw.addTree(new DirCacheIterator(tree0));
+ tw.addTree(new DirCacheIterator(tree1));
+
+ assertModes("a", REGULAR_FILE, TREE, tw);
+ assertTrue(tw.isSubtree());
+ assertTrue(tw.isDirectoryFileConflict());
+ tw.enterSubtree();
+ assertModes("a/b", MISSING, REGULAR_FILE, tw);
+ assertTrue(tw.isDirectoryFileConflict());
+ assertModes("a.b", EXECUTABLE_FILE, EXECUTABLE_FILE, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ assertModes("a0b", SYMLINK, MISSING, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ }
}
@Test
assertEquals(3, tree1.getEntryCount());
}
- final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
- tw.addTree(new DirCacheIterator(tree0));
- tw.addTree(new DirCacheIterator(tree1));
-
- assertModes("a", REGULAR_FILE, TREE, tw);
- assertTrue(tw.isSubtree());
- assertTrue(tw.isDirectoryFileConflict());
- tw.enterSubtree();
- assertModes("a/b", MISSING, REGULAR_FILE, tw);
- assertTrue(tw.isDirectoryFileConflict());
- assertModes("a.b", MISSING, EXECUTABLE_FILE, tw);
- assertFalse(tw.isDirectoryFileConflict());
- assertModes("a0b", SYMLINK, SYMLINK, tw);
- assertFalse(tw.isDirectoryFileConflict());
+ try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
+ tw.addTree(new DirCacheIterator(tree0));
+ tw.addTree(new DirCacheIterator(tree1));
+
+ assertModes("a", REGULAR_FILE, TREE, tw);
+ assertTrue(tw.isSubtree());
+ assertTrue(tw.isDirectoryFileConflict());
+ tw.enterSubtree();
+ assertModes("a/b", MISSING, REGULAR_FILE, tw);
+ assertTrue(tw.isDirectoryFileConflict());
+ assertModes("a.b", MISSING, EXECUTABLE_FILE, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ assertModes("a0b", SYMLINK, SYMLINK, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ }
}
@Test
assertEquals(4, tree1.getEntryCount());
}
- final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
- tw.addTree(new DirCacheIterator(tree0));
- tw.addTree(new DirCacheIterator(tree1));
-
- assertModes("0", REGULAR_FILE, REGULAR_FILE, tw);
- assertFalse(tw.isDirectoryFileConflict());
- assertModes("a", REGULAR_FILE, TREE, tw);
- assertTrue(tw.isSubtree());
- assertTrue(tw.isDirectoryFileConflict());
- tw.enterSubtree();
- assertModes("a/b", MISSING, REGULAR_FILE, tw);
- assertTrue(tw.isDirectoryFileConflict());
- assertModes("a/c", MISSING, TREE, tw);
- assertTrue(tw.isDirectoryFileConflict());
- tw.enterSubtree();
- assertModes("a/c/e", MISSING, REGULAR_FILE, tw);
- assertTrue(tw.isDirectoryFileConflict());
-
- assertModes("a.b", MISSING, REGULAR_FILE, tw);
- assertFalse(tw.isDirectoryFileConflict());
+ try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
+ tw.addTree(new DirCacheIterator(tree0));
+ tw.addTree(new DirCacheIterator(tree1));
+
+ assertModes("0", REGULAR_FILE, REGULAR_FILE, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ assertModes("a", REGULAR_FILE, TREE, tw);
+ assertTrue(tw.isSubtree());
+ assertTrue(tw.isDirectoryFileConflict());
+ tw.enterSubtree();
+ assertModes("a/b", MISSING, REGULAR_FILE, tw);
+ assertTrue(tw.isDirectoryFileConflict());
+ assertModes("a/c", MISSING, TREE, tw);
+ assertTrue(tw.isDirectoryFileConflict());
+ tw.enterSubtree();
+ assertModes("a/c/e", MISSING, REGULAR_FILE, tw);
+ assertTrue(tw.isDirectoryFileConflict());
+
+ assertModes("a.b", MISSING, REGULAR_FILE, tw);
+ assertFalse(tw.isDirectoryFileConflict());
+ }
}
private static void assertModes(final String path, final FileMode mode0,
RevCommit commit = writeFileInFolderAndCommit();
deleteAll();
writeFileWithFolderName();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertTrue(treeWalk.next());
- assertEquals("folder", treeWalk.getPathString());
- assertTrue(treeWalk.next());
- assertEquals("folder/file", treeWalk.getPathString());
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertTrue(treeWalk.next());
+ assertEquals("folder", treeWalk.getPathString());
+ assertTrue(treeWalk.next());
+ assertEquals("folder/file", treeWalk.getPathString());
+ assertFalse(treeWalk.next());
+ }
}
@Test
RevCommit commit = writeFileInFolderAndCommit();
deleteAll();
writeFileWithFolderName();
- TreeWalk treeWalk = createNonRecursiveTreeWalk(commit);
-
- assertTrue(treeWalk.next());
- assertEquals("folder", treeWalk.getPathString());
- assertTrue(treeWalk.next());
- assertEquals("folder", treeWalk.getPathString());
- assertTrue(treeWalk.isSubtree());
- treeWalk.enterSubtree();
- assertTrue(treeWalk.next());
- assertEquals("folder/file", treeWalk.getPathString());
- assertFalse(treeWalk.next());
+
+ try (TreeWalk treeWalk = createNonRecursiveTreeWalk(commit)) {
+ assertTrue(treeWalk.next());
+ assertEquals("folder", treeWalk.getPathString());
+ assertTrue(treeWalk.next());
+ assertEquals("folder", treeWalk.getPathString());
+ assertTrue(treeWalk.isSubtree());
+ treeWalk.enterSubtree();
+ assertTrue(treeWalk.next());
+ assertEquals("folder/file", treeWalk.getPathString());
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileCommitted() throws Exception {
RevCommit commit = writeFileAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
"<<<<<<< HEAD\nside\n=======\nmaster\n>>>>>>> master\n");
writeTrashFile(FILE, "master");
- TreeWalk treeWalk = createTreeWalk(side);
- int count = 0;
- while (treeWalk.next())
- count++;
- assertEquals(2, count);
+ try (TreeWalk treeWalk = createTreeWalk(side)) {
+ int count = 0;
+ while (treeWalk.next())
+ count++;
+ assertEquals(2, count);
+ }
}
@Test
public void testFileInFolderCommitted() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testEmptyFolderCommitted() throws Exception {
RevCommit commit = createEmptyFolderAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileCommittedChangedNotModified() throws Exception {
RevCommit commit = writeFileAndCommit();
writeFile();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileInFolderCommittedChangedNotModified() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolder();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileCommittedModified() throws Exception {
RevCommit commit = writeFileAndCommit();
writeFileModified();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE);
+ }
}
@Test
public void testFileInFolderCommittedModified() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModified();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
public void testFileCommittedDeleted() throws Exception {
RevCommit commit = writeFileAndCommit();
deleteFile();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE);
+ }
}
@Test
public void testFileInFolderCommittedDeleted() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
deleteFileInFolder();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
public void testFileInFolderCommittedAllDeleted() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
deleteAll();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
public void testEmptyFolderCommittedDeleted() throws Exception {
RevCommit commit = createEmptyFolderAndCommit();
deleteFolder();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
throws Exception {
RevCommit commit = writeFileAndCommit();
writeFileModifiedAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE);
+ }
}
@Test
throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModifiedAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
throws Exception {
RevCommit commit = writeFileAndCommit();
deleteFileAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE);
+ }
}
@Test
throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
deleteFileInFolderAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
deleteAllAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
throws Exception {
RevCommit commit = createEmptyFolderAndCommit();
deleteFolderAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileUntracked() throws Exception {
RevCommit commit = writeFileAndCommit();
writeFileUntracked();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, UNTRACKED_FILE);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, UNTRACKED_FILE);
+ }
}
@Test
public void testFileInFolderUntracked() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderUntracked();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, UNTRACKED_FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, UNTRACKED_FILE_IN_FOLDER);
+ }
}
@Test
public void testEmptyFolderUntracked() throws Exception {
RevCommit commit = createEmptyFolderAndCommit();
createEmptyFolderUntracked();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileIgnored() throws Exception {
RevCommit commit = writeFileAndCommit();
writeFileIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileInFolderIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileInFolderAllIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderAllIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testEmptyFolderIgnored() throws Exception {
RevCommit commit = createEmptyFolderAndCommit();
createEmptyFolderIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileIgnoredNotHonored() throws Exception {
RevCommit commit = writeFileAndCommit();
writeFileIgnored();
- TreeWalk treeWalk = createTreeWalkDishonorIgnores(commit);
- assertPaths(treeWalk, IGNORED_FILE, GITIGNORE);
+ try (TreeWalk treeWalk = createTreeWalkDishonorIgnores(commit)) {
+ assertPaths(treeWalk, IGNORED_FILE, GITIGNORE);
+ }
}
@Test
public void testFileCommittedModifiedIgnored() throws Exception {
RevCommit commit = writeFileAndCommit();
writeFileModifiedIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE);
+ }
}
@Test
public void testFileInFolderCommittedModifiedIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModifiedIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
public void testFileInFolderCommittedModifiedAllIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModifiedAllIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
RevCommit commit = writeFileAndCommit();
deleteFileAndCommit();
rewriteFileIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE);
+ }
}
@Test
RevCommit commit = writeFileInFolderAndCommit();
deleteFileInFolderAndCommit();
rewriteFileInFolderIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
RevCommit commit = writeFileInFolderAndCommit();
deleteAllAndCommit();
rewriteFileInFolderAllIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FILE_IN_FOLDER);
+ }
}
@Test
RevCommit commit = createEmptyFolderAndCommit();
deleteFolderAndCommit();
recreateEmptyFolderIgnored();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertFalse(treeWalk.next());
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertFalse(treeWalk.next());
+ }
}
@Test
public void testFileInFolderCommittedNonRecursive() throws Exception {
RevCommit commit = writeFileInFolderAndCommit();
- TreeWalk treeWalk = createNonRecursiveTreeWalk(commit);
- assertPaths(treeWalk, FOLDER);
+ try (TreeWalk treeWalk = createNonRecursiveTreeWalk(commit)) {
+ assertPaths(treeWalk, FOLDER);
+ }
}
@Test
RevCommit commit = writeFileInFolderAndCommit();
deleteAll();
writeFileWithFolderName();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER);
+ }
}
@Test
RevCommit commit = writeFileInFolderAndCommit();
deleteAll();
writeFileWithFolderNameAndCommit();
- TreeWalk treeWalk = createTreeWalk(commit);
- assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER);
+ try (TreeWalk treeWalk = createTreeWalk(commit)) {
+ assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER);
+ }
}
private void writeFile() throws Exception {