Browse Source

Merge changes I6e022e4a,If1b9d808

* changes:
  Close TreeWalks in tests
  Close SubmoduleWalks in tests
next
David Pursehouse 5 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
51b24ea17c
  1. 28
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
  2. 52
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
  3. 38
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
  4. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java
  5. 529
      org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesHandlerTest.java
  6. 109
      org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java
  7. 99
      org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeWorkingTreeIteratorTest.java
  8. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java
  9. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
  10. 48
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
  11. 48
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
  12. 89
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
  13. 53
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java
  14. 106
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java
  15. 62
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
  16. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
  17. 239
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
  18. 33
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
  19. 149
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java
  20. 222
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/IndexDiffFilterTest.java

28
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java

@ -646,25 +646,27 @@ public class CloneCommandTest extends RepositoryTestCase {
assertEquals(sub1Head, pathStatus.getHeadId()); assertEquals(sub1Head, pathStatus.getHeadId());
assertEquals(sub1Head, pathStatus.getIndexId()); assertEquals(sub1Head, pathStatus.getIndexId());
SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository()); try (SubmoduleWalk walk = SubmoduleWalk
assertTrue(walk.next()); .forIndex(git2.getRepository())) {
try (Repository clonedSub1 = walk.getRepository()) { assertTrue(walk.next());
assertNotNull(clonedSub1); try (Repository clonedSub1 = walk.getRepository()) {
assertEquals(new File(git2.getRepository().getWorkTree(), assertNotNull(clonedSub1);
walk.getPath()), clonedSub1.getWorkTree()); assertEquals(new File(git2.getRepository().getWorkTree(),
assertEquals( walk.getPath()), clonedSub1.getWorkTree());
new File(new File(git2.getRepository().getDirectory(), assertEquals(
"modules"), walk.getPath()), new File(new File(git2.getRepository().getDirectory(),
clonedSub1.getDirectory()); "modules"), walk.getPath()),
status = new SubmoduleStatusCommand(clonedSub1); clonedSub1.getDirectory());
statuses = status.call(); status = new SubmoduleStatusCommand(clonedSub1);
statuses = status.call();
}
assertFalse(walk.next());
} }
pathStatus = statuses.get(path); pathStatus = statuses.get(path);
assertNotNull(pathStatus); assertNotNull(pathStatus);
assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType()); assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType());
assertEquals(sub2Head, pathStatus.getHeadId()); assertEquals(sub2Head, pathStatus.getHeadId());
assertEquals(sub2Head, pathStatus.getIndexId()); assertEquals(sub2Head, pathStatus.getIndexId());
assertFalse(walk.next());
} }
@Test @Test

52
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java

@ -148,9 +148,10 @@ public class CommitCommandTest extends RepositoryTestCase {
writeTrashFile(path, "content"); writeTrashFile(path, "content");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
RevCommit commit1 = git.commit().setMessage("commit").call(); RevCommit commit1 = git.commit().setMessage("commit").call();
TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree()); try (TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree())) {
assertNotNull(walk); assertNotNull(walk);
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
}
FS nonExecutableFs = new FS() { FS nonExecutableFs = new FS() {
@ -204,9 +205,10 @@ public class CommitCommandTest extends RepositoryTestCase {
writeTrashFile(path, "content2"); writeTrashFile(path, "content2");
RevCommit commit2 = git2.commit().setOnly(path).setMessage("commit2") RevCommit commit2 = git2.commit().setOnly(path).setMessage("commit2")
.call(); .call();
walk = TreeWalk.forPath(db, path, commit2.getTree()); try (TreeWalk walk = TreeWalk.forPath(db, path, commit2.getTree())) {
assertNotNull(walk); assertNotNull(walk);
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
}
} }
@Test @Test
@ -225,15 +227,16 @@ public class CommitCommandTest extends RepositoryTestCase {
assertNotNull(repo); assertNotNull(repo);
addRepoToClose(repo); addRepoToClose(repo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit, generator.getObjectId()); assertEquals(commit, generator.getObjectId());
assertEquals(uri, generator.getModulesUrl()); assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl()); assertEquals(uri, generator.getConfigUrl());
try (Repository subModRepo = generator.getRepository()) { try (Repository subModRepo = generator.getRepository()) {
assertNotNull(subModRepo); assertNotNull(subModRepo);
}
} }
assertEquals(commit, repo.resolve(Constants.HEAD)); assertEquals(commit, repo.resolve(Constants.HEAD));
@ -275,15 +278,16 @@ public class CommitCommandTest extends RepositoryTestCase {
assertNotNull(repo); assertNotNull(repo);
addRepoToClose(repo); addRepoToClose(repo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit2, generator.getObjectId()); assertEquals(commit2, generator.getObjectId());
assertEquals(uri, generator.getModulesUrl()); assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl()); assertEquals(uri, generator.getConfigUrl());
try (Repository subModRepo = generator.getRepository()) { try (Repository subModRepo = generator.getRepository()) {
assertNotNull(subModRepo); assertNotNull(subModRepo);
}
} }
assertEquals(commit2, repo.resolve(Constants.HEAD)); assertEquals(commit2, repo.resolve(Constants.HEAD));

38
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java

@ -142,8 +142,6 @@ public class EolRepositoryTest extends RepositoryTestCase {
protected String CONTENT_MIXED; protected String CONTENT_MIXED;
private TreeWalk walk;
/** work tree root .gitattributes */ /** work tree root .gitattributes */
private File dotGitattributes; private File dotGitattributes;
@ -689,27 +687,25 @@ public class EolRepositoryTest extends RepositoryTestCase {
private void collectRepositoryState() throws Exception { private void collectRepositoryState() throws Exception {
dirCache = db.readDirCache(); dirCache = db.readDirCache();
walk = beginWalk(); try (TreeWalk walk = new TreeWalk(db)) {
if (dotGitattributes != null) walk.addTree(new FileTreeIterator(db));
collectEntryContentAndAttributes(F, ".gitattributes", null); walk.addTree(new DirCacheIterator(db.readDirCache()));
collectEntryContentAndAttributes(F, fileCRLF.getName(), entryCRLF); if (dotGitattributes != null) {
collectEntryContentAndAttributes(F, fileLF.getName(), entryLF); collectEntryContentAndAttributes(walk, F, ".gitattributes",
collectEntryContentAndAttributes(F, fileMixed.getName(), entryMixed); null);
endWalk(); }
} collectEntryContentAndAttributes(walk, F, fileCRLF.getName(),
entryCRLF);
private TreeWalk beginWalk() throws Exception { collectEntryContentAndAttributes(walk, F, fileLF.getName(),
TreeWalk newWalk = new TreeWalk(db); entryLF);
newWalk.addTree(new FileTreeIterator(db)); collectEntryContentAndAttributes(walk, F, fileMixed.getName(),
newWalk.addTree(new DirCacheIterator(db.readDirCache())); entryMixed);
return newWalk; assertFalse("Not all files tested", walk.next());
} }
private void endWalk() throws IOException {
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 { ActualEntry e) throws IOException {
assertTrue("walk has entry", walk.next()); assertTrue("walk has entry", walk.next());

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java

@ -343,19 +343,22 @@ public class FetchAndPullCommandsRecurseSubmodulesTest extends RepositoryTestCas
private void assertSubmoduleFetchHeads(ObjectId expectedHead1, private void assertSubmoduleFetchHeads(ObjectId expectedHead1,
ObjectId expectedHead2) throws Exception { ObjectId expectedHead2) throws Exception {
Object newHead1 = null;
ObjectId newHead2 = null;
try (SubmoduleWalk walk = SubmoduleWalk try (SubmoduleWalk walk = SubmoduleWalk
.forIndex(git2.getRepository())) { .forIndex(git2.getRepository())) {
assertTrue(walk.next()); assertTrue(walk.next());
Repository r = walk.getRepository(); try (Repository r = walk.getRepository()) {
ObjectId newHead1 = r.resolve(Constants.FETCH_HEAD); newHead1 = r.resolve(Constants.FETCH_HEAD);
ObjectId newHead2; try (SubmoduleWalk walk2 = SubmoduleWalk.forIndex(r)) {
try (SubmoduleWalk walk2 = SubmoduleWalk.forIndex(r)) { assertTrue(walk2.next());
assertTrue(walk2.next()); try (Repository r2 = walk2.getRepository()) {
newHead2 = walk2.getRepository().resolve(Constants.FETCH_HEAD); newHead2 = r2.resolve(Constants.FETCH_HEAD);
}
}
} }
assertEquals(expectedHead1, newHead1);
assertEquals(expectedHead2, newHead2);
} }
assertEquals(expectedHead1, newHead1);
assertEquals(expectedHead2, newHead2);
} }
} }

529
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesHandlerTest.java

@ -69,83 +69,90 @@ public class AttributesHandlerTest extends RepositoryTestCase {
private static final FileMode F = FileMode.REGULAR_FILE; private static final FileMode F = FileMode.REGULAR_FILE;
private TreeWalk walk;
@Test @Test
public void testExpandNonMacro1() throws Exception { public void testExpandNonMacro1() throws Exception {
setupRepo(null, null, null, "*.txt text"); setupRepo(null, null, null, "*.txt text");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("text")); assertIteration(walk, F, "sub/a.txt", attrs("text"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testExpandNonMacro2() throws Exception { public void testExpandNonMacro2() throws Exception {
setupRepo(null, null, null, "*.txt -text"); setupRepo(null, null, null, "*.txt -text");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("-text")); assertIteration(walk, F, "sub/a.txt", attrs("-text"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testExpandNonMacro3() throws Exception { public void testExpandNonMacro3() throws Exception {
setupRepo(null, null, null, "*.txt !text"); setupRepo(null, null, null, "*.txt !text");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("")); assertIteration(walk, F, "sub/a.txt", attrs(""));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testExpandNonMacro4() throws Exception { public void testExpandNonMacro4() throws Exception {
setupRepo(null, null, null, "*.txt text=auto"); setupRepo(null, null, null, "*.txt text=auto");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("text=auto")); assertIteration(walk, F, "sub/a.txt", attrs("text=auto"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testExpandBuiltInMacro1() throws Exception { public void testExpandBuiltInMacro1() throws Exception {
setupRepo(null, null, null, "*.txt binary"); setupRepo(null, null, null, "*.txt binary");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("binary -diff -merge -text")); assertIteration(walk, F, "sub/a.txt",
endWalk(); attrs("binary -diff -merge -text"));
assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testExpandBuiltInMacro2() throws Exception { public void testExpandBuiltInMacro2() throws Exception {
setupRepo(null, null, null, "*.txt -binary"); setupRepo(null, null, null, "*.txt -binary");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("-binary diff merge text")); assertIteration(walk, F, "sub/a.txt",
endWalk(); attrs("-binary diff merge text"));
assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testExpandBuiltInMacro3() throws Exception { public void testExpandBuiltInMacro3() throws Exception {
setupRepo(null, null, null, "*.txt !binary"); setupRepo(null, null, null, "*.txt !binary");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("")); assertIteration(walk, F, "sub/a.txt", attrs(""));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -153,44 +160,48 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo( setupRepo(
"[attr]foo a -b !c d=e", null, null, "*.txt foo"); "[attr]foo a -b !c d=e", null, null, "*.txt foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("foo a -b d=e")); assertIteration(walk, F, "sub/a.txt", attrs("foo a -b d=e"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testCustomGlobalMacro2() throws Exception { public void testCustomGlobalMacro2() throws Exception {
setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt -foo"); setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt -foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("-foo -a b d=e")); assertIteration(walk, F, "sub/a.txt", attrs("-foo -a b d=e"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testCustomGlobalMacro3() throws Exception { public void testCustomGlobalMacro3() throws Exception {
setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt !foo"); setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt !foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("")); assertIteration(walk, F, "sub/a.txt", attrs(""));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testCustomGlobalMacro4() throws Exception { public void testCustomGlobalMacro4() throws Exception {
setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt foo=bar"); setupRepo("[attr]foo a -b !c d=e", null, null, "*.txt foo=bar");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("foo=bar a -b d=bar")); assertIteration(walk, F, "sub/a.txt", attrs("foo=bar a -b d=bar"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -198,11 +209,12 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo("[attr]foo bar1", setupRepo("[attr]foo bar1",
"[attr]foo bar2", null, "*.txt foo"); "[attr]foo bar2", null, "*.txt foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("foo bar2")); assertIteration(walk, F, "sub/a.txt", attrs("foo bar2"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -211,12 +223,13 @@ public class AttributesHandlerTest extends RepositoryTestCase {
null, null,
"[attr]foo bar3", "*.txt foo"); "[attr]foo bar3", "*.txt foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("foo bar3")); assertIteration(walk, F, "sub/a.txt", attrs("foo bar3"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -224,12 +237,13 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo("[attr]foo bar1", setupRepo("[attr]foo bar1",
"[attr]foo bar2", "[attr]foo bar3", "*.txt foo"); "[attr]foo bar2", "[attr]foo bar3", "*.txt foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("foo bar2")); assertIteration(walk, F, "sub/a.txt", attrs("foo bar2"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -238,11 +252,12 @@ public class AttributesHandlerTest extends RepositoryTestCase {
"[attr]foo x bar -foo", "[attr]foo x bar -foo",
null, null, "*.txt foo"); null, null, "*.txt foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("foo x bar")); assertIteration(walk, F, "sub/a.txt", attrs("foo x bar"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -250,11 +265,12 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo( setupRepo(
"[attr]foo x -bar\n[attr]bar y -foo", null, null, "*.txt foo"); "[attr]foo x -bar\n[attr]bar y -foo", null, null, "*.txt foo");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/.gitattributes"); assertIteration(walk, F, "sub/.gitattributes");
assertIteration(F, "sub/a.txt", attrs("foo x -bar -y")); assertIteration(walk, F, "sub/a.txt", attrs("foo x -bar -y"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -266,23 +282,30 @@ public class AttributesHandlerTest extends RepositoryTestCase {
// apply to any of the files here. It would match for a // apply to any of the files here. It would match for a
// further subdirectory sub/sub. The sub/ rules must match // further subdirectory sub/sub. The sub/ rules must match
// only for directories. // only for directories.
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "sub", attrs("global")); assertIteration(walk, D, "sub", attrs("global"));
assertIteration(F, "sub/.gitattributes", attrs("init top_sub")); assertIteration(walk, F, "sub/.gitattributes",
assertIteration(F, "sub/a.txt", attrs("init foo top top_sub")); attrs("init top_sub"));
endWalk(); 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: // All right, let's see that they *do* apply in sub/sub:
writeTrashFile("sub/sub/b.txt", "b"); writeTrashFile("sub/sub/b.txt", "b");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "sub", attrs("global")); assertIteration(walk, D, "sub", attrs("global"));
assertIteration(F, "sub/.gitattributes", attrs("init top_sub")); assertIteration(walk, F, "sub/.gitattributes",
assertIteration(F, "sub/a.txt", attrs("init foo top top_sub")); attrs("init top_sub"));
assertIteration(D, "sub/sub", attrs("init subsub2 top_sub global")); assertIteration(walk, F, "sub/a.txt",
assertIteration(F, "sub/sub/b.txt", attrs("init foo top top_sub"));
attrs("init foo subsub top top_sub")); assertIteration(walk, D, "sub/sub",
endWalk(); 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 @Test
@ -293,16 +316,17 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/b.jar", "bj"); writeTrashFile("sub/b.jar", "bj");
writeTrashFile("sub/b.xml", "bx"); writeTrashFile("sub/b.xml", "bx");
// On foo.xml/bar.jar we must not have 'xml' // On foo.xml/bar.jar we must not have 'xml'
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo.xml", attrs("xml")); assertIteration(walk, D, "foo.xml", attrs("xml"));
assertIteration(F, "foo.xml/bar.jar", attrs("jar")); assertIteration(walk, F, "foo.xml/bar.jar", attrs("jar"));
assertIteration(F, "foo.xml/bar.xml", attrs("xml")); assertIteration(walk, F, "foo.xml/bar.xml", attrs("xml"));
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(F, "sub/b.jar", attrs("jar")); assertIteration(walk, F, "sub/b.jar", attrs("jar"));
assertIteration(F, "sub/b.xml", attrs("xml")); assertIteration(walk, F, "sub/b.xml", attrs("xml"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -314,18 +338,19 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/b.jar", "bj"); writeTrashFile("sub/b.jar", "bj");
writeTrashFile("sub/b.xml", "bx"); writeTrashFile("sub/b.xml", "bx");
writeTrashFile("sub/foo/b.jar", "bf"); writeTrashFile("sub/foo/b.jar", "bf");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo", attrs("xml")); assertIteration(walk, D, "foo", attrs("xml"));
assertIteration(F, "foo/bar.jar", attrs("jar")); assertIteration(walk, F, "foo/bar.jar", attrs("jar"));
assertIteration(F, "foo/bar.xml"); assertIteration(walk, F, "foo/bar.xml");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(F, "sub/b.jar", attrs("jar")); assertIteration(walk, F, "sub/b.jar", attrs("jar"));
assertIteration(F, "sub/b.xml"); assertIteration(walk, F, "sub/b.xml");
assertIteration(D, "sub/foo", attrs("sub xml")); assertIteration(walk, D, "sub/foo", attrs("sub xml"));
assertIteration(F, "sub/foo/b.jar", attrs("jar")); assertIteration(walk, F, "sub/foo/b.jar", attrs("jar"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -337,18 +362,19 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/b.xml", "bx"); writeTrashFile("sub/b.xml", "bx");
writeTrashFile("sub/foo/b.jar", "bf"); writeTrashFile("sub/foo/b.jar", "bf");
// On foo.xml/bar.jar we must not have 'xml' // On foo.xml/bar.jar we must not have 'xml'
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(F, "foo/bar.jar", attrs("jar xml")); assertIteration(walk, F, "foo/bar.jar", attrs("jar xml"));
assertIteration(F, "foo/bar.xml", attrs("xml")); assertIteration(walk, F, "foo/bar.xml", attrs("xml"));
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(F, "sub/b.jar", attrs("jar")); assertIteration(walk, F, "sub/b.jar", attrs("jar"));
assertIteration(F, "sub/b.xml"); assertIteration(walk, F, "sub/b.xml");
assertIteration(D, "sub/foo"); assertIteration(walk, D, "sub/foo");
assertIteration(F, "sub/foo/b.jar", attrs("jar")); assertIteration(walk, F, "sub/foo/b.jar", attrs("jar"));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -357,27 +383,29 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/a.txt", "1"); writeTrashFile("sub/a.txt", "1");
writeTrashFile("foo/sext", "2"); writeTrashFile("foo/sext", "2");
writeTrashFile("foo/s.txt", "3"); writeTrashFile("foo/s.txt", "3");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(F, "foo/s.txt", attrs("bar")); assertIteration(walk, F, "foo/s.txt", attrs("bar"));
assertIteration(F, "foo/sext", attrs("bar")); assertIteration(walk, F, "foo/sext", attrs("bar"));
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
public void testPrefixMatchNot() throws Exception { public void testPrefixMatchNot() throws Exception {
setupRepo(null, null, "sub/new bar", null); setupRepo(null, null, "sub/new bar", null);
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -385,14 +413,15 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo(null, null, "s[t-v]b/n[de]w bar", null); setupRepo(null, null, "s[t-v]b/n[de]w bar", null);
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("sub/ndw", "2"); writeTrashFile("sub/ndw", "2");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(F, "sub/ndw", attrs("bar")); assertIteration(walk, F, "sub/ndw", attrs("bar"));
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -400,15 +429,16 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo(null, null, "sub/new/* bar", null); setupRepo(null, null, "sub/new/* bar", null);
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("sub/new/lower/foo.txt", "2"); writeTrashFile("sub/new/lower/foo.txt", "2");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new"); assertIteration(walk, D, "sub/new");
assertIteration(F, "sub/new/foo.txt", attrs("bar")); assertIteration(walk, F, "sub/new/foo.txt", attrs("bar"));
assertIteration(D, "sub/new/lower", attrs("bar")); assertIteration(walk, D, "sub/new/lower", attrs("bar"));
assertIteration(F, "sub/new/lower/foo.txt"); assertIteration(walk, F, "sub/new/lower/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -417,20 +447,21 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2"); writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("sub/sub/new/foo.txt", "3"); writeTrashFile("sub/sub/new/foo.txt", "3");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(D, "foo/sub"); assertIteration(walk, D, "foo/sub");
assertIteration(D, "foo/sub/new"); assertIteration(walk, D, "foo/sub/new");
assertIteration(F, "foo/sub/new/foo.txt"); assertIteration(walk, F, "foo/sub/new/foo.txt");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
assertIteration(D, "sub/sub"); assertIteration(walk, D, "sub/sub");
assertIteration(D, "sub/sub/new"); assertIteration(walk, D, "sub/sub/new");
assertIteration(F, "sub/sub/new/foo.txt"); assertIteration(walk, F, "sub/sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -438,17 +469,18 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo(null, null, "**/sub/new/ bar", null); setupRepo(null, null, "**/sub/new/ bar", null);
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2"); writeTrashFile("foo/sub/new/foo.txt", "2");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(D, "foo/sub"); assertIteration(walk, D, "foo/sub");
assertIteration(D, "foo/sub/new", attrs("bar")); assertIteration(walk, D, "foo/sub/new", attrs("bar"));
assertIteration(F, "foo/sub/new/foo.txt"); assertIteration(walk, F, "foo/sub/new/foo.txt");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -457,20 +489,21 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2"); writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("sub/sub/new/foo.txt", "3"); writeTrashFile("sub/sub/new/foo.txt", "3");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(D, "foo/sub"); assertIteration(walk, D, "foo/sub");
assertIteration(D, "foo/sub/new", attrs("bar")); assertIteration(walk, D, "foo/sub/new", attrs("bar"));
assertIteration(F, "foo/sub/new/foo.txt"); assertIteration(walk, F, "foo/sub/new/foo.txt");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
assertIteration(D, "sub/sub"); assertIteration(walk, D, "sub/sub");
assertIteration(D, "sub/sub/new", attrs("bar")); assertIteration(walk, D, "sub/sub/new", attrs("bar"));
assertIteration(F, "sub/sub/new/foo.txt"); assertIteration(walk, F, "sub/sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -479,20 +512,21 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2"); writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("sub/sub/new/foo.txt", "3"); writeTrashFile("sub/sub/new/foo.txt", "3");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(D, "foo/sub"); assertIteration(walk, D, "foo/sub");
assertIteration(D, "foo/sub/new", attrs("bar")); assertIteration(walk, D, "foo/sub/new", attrs("bar"));
assertIteration(F, "foo/sub/new/foo.txt"); assertIteration(walk, F, "foo/sub/new/foo.txt");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
assertIteration(D, "sub/sub"); assertIteration(walk, D, "sub/sub");
assertIteration(D, "sub/sub/new", attrs("bar")); assertIteration(walk, D, "sub/sub/new", attrs("bar"));
assertIteration(F, "sub/sub/new/foo.txt"); assertIteration(walk, F, "sub/sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -500,17 +534,18 @@ public class AttributesHandlerTest extends RepositoryTestCase {
setupRepo(null, null, "s[uv]b/n*/ bar", null); setupRepo(null, null, "s[uv]b/n*/ bar", null);
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2"); writeTrashFile("foo/sub/new/foo.txt", "2");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(D, "foo/sub"); assertIteration(walk, D, "foo/sub");
assertIteration(D, "foo/sub/new"); assertIteration(walk, D, "foo/sub/new");
assertIteration(F, "foo/sub/new/foo.txt"); assertIteration(walk, F, "foo/sub/new/foo.txt");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -519,30 +554,32 @@ public class AttributesHandlerTest extends RepositoryTestCase {
writeTrashFile("sub/new/foo.txt", "1"); writeTrashFile("sub/new/foo.txt", "1");
writeTrashFile("foo/sub/new/foo.txt", "2"); writeTrashFile("foo/sub/new/foo.txt", "2");
writeTrashFile("foo/new", "3"); writeTrashFile("foo/new", "3");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(F, ".gitattributes"); assertIteration(walk, F, ".gitattributes");
assertIteration(D, "foo"); assertIteration(walk, D, "foo");
assertIteration(F, "foo/new"); assertIteration(walk, F, "foo/new");
assertIteration(D, "foo/sub"); assertIteration(walk, D, "foo/sub");
assertIteration(D, "foo/sub/new", attrs("bar")); assertIteration(walk, D, "foo/sub/new", attrs("bar"));
assertIteration(F, "foo/sub/new/foo.txt"); assertIteration(walk, F, "foo/sub/new/foo.txt");
assertIteration(D, "sub"); assertIteration(walk, D, "sub");
assertIteration(F, "sub/a.txt"); assertIteration(walk, F, "sub/a.txt");
assertIteration(D, "sub/new", attrs("bar")); assertIteration(walk, D, "sub/new", attrs("bar"));
assertIteration(F, "sub/new/foo.txt"); assertIteration(walk, F, "sub/new/foo.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
private static Collection<Attribute> attrs(String s) { private static Collection<Attribute> attrs(String s) {
return new AttributesRule("*", s).getAttributes(); return new AttributesRule("*", s).getAttributes();
} }
private void assertIteration(FileMode type, String pathName) private void assertIteration(TreeWalk walk, FileMode type, String pathName)
throws IOException { 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 { Collection<Attribute> expectedAttrs) throws IOException {
assertTrue("walk has entry", walk.next()); assertTrue("walk has entry", walk.next());
assertEquals(pathName, walk.getPathString()); assertEquals(pathName, walk.getPathString());
@ -611,8 +648,4 @@ public class AttributesHandlerTest extends RepositoryTestCase {
newWalk.addTree(new FileTreeIterator(db)); newWalk.addTree(new FileTreeIterator(db));
return newWalk; return newWalk;
} }
private void endWalk() throws IOException {
assertFalse("Not all files tested", walk.next());
}
} }

109
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java

@ -78,8 +78,6 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
private Git git; private Git git;
private TreeWalk walk;
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -105,23 +103,25 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
// Adds file to index // Adds file to index
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(walk, F, ".gitattributes");
assertIteration(F, ".gitattributes"); assertIteration(walk, F, "readme.txt", asList(EOL_LF));
assertIteration(F, "readme.txt", asList(EOL_LF));
assertIteration(D, "src"); assertIteration(walk, D, "src");
assertIteration(D, "src/config"); assertIteration(walk, D, "src/config");
assertIteration(F, "src/config/.gitattributes"); assertIteration(walk, F, "src/config/.gitattributes");
assertIteration(F, "src/config/readme.txt", asList(DELTA_UNSET)); assertIteration(walk, F, "src/config/readme.txt",
assertIteration(F, "src/config/windows.file", null); asList(DELTA_UNSET));
assertIteration(F, "src/config/windows.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(walk, F, "windows.file", null);
assertIteration(F, "windows.txt", asList(EOL_LF)); assertIteration(walk, F, "windows.txt", asList(EOL_LF));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
/** /**
@ -138,17 +138,18 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
// Adds file to index // Adds file to index
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
walk = beginWalk();
assertIteration(F, "l0.txt"); try (TreeWalk walk = beginWalk()) {
assertIteration(walk, F, "l0.txt");
assertIteration(D, "level1"); assertIteration(walk, D, "level1");
assertIteration(F, "level1/l1.txt"); assertIteration(walk, F, "level1/l1.txt");
assertIteration(D, "level1/level2"); assertIteration(walk, D, "level1/level2");
assertIteration(F, "level1/level2/l2.txt"); assertIteration(walk, F, "level1/level2/l2.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
/** /**
@ -166,18 +167,19 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
// Adds file to index // Adds file to index
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
walk = beginWalk();
assertIteration(F, ".gitattributes"); try (TreeWalk walk = beginWalk()) {
assertIteration(F, "l0.txt"); assertIteration(walk, F, ".gitattributes");
assertIteration(walk, F, "l0.txt");
assertIteration(D, "level1"); assertIteration(walk, D, "level1");
assertIteration(F, "level1/l1.txt"); assertIteration(walk, F, "level1/l1.txt");
assertIteration(D, "level1/level2"); assertIteration(walk, D, "level1/level2");
assertIteration(F, "level1/level2/l2.txt"); assertIteration(walk, F, "level1/level2/l2.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -191,18 +193,19 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
// Adds file to index // Adds file to index
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
walk = beginWalk();
assertIteration(F, ".gitattributes"); try (TreeWalk walk = beginWalk()) {
assertIteration(walk, F, ".gitattributes");
assertIteration(D, "levelA"); assertIteration(walk, D, "levelA");
assertIteration(F, "levelA/.gitattributes"); assertIteration(walk, F, "levelA/.gitattributes");
assertIteration(F, "levelA/lA.txt"); assertIteration(walk, F, "levelA/lA.txt");
assertIteration(D, "levelB"); assertIteration(walk, D, "levelB");
assertIteration(F, "levelB/.gitattributes"); assertIteration(walk, F, "levelB/.gitattributes");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -215,25 +218,27 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
// Adds file to index // Adds file to index
git.add().addFilepattern(".").call(); 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(walk, D, "levelA");
assertIteration(F, "levelA/file.gitattributes"); assertIteration(walk, F, "levelA/file.gitattributes");
assertIteration(F, "levelA/lA.txt"); 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 { 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 { List<Attribute> nodeAttrs) throws IOException {
assertTrue("walk has entry", walk.next()); assertTrue("walk has entry", walk.next());
assertEquals(pathName, walk.getPathString()); assertEquals(pathName, walk.getPathString());
@ -243,14 +248,14 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
AttributesNode attributesNode = itr.getEntryAttributesNode(db AttributesNode attributesNode = itr.getEntryAttributesNode(db
.newObjectReader()); .newObjectReader());
assertAttributesNode(pathName, attributesNode, nodeAttrs); assertAttributesNode(walk, pathName, attributesNode, nodeAttrs);
if (D.equals(type)) if (D.equals(type))
walk.enterSubtree(); walk.enterSubtree();
} }
private void assertAttributesNode(String pathName, private void assertAttributesNode(TreeWalk walk, String pathName,
AttributesNode attributesNode, List<Attribute> nodeAttrs) AttributesNode attributesNode, List<Attribute> nodeAttrs)
throws IOException { throws IOException {
if (attributesNode == null) if (attributesNode == null)
@ -292,8 +297,4 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase {
newWalk.addTree(new DirCacheIterator(db.readDirCache())); newWalk.addTree(new DirCacheIterator(db.readDirCache()));
return newWalk; return newWalk;
} }
private void endWalk() throws IOException {
assertFalse("Not all files tested", walk.next());
}
} }

99
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeWorkingTreeIteratorTest.java

@ -77,8 +77,6 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase {
private static Attribute DELTA_UNSET = new Attribute("delta", State.UNSET); private static Attribute DELTA_UNSET = new Attribute("delta", State.UNSET);
private TreeWalk walk;
@Test @Test
public void testRules() throws Exception { public void testRules() throws Exception {
@ -102,24 +100,26 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase {
writeTrashFile("src/config/windows.file", ""); writeTrashFile("src/config/windows.file", "");
writeTrashFile("src/config/windows.txt", ""); writeTrashFile("src/config/windows.txt", "");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(walk, F, ".gitattributes");
assertIteration(F, ".gitattributes"); assertIteration(walk, F, "global.txt", asList(EOL_LF));
assertIteration(F, "global.txt", asList(EOL_LF)); assertIteration(walk, F, "readme.txt", asList(EOL_LF));
assertIteration(F, "readme.txt", asList(EOL_LF));
assertIteration(D, "src"); assertIteration(walk, D, "src");
assertIteration(D, "src/config"); assertIteration(walk, D, "src/config");
assertIteration(F, "src/config/.gitattributes"); assertIteration(walk, F, "src/config/.gitattributes");
assertIteration(F, "src/config/readme.txt", asList(DELTA_UNSET)); assertIteration(walk, F, "src/config/readme.txt",
assertIteration(F, "src/config/windows.file", null); asList(DELTA_UNSET));
assertIteration(F, "src/config/windows.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(walk, F, "windows.file", null);
assertIteration(F, "windows.txt", asList(EOL_LF)); assertIteration(walk, F, "windows.txt", asList(EOL_LF));
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
/** /**
@ -134,17 +134,17 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase {
writeTrashFile("level1/l1.txt", ""); writeTrashFile("level1/l1.txt", "");
writeTrashFile("level1/level2/l2.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(walk, D, "level1/level2");
assertIteration(F, "level1/l1.txt"); assertIteration(walk, F, "level1/level2/l2.txt");
assertIteration(D, "level1/level2"); assertFalse("Not all files tested", walk.next());
assertIteration(F, "level1/level2/l2.txt"); }
endWalk();
} }
/** /**
@ -160,18 +160,18 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase {
writeTrashFile("level1/l1.txt", ""); writeTrashFile("level1/l1.txt", "");
writeTrashFile("level1/level2/l2.txt", ""); writeTrashFile("level1/level2/l2.txt", "");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(walk, F, ".gitattributes");
assertIteration(F, ".gitattributes"); assertIteration(walk, F, "l0.txt");
assertIteration(F, "l0.txt");
assertIteration(D, "level1"); assertIteration(walk, D, "level1");
assertIteration(F, "level1/l1.txt"); assertIteration(walk, F, "level1/l1.txt");
assertIteration(D, "level1/level2"); assertIteration(walk, D, "level1/level2");
assertIteration(F, "level1/level2/l2.txt"); assertIteration(walk, F, "level1/level2/l2.txt");
endWalk(); assertFalse("Not all files tested", walk.next());
}
} }
@Test @Test
@ -183,26 +183,27 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase {
writeTrashFile("levelA/lA.txt", ""); writeTrashFile("levelA/lA.txt", "");
walk = beginWalk(); try (TreeWalk walk = beginWalk()) {
assertIteration(walk, F, ".gitattributes");
assertIteration(F, ".gitattributes");
assertIteration(D, "levelA"); assertIteration(walk, D, "levelA");
assertIteration(F, "levelA/.gitattributes"); assertIteration(walk, F, "levelA/.gitattributes");
assertIteration(F, "levelA/lA.txt"); assertIteration(walk, F, "levelA/lA.txt");
assertIteration(D, "levelB"); assertIteration(walk, D, "levelB");
assertIteration(F, "levelB/.gitattributes"); 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 { 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) List<Attribute> nodeAttrs)
throws IOException { throws IOException {
assertTrue("walk has entry", walk.next()); assertTrue("walk has entry", walk.next());
@ -212,13 +213,13 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase {
assertNotNull("has tree", itr); assertNotNull("has tree", itr);
AttributesNode attributesNode = itr.getEntryAttributesNode(); AttributesNode attributesNode = itr.getEntryAttributesNode();
assertAttributesNode(pathName, attributesNode, nodeAttrs); assertAttributesNode(walk, pathName, attributesNode, nodeAttrs);
if (D.equals(type)) if (D.equals(type))
walk.enterSubtree(); walk.enterSubtree();
} }
private void assertAttributesNode(String pathName, private void assertAttributesNode(TreeWalk walk, String pathName,
AttributesNode attributesNode, List<Attribute> nodeAttrs) AttributesNode attributesNode, List<Attribute> nodeAttrs)
throws IOException { throws IOException {
if (attributesNode == null) if (attributesNode == null)
@ -259,8 +260,4 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase {
newWalk.addTree(new FileTreeIterator(db)); newWalk.addTree(new FileTreeIterator(db));
return newWalk; return newWalk;
} }
private void endWalk() throws IOException {
assertFalse("Not all files tested", walk.next());
}
} }

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java

@ -131,6 +131,12 @@ public class TreeWalkAttributeTest extends RepositoryTestCase {
@Override @Override
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
if (walk != null) {
walk.close();
}
if (ci_walk != null) {
ci_walk.close();
}
super.tearDown(); super.tearDown();
if (customAttributeFile != null) if (customAttributeFile != null)
customAttributeFile.delete(); customAttributeFile.delete();

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java

@ -63,6 +63,7 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator; import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader; import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
import org.junit.Test; import org.junit.Test;
/** /**
@ -79,6 +80,13 @@ public class IgnoreNodeTest extends RepositoryTestCase {
private TreeWalk walk; private TreeWalk walk;
@After
public void closeWalk() {
if (walk != null) {
walk.close();
}
}
@Test @Test
public void testSimpleRootGitIgnoreGlobalIgnore() throws IOException { public void testSimpleRootGitIgnoreGlobalIgnore() throws IOException {
writeIgnoreFile(".gitignore", "x"); writeIgnoreFile(".gitignore", "x");

48
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java

@ -106,23 +106,24 @@ public class CherryPickTest extends RepositoryTestCase {
boolean merge = twm.merge(new ObjectId[] { O, T }); boolean merge = twm.merge(new ObjectId[] { O, T });
assertTrue(merge); assertTrue(merge);
final TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.reset(twm.getResultTreeId()); tw.reset(twm.getResultTreeId());
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("a", tw.getPathString()); assertEquals("a", tw.getPathString());
assertCorrectId(treeO, tw); assertCorrectId(treeO, tw);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("o", tw.getPathString()); assertEquals("o", tw.getPathString());
assertCorrectId(treeO, tw); assertCorrectId(treeO, tw);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("t", tw.getPathString()); assertEquals("t", tw.getPathString());
assertCorrectId(treeT, tw); assertCorrectId(treeT, tw);
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
@Test @Test
@ -168,19 +169,20 @@ public class CherryPickTest extends RepositoryTestCase {
boolean merge = twm.merge(new ObjectId[] { B, T }); boolean merge = twm.merge(new ObjectId[] { B, T });
assertTrue(merge); assertTrue(merge);
final TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.reset(twm.getResultTreeId()); tw.reset(twm.getResultTreeId());
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("a", tw.getPathString()); assertEquals("a", tw.getPathString());
assertCorrectId(treeB, tw); assertCorrectId(treeB, tw);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("t", tw.getPathString()); assertEquals("t", tw.getPathString());
assertCorrectId(treeT, tw); assertCorrectId(treeT, tw);
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
private static void assertCorrectId(DirCache treeT, TreeWalk tw) { private static void assertCorrectId(DirCache treeT, TreeWalk tw) {

48
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java

@ -174,23 +174,24 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
boolean merge = ourMerger.merge(new ObjectId[] { o, t }); boolean merge = ourMerger.merge(new ObjectId[] { o, t });
assertTrue(merge); assertTrue(merge);
final TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.reset(ourMerger.getResultTreeId()); tw.reset(ourMerger.getResultTreeId());
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("Makefile", tw.getPathString()); assertEquals("Makefile", tw.getPathString());
assertCorrectId(treeO, tw); assertCorrectId(treeO, tw);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("libelf-po/a", tw.getPathString()); assertEquals("libelf-po/a", tw.getPathString());
assertCorrectId(treeO, tw); assertCorrectId(treeO, tw);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("libelf/c", tw.getPathString()); assertEquals("libelf/c", tw.getPathString());
assertCorrectId(treeT, tw); assertCorrectId(treeT, tw);
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
@Test @Test
@ -226,19 +227,20 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
boolean merge = ourMerger.merge(new ObjectId[] { o, t }); boolean merge = ourMerger.merge(new ObjectId[] { o, t });
assertTrue(merge); assertTrue(merge);
final TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.reset(ourMerger.getResultTreeId()); tw.reset(ourMerger.getResultTreeId());
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("d/o", tw.getPathString()); assertEquals("d/o", tw.getPathString());
assertCorrectId(treeO, tw); assertCorrectId(treeO, tw);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("d/t", tw.getPathString()); assertEquals("d/t", tw.getPathString());
assertCorrectId(treeT, tw); assertCorrectId(treeT, tw);
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
@Test @Test

89
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java

@ -135,20 +135,20 @@ public class SubmoduleAddTest extends RepositoryTestCase {
subCommit = repo.resolve(Constants.HEAD); subCommit = repo.resolve(Constants.HEAD);
} }
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
generator.loadModulesConfig(); generator.loadModulesConfig();
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getModuleName()); assertEquals(path, generator.getModuleName());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit, generator.getObjectId()); assertEquals(commit, generator.getObjectId());
assertEquals(uri, generator.getModulesUrl()); assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl()); assertEquals(uri, generator.getConfigUrl());
try (Repository subModRepo = generator.getRepository()) { try (Repository subModRepo = generator.getRepository()) {
assertNotNull(subModRepo); assertNotNull(subModRepo);
assertEquals(subCommit, commit); assertEquals(subCommit, commit);
}
} }
Status status = Git.wrap(db).status().call(); Status status = Git.wrap(db).status().call();
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES)); assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
assertTrue(status.getAdded().contains(path)); assertTrue(status.getAdded().contains(path));
@ -175,20 +175,20 @@ public class SubmoduleAddTest extends RepositoryTestCase {
subCommit = repo.resolve(Constants.HEAD); subCommit = repo.resolve(Constants.HEAD);
} }
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
generator.loadModulesConfig(); generator.loadModulesConfig();
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(name, generator.getModuleName()); assertEquals(name, generator.getModuleName());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit, generator.getObjectId()); assertEquals(commit, generator.getObjectId());
assertEquals(uri, generator.getModulesUrl()); assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl()); assertEquals(uri, generator.getConfigUrl());
try (Repository subModRepo = generator.getRepository()) { try (Repository subModRepo = generator.getRepository()) {
assertNotNull(subModRepo); assertNotNull(subModRepo);
assertEquals(subCommit, commit); assertEquals(subCommit, commit);
}
} }
Status status = Git.wrap(db).status().call(); Status status = Git.wrap(db).status().call();
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES)); assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
assertTrue(status.getAdded().contains(path)); assertTrue(status.getAdded().contains(path));
@ -269,24 +269,25 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertNotNull(repo); assertNotNull(repo);
addRepoToClose(repo); addRepoToClose(repo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit, generator.getObjectId()); assertEquals(commit, generator.getObjectId());
assertEquals(uri, generator.getModulesUrl()); assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
String fullUri = db.getDirectory().getAbsolutePath(); String fullUri = db.getDirectory().getAbsolutePath();
if (File.separatorChar == '\\') { if (File.separatorChar == '\\') {
fullUri = fullUri.replace('\\', '/'); fullUri = fullUri.replace('\\', '/');
} }
assertEquals(fullUri, generator.getConfigUrl()); assertEquals(fullUri, generator.getConfigUrl());
try (Repository subModRepo = generator.getRepository()) { try (Repository subModRepo = generator.getRepository()) {
assertNotNull(subModRepo); assertNotNull(subModRepo);
assertEquals(fullUri, assertEquals(fullUri,
subModRepo.getConfig().getString( subModRepo.getConfig().getString(
ConfigConstants.CONFIG_REMOTE_SECTION, ConfigConstants.CONFIG_REMOTE_SECTION,
Constants.DEFAULT_REMOTE_NAME, Constants.DEFAULT_REMOTE_NAME,
ConfigConstants.CONFIG_KEY_URL)); ConfigConstants.CONFIG_KEY_URL));
}
} }
assertEquals(commit, repo.resolve(Constants.HEAD)); assertEquals(commit, repo.resolve(Constants.HEAD));

53
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java

@ -107,7 +107,6 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(1, updated.size()); assertEquals(1, updated.size());
File submoduleDir = assertSubmoduleIsInitialized(); File submoduleDir = assertSubmoduleIsInitialized();
SubmoduleWalk generator;
write(new File(submoduleDir, "untracked"), "untracked"); write(new File(submoduleDir, "untracked"), "untracked");
@ -115,8 +114,9 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length); assertNotEquals(0, submoduleDir.list().length);
} }
@ -132,33 +132,36 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(1, updated.size()); assertEquals(1, updated.size());
File submoduleDir = assertSubmoduleIsInitialized(); File submoduleDir = assertSubmoduleIsInitialized();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
generator.next(); generator.next();
//want to create a commit inside the repo... // want to create a commit inside the repo...
try (Repository submoduleLocalRepo = generator.getRepository()) { try (Repository submoduleLocalRepo = generator.getRepository()) {
JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt", JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt",
"new data"); "new data");
Git.wrap(submoduleLocalRepo).commit().setAll(true) Git.wrap(submoduleLocalRepo).commit().setAll(true)
.setMessage("local commit").call(); .setMessage("local commit").call();
}
} }
SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub")); SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub"));
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length); assertNotEquals(0, submoduleDir.list().length);
} }
private File assertSubmoduleIsInitialized() throws IOException { private File assertSubmoduleIsInitialized() throws IOException {
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
File submoduleDir = new File(db.getWorkTree(), generator.getPath()); File submoduleDir = new File(db.getWorkTree(), generator.getPath());
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length); assertNotEquals(0, submoduleDir.list().length);
return submoduleDir; return submoduleDir;
}
} }
@Test @Test
@ -180,8 +183,9 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.FORCED, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.FORCED, result.getStatus());
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertEquals(0, submoduleDir.list().length); assertEquals(0, submoduleDir.list().length);
} }
@ -202,8 +206,9 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.SUCCESS, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.SUCCESS, result.getStatus());
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertEquals(0, submoduleDir.list().length); assertEquals(0, submoduleDir.list().length);
} }

106
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java

@ -86,11 +86,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
ConfigInvalidException, GitAPIException { ConfigInvalidException, GitAPIException {
final String path = addSubmoduleToIndex(); final String path = addSubmoduleToIndex();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -109,10 +109,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(url, generator.getConfigUrl()); assertEquals(url, generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
}
} }
@Test @Test
@ -126,11 +127,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -149,10 +150,12 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server/repo.git/sub.git", generator.getConfigUrl()); assertEquals("git://server/repo.git/sub.git",
assertEquals(update, generator.getConfigUpdate()); generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate());
}
} }
@Test @Test
@ -167,11 +170,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -190,10 +193,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server/sub.git", generator.getConfigUrl()); assertEquals("git://server/sub.git", generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
}
} }
@Test @Test
@ -208,11 +212,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -231,10 +235,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server2/sub.git", generator.getConfigUrl()); assertEquals("git://server2/sub.git", generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
}
} }
@Test @Test
@ -250,11 +255,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL); Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -273,10 +278,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(base + "/sub.git", generator.getConfigUrl()); assertEquals(base + "/sub.git", generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
}
} }
@Test @Test
@ -291,11 +297,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,

62
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java

@ -119,11 +119,11 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
addRepoToClose(subRepo); addRepoToClose(subRepo);
assertNotNull(subRepo); assertNotNull(subRepo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertEquals(url, generator.getModulesUrl()); assertEquals(url, generator.getModulesUrl());
}
SubmoduleSyncCommand command = new SubmoduleSyncCommand(db); SubmoduleSyncCommand command = new SubmoduleSyncCommand(db);
Map<String, String> synced = command.call(); Map<String, String> synced = command.call();
assertNotNull(synced); assertNotNull(synced);
@ -132,16 +132,17 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
assertEquals(path, module.getKey()); assertEquals(path, module.getKey());
assertEquals(url, module.getValue()); assertEquals(url, module.getValue());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(url, generator.getConfigUrl()); assertEquals(url, generator.getConfigUrl());
try (Repository subModRepository = generator.getRepository()) { try (Repository subModRepository = generator.getRepository()) {
StoredConfig submoduleConfig = subModRepository.getConfig(); StoredConfig submoduleConfig = subModRepository.getConfig();
assertEquals(url, assertEquals(url,
submoduleConfig.getString( submoduleConfig.getString(
ConfigConstants.CONFIG_REMOTE_SECTION, ConfigConstants.CONFIG_REMOTE_SECTION,
Constants.DEFAULT_REMOTE_NAME, Constants.DEFAULT_REMOTE_NAME,
ConfigConstants.CONFIG_KEY_URL)); ConfigConstants.CONFIG_KEY_URL));
}
} }
} }
@ -190,11 +191,11 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
assertNotNull(subRepo); assertNotNull(subRepo);
addRepoToClose(subRepo); addRepoToClose(subRepo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertEquals(current, generator.getModulesUrl()); assertEquals(current, generator.getModulesUrl());
}
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
ConfigConstants.CONFIG_KEY_URL, "../sub.git"); ConfigConstants.CONFIG_KEY_URL, "../sub.git");
modulesConfig.save(); modulesConfig.save();
@ -207,16 +208,17 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
assertEquals(path, module.getKey()); assertEquals(path, module.getKey());
assertEquals("git://server/sub.git", module.getValue()); assertEquals("git://server/sub.git", module.getValue());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server/sub.git", generator.getConfigUrl()); assertEquals("git://server/sub.git", generator.getConfigUrl());
try (Repository subModRepository1 = generator.getRepository()) { try (Repository subModRepository1 = generator.getRepository()) {
StoredConfig submoduleConfig = subModRepository1.getConfig(); StoredConfig submoduleConfig = subModRepository1.getConfig();
assertEquals("git://server/sub.git", assertEquals("git://server/sub.git",
submoduleConfig.getString( submoduleConfig.getString(
ConfigConstants.CONFIG_REMOTE_SECTION, ConfigConstants.CONFIG_REMOTE_SECTION,
Constants.DEFAULT_REMOTE_NAME, Constants.DEFAULT_REMOTE_NAME,
ConfigConstants.CONFIG_KEY_URL)); ConfigConstants.CONFIG_KEY_URL));
}
} }
} }
} }

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java

@ -119,11 +119,12 @@ public class SubmoduleUpdateTest extends RepositoryTestCase {
assertEquals(1, updated.size()); assertEquals(1, updated.size());
assertEquals(path, updated.iterator().next()); assertEquals(path, updated.iterator().next());
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
try (Repository subRepo = generator.getRepository()) { try (Repository subRepo = generator.getRepository()) {
assertNotNull(subRepo); assertNotNull(subRepo);
assertEquals(commit, subRepo.resolve(Constants.HEAD)); assertEquals(commit, subRepo.resolve(Constants.HEAD));
}
} }
} }
@ -181,10 +182,11 @@ public class SubmoduleUpdateTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
Repository subRepo = Git.init().setBare(false) try (Repository subRepo = Git.init().setBare(false)
.setDirectory(new File(db.getWorkTree(), path)).call() .setDirectory(new File(db.getWorkTree(), path)).call()
.getRepository(); .getRepository()) {
assertNotNull(subRepo); assertNotNull(subRepo);
}
SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db); SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db);
Collection<String> updated = command.call(); Collection<String> updated = command.call();

239
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java

@ -98,10 +98,11 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
@Test @Test
public void repositoryWithNoSubmodules() throws IOException { public void repositoryWithNoSubmodules() throws IOException {
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertFalse(gen.next()); assertFalse(gen.next());
assertNull(gen.getPath()); assertNull(gen.getPath());
assertEquals(ObjectId.zeroId(), gen.getObjectId()); assertEquals(ObjectId.zeroId(), gen.getObjectId());
}
} }
@Test @Test
@ -129,20 +130,21 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUpdate()); assertNull(gen.getConfigUpdate());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUrl());
assertNull(gen.getModulesPath()); assertNull(gen.getModulesPath());
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertNull(gen.getModulesUrl()); assertNull(gen.getModulesUrl());
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next());
}
Status status = Git.wrap(db).status().call(); Status status = Git.wrap(db).status().call();
assertTrue(!status.isClean()); assertFalse(status.isClean());
assertFalse(gen.next());
} }
@Test @Test
@ -178,24 +180,25 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUpdate()); assertNull(gen.getConfigUpdate());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUrl());
assertNull(gen.getModulesPath()); assertNull(gen.getModulesPath());
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertNull(gen.getModulesUrl()); assertNull(gen.getModulesUrl());
try (Repository subRepo = gen.getRepository()) { try (Repository subRepo = gen.getRepository()) {
assertNotNull(subRepo); assertNotNull(subRepo);
assertEquals(modulesGitDir.getAbsolutePath(), assertEquals(modulesGitDir.getAbsolutePath(),
subRepo.getDirectory().getAbsolutePath()); subRepo.getDirectory().getAbsolutePath());
assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(), assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(),
subRepo.getWorkTree().getAbsolutePath()); subRepo.getWorkTree().getAbsolutePath());
}
assertFalse(gen.next());
} }
assertFalse(gen.next());
} }
@Test @Test
@ -232,23 +235,24 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUpdate()); assertNull(gen.getConfigUpdate());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUrl());
assertNull(gen.getModulesPath()); assertNull(gen.getModulesPath());
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertNull(gen.getModulesUrl()); assertNull(gen.getModulesUrl());
try (Repository subRepo = gen.getRepository()) { try (Repository subRepo = gen.getRepository()) {
assertNotNull(subRepo); assertNotNull(subRepo);
assertEqualsFile(modulesGitDir, subRepo.getDirectory()); assertEqualsFile(modulesGitDir, subRepo.getDirectory());
assertEqualsFile(new File(db.getWorkTree(), path), assertEqualsFile(new File(db.getWorkTree(), path),
subRepo.getWorkTree()); subRepo.getWorkTree());
subRepo.close(); subRepo.close();
assertFalse(gen.next()); assertFalse(gen.next());
}
} }
} }
@ -270,18 +274,19 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUpdate()); assertNull(gen.getConfigUpdate());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUrl());
assertNull(gen.getModulesPath()); assertNull(gen.getModulesPath());
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertNull(gen.getModulesUrl()); assertNull(gen.getModulesUrl());
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
}
} }
@Test @Test
@ -312,12 +317,13 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
gen.setFilter(PathFilter.create(path1)); gen.setFilter(PathFilter.create(path1));
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path1, gen.getPath()); assertEquals(path1, gen.getPath());
assertEquals(id1, gen.getObjectId()); assertEquals(id1, gen.getObjectId());
assertFalse(gen.next()); assertFalse(gen.next());
}
} }
@Test @Test
@ -358,18 +364,19 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUpdate()); assertNull(gen.getConfigUpdate());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUrl());
assertEquals("sub", gen.getModulesPath()); assertEquals("sub", gen.getModulesPath());
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertEquals("git://example.com/sub", gen.getModulesUrl()); assertEquals("git://example.com/sub", gen.getModulesUrl());
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
}
} }
@Test @Test
@ -397,17 +404,19 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}) })
.create()); .create());
SubmoduleWalk gen = SubmoduleWalk.forPath(db, commit.getTree(), "sub"); try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, commit.getTree(),
assertEquals(path, gen.getPath()); "sub")) {
assertEquals(subId, gen.getObjectId()); assertEquals(path, gen.getPath());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(subId, gen.getObjectId());
assertNull(gen.getConfigUpdate()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUpdate());
assertEquals("sub", gen.getModulesPath()); assertNull(gen.getConfigUrl());
assertNull(gen.getModulesUpdate()); assertEquals("sub", gen.getModulesPath());
assertEquals("git://example.com/sub", gen.getModulesUrl()); assertNull(gen.getModulesUpdate());
assertNull(gen.getRepository()); assertEquals("git://example.com/sub", gen.getModulesUrl());
assertFalse(gen.next()); assertNull(gen.getRepository());
assertFalse(gen.next());
}
} }
@Test @Test
@ -437,17 +446,18 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
final CanonicalTreeParser p = new CanonicalTreeParser(); final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree()); p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub"); try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUpdate()); assertNull(gen.getConfigUpdate());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUrl());
assertEquals("sub", gen.getModulesPath()); assertEquals("sub", gen.getModulesPath());
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertEquals("git://example.com/sub", gen.getModulesUrl()); assertEquals("git://example.com/sub", gen.getModulesUrl());
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
}
} }
@Test @Test
@ -477,16 +487,17 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
final CanonicalTreeParser p = new CanonicalTreeParser(); final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree()); p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub"); try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
assertNull(gen.getConfigUpdate()); assertNull(gen.getConfigUpdate());
assertNull(gen.getConfigUrl()); assertNull(gen.getConfigUrl());
assertEquals("sub", gen.getModulesPath()); assertEquals("sub", gen.getModulesPath());
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertEquals("git://example.com/sub", gen.getModulesUrl()); assertEquals("git://example.com/sub", gen.getModulesUrl());
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
}
} }
} }

33
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java

@ -272,22 +272,23 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
git.add().addFilepattern("file").call(); git.add().addFilepattern("file").call();
} }
DirCacheEntry dce = db.readDirCache().getEntry("file"); DirCacheEntry dce = db.readDirCache().getEntry("file");
TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(),
.getConfig().get(WorkingTreeOptions.KEY)); db.getConfig().get(WorkingTreeOptions.KEY));
tw.addTree(fti); tw.addTree(fti);
DirCacheIterator dci = new DirCacheIterator(db.readDirCache()); DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
tw.addTree(dci); tw.addTree(dci);
fti.setDirCacheIterator(tw, 1); fti.setDirCacheIterator(tw, 1);
while (tw.next() && !tw.getPathString().equals("file")) { while (tw.next() && !tw.getPathString().equals("file")) {
// //
} }
assertEquals(MetadataDiff.EQUAL, fti.compareMetadata(dce)); assertEquals(MetadataDiff.EQUAL, fti.compareMetadata(dce));
ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset()); ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
fromRaw.getName()); fromRaw.getName());
try (ObjectReader objectReader = db.newObjectReader()) { try (ObjectReader objectReader = db.newObjectReader()) {
assertFalse(fti.isModified(dce, false, objectReader)); assertFalse(fti.isModified(dce, false, objectReader));
}
} }
} }

149
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java

@ -84,16 +84,17 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
assertEquals(1, tree1.getEntryCount()); assertEquals(1, tree1.getEntryCount());
} }
final TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
assertModes("a", REGULAR_FILE, MISSING, tw); assertModes("a", REGULAR_FILE, MISSING, tw);
assertModes("a.b", EXECUTABLE_FILE, MISSING, tw); assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
assertModes("a", MISSING, TREE, tw); assertModes("a", MISSING, TREE, tw);
tw.enterSubtree(); tw.enterSubtree();
assertModes("a/b", MISSING, REGULAR_FILE, tw); assertModes("a/b", MISSING, REGULAR_FILE, tw);
assertModes("a0b", SYMLINK, MISSING, tw); assertModes("a0b", SYMLINK, MISSING, tw);
}
} }
@Test @Test
@ -115,20 +116,21 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
assertEquals(1, tree1.getEntryCount()); assertEquals(1, tree1.getEntryCount());
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
assertModes("a", REGULAR_FILE, TREE, tw); assertModes("a", REGULAR_FILE, TREE, tw);
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
assertTrue(tw.isSubtree()); assertTrue(tw.isSubtree());
tw.enterSubtree(); tw.enterSubtree();
assertModes("a/b", MISSING, REGULAR_FILE, tw); assertModes("a/b", MISSING, REGULAR_FILE, tw);
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
assertModes("a.b", EXECUTABLE_FILE, MISSING, tw); assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
assertModes("a0b", SYMLINK, MISSING, tw); assertModes("a0b", SYMLINK, MISSING, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
}
} }
@Test @Test
@ -151,20 +153,21 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
assertEquals(2, tree1.getEntryCount()); assertEquals(2, tree1.getEntryCount());
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
assertModes("a", REGULAR_FILE, TREE, tw); assertModes("a", REGULAR_FILE, TREE, tw);
assertTrue(tw.isSubtree()); assertTrue(tw.isSubtree());
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
tw.enterSubtree(); tw.enterSubtree();
assertModes("a/b", MISSING, REGULAR_FILE, tw); assertModes("a/b", MISSING, REGULAR_FILE, tw);
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
assertModes("a.b", EXECUTABLE_FILE, EXECUTABLE_FILE, tw); assertModes("a.b", EXECUTABLE_FILE, EXECUTABLE_FILE, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
assertModes("a0b", SYMLINK, MISSING, tw); assertModes("a0b", SYMLINK, MISSING, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
}
} }
@Test @Test
@ -187,20 +190,21 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
assertEquals(3, tree1.getEntryCount()); assertEquals(3, tree1.getEntryCount());
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
assertModes("a", REGULAR_FILE, TREE, tw); assertModes("a", REGULAR_FILE, TREE, tw);
assertTrue(tw.isSubtree()); assertTrue(tw.isSubtree());
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
tw.enterSubtree(); tw.enterSubtree();
assertModes("a/b", MISSING, REGULAR_FILE, tw); assertModes("a/b", MISSING, REGULAR_FILE, tw);
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
assertModes("a.b", MISSING, EXECUTABLE_FILE, tw); assertModes("a.b", MISSING, EXECUTABLE_FILE, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
assertModes("a0b", SYMLINK, SYMLINK, tw); assertModes("a0b", SYMLINK, SYMLINK, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
}
} }
@Test @Test
@ -224,26 +228,27 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
assertEquals(4, tree1.getEntryCount()); assertEquals(4, tree1.getEntryCount());
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
assertModes("0", REGULAR_FILE, REGULAR_FILE, tw); assertModes("0", REGULAR_FILE, REGULAR_FILE, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
assertModes("a", REGULAR_FILE, TREE, tw); assertModes("a", REGULAR_FILE, TREE, tw);
assertTrue(tw.isSubtree()); assertTrue(tw.isSubtree());
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
tw.enterSubtree(); tw.enterSubtree();
assertModes("a/b", MISSING, REGULAR_FILE, tw); assertModes("a/b", MISSING, REGULAR_FILE, tw);
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
assertModes("a/c", MISSING, TREE, tw); assertModes("a/c", MISSING, TREE, tw);
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
tw.enterSubtree(); tw.enterSubtree();
assertModes("a/c/e", MISSING, REGULAR_FILE, tw); assertModes("a/c/e", MISSING, REGULAR_FILE, tw);
assertTrue(tw.isDirectoryFileConflict()); assertTrue(tw.isDirectoryFileConflict());
assertModes("a.b", MISSING, REGULAR_FILE, tw); assertModes("a.b", MISSING, REGULAR_FILE, tw);
assertFalse(tw.isDirectoryFileConflict()); assertFalse(tw.isDirectoryFileConflict());
}
} }
private static void assertModes(final String path, final FileMode mode0, private static void assertModes(final String path, final FileMode mode0,

222
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/IndexDiffFilterTest.java

@ -101,13 +101,14 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteAll(); deleteAll();
writeFileWithFolderName(); writeFileWithFolderName();
TreeWalk treeWalk = createTreeWalk(commit);
assertTrue(treeWalk.next()); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertEquals("folder", treeWalk.getPathString()); assertTrue(treeWalk.next());
assertTrue(treeWalk.next()); assertEquals("folder", treeWalk.getPathString());
assertEquals("folder/file", treeWalk.getPathString()); assertTrue(treeWalk.next());
assertFalse(treeWalk.next()); assertEquals("folder/file", treeWalk.getPathString());
assertFalse(treeWalk.next());
}
} }
@Test @Test
@ -115,24 +116,26 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteAll(); deleteAll();
writeFileWithFolderName(); writeFileWithFolderName();
TreeWalk treeWalk = createNonRecursiveTreeWalk(commit);
try (TreeWalk treeWalk = createNonRecursiveTreeWalk(commit)) {
assertTrue(treeWalk.next()); assertTrue(treeWalk.next());
assertEquals("folder", treeWalk.getPathString()); assertEquals("folder", treeWalk.getPathString());
assertTrue(treeWalk.next()); assertTrue(treeWalk.next());
assertEquals("folder", treeWalk.getPathString()); assertEquals("folder", treeWalk.getPathString());
assertTrue(treeWalk.isSubtree()); assertTrue(treeWalk.isSubtree());
treeWalk.enterSubtree(); treeWalk.enterSubtree();
assertTrue(treeWalk.next()); assertTrue(treeWalk.next());
assertEquals("folder/file", treeWalk.getPathString()); assertEquals("folder/file", treeWalk.getPathString());
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileCommitted() throws Exception { public void testFileCommitted() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
@ -153,89 +156,100 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
"<<<<<<< HEAD\nside\n=======\nmaster\n>>>>>>> master\n"); "<<<<<<< HEAD\nside\n=======\nmaster\n>>>>>>> master\n");
writeTrashFile(FILE, "master"); writeTrashFile(FILE, "master");
TreeWalk treeWalk = createTreeWalk(side); try (TreeWalk treeWalk = createTreeWalk(side)) {
int count = 0; int count = 0;
while (treeWalk.next()) while (treeWalk.next())
count++; count++;
assertEquals(2, count); assertEquals(2, count);
}
} }
@Test @Test
public void testFileInFolderCommitted() throws Exception { public void testFileInFolderCommitted() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testEmptyFolderCommitted() throws Exception { public void testEmptyFolderCommitted() throws Exception {
RevCommit commit = createEmptyFolderAndCommit(); RevCommit commit = createEmptyFolderAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileCommittedChangedNotModified() throws Exception { public void testFileCommittedChangedNotModified() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
writeFile(); writeFile();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileInFolderCommittedChangedNotModified() throws Exception { public void testFileInFolderCommittedChangedNotModified() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolder(); writeFileInFolder();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileCommittedModified() throws Exception { public void testFileCommittedModified() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
writeFileModified(); writeFileModified();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE); assertPaths(treeWalk, FILE);
}
} }
@Test @Test
public void testFileInFolderCommittedModified() throws Exception { public void testFileInFolderCommittedModified() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModified(); writeFileInFolderModified();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
public void testFileCommittedDeleted() throws Exception { public void testFileCommittedDeleted() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
deleteFile(); deleteFile();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE); assertPaths(treeWalk, FILE);
}
} }
@Test @Test
public void testFileInFolderCommittedDeleted() throws Exception { public void testFileInFolderCommittedDeleted() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteFileInFolder(); deleteFileInFolder();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
public void testFileInFolderCommittedAllDeleted() throws Exception { public void testFileInFolderCommittedAllDeleted() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteAll(); deleteAll();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
public void testEmptyFolderCommittedDeleted() throws Exception { public void testEmptyFolderCommittedDeleted() throws Exception {
RevCommit commit = createEmptyFolderAndCommit(); RevCommit commit = createEmptyFolderAndCommit();
deleteFolder(); deleteFolder();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
@ -243,8 +257,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
throws Exception { throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
writeFileModifiedAndCommit(); writeFileModifiedAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE); assertPaths(treeWalk, FILE);
}
} }
@Test @Test
@ -252,8 +267,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
throws Exception { throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModifiedAndCommit(); writeFileInFolderModifiedAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
@ -261,8 +277,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
throws Exception { throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
deleteFileAndCommit(); deleteFileAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE); assertPaths(treeWalk, FILE);
}
} }
@Test @Test
@ -270,8 +287,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
throws Exception { throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteFileInFolderAndCommit(); deleteFileInFolderAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
@ -279,8 +297,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
throws Exception { throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteAllAndCommit(); deleteAllAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
@ -288,96 +307,108 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
throws Exception { throws Exception {
RevCommit commit = createEmptyFolderAndCommit(); RevCommit commit = createEmptyFolderAndCommit();
deleteFolderAndCommit(); deleteFolderAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileUntracked() throws Exception { public void testFileUntracked() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
writeFileUntracked(); writeFileUntracked();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, UNTRACKED_FILE); assertPaths(treeWalk, UNTRACKED_FILE);
}
} }
@Test @Test
public void testFileInFolderUntracked() throws Exception { public void testFileInFolderUntracked() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderUntracked(); writeFileInFolderUntracked();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, UNTRACKED_FILE_IN_FOLDER); assertPaths(treeWalk, UNTRACKED_FILE_IN_FOLDER);
}
} }
@Test @Test
public void testEmptyFolderUntracked() throws Exception { public void testEmptyFolderUntracked() throws Exception {
RevCommit commit = createEmptyFolderAndCommit(); RevCommit commit = createEmptyFolderAndCommit();
createEmptyFolderUntracked(); createEmptyFolderUntracked();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileIgnored() throws Exception { public void testFileIgnored() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
writeFileIgnored(); writeFileIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileInFolderIgnored() throws Exception { public void testFileInFolderIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderIgnored(); writeFileInFolderIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileInFolderAllIgnored() throws Exception { public void testFileInFolderAllIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderAllIgnored(); writeFileInFolderAllIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testEmptyFolderIgnored() throws Exception { public void testEmptyFolderIgnored() throws Exception {
RevCommit commit = createEmptyFolderAndCommit(); RevCommit commit = createEmptyFolderAndCommit();
createEmptyFolderIgnored(); createEmptyFolderIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileIgnoredNotHonored() throws Exception { public void testFileIgnoredNotHonored() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
writeFileIgnored(); writeFileIgnored();
TreeWalk treeWalk = createTreeWalkDishonorIgnores(commit); try (TreeWalk treeWalk = createTreeWalkDishonorIgnores(commit)) {
assertPaths(treeWalk, IGNORED_FILE, GITIGNORE); assertPaths(treeWalk, IGNORED_FILE, GITIGNORE);
}
} }
@Test @Test
public void testFileCommittedModifiedIgnored() throws Exception { public void testFileCommittedModifiedIgnored() throws Exception {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
writeFileModifiedIgnored(); writeFileModifiedIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE); assertPaths(treeWalk, FILE);
}
} }
@Test @Test
public void testFileInFolderCommittedModifiedIgnored() throws Exception { public void testFileInFolderCommittedModifiedIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModifiedIgnored(); writeFileInFolderModifiedIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
public void testFileInFolderCommittedModifiedAllIgnored() throws Exception { public void testFileInFolderCommittedModifiedAllIgnored() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
writeFileInFolderModifiedAllIgnored(); writeFileInFolderModifiedAllIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
@ -386,8 +417,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = writeFileAndCommit(); RevCommit commit = writeFileAndCommit();
deleteFileAndCommit(); deleteFileAndCommit();
rewriteFileIgnored(); rewriteFileIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE); assertPaths(treeWalk, FILE);
}
} }
@Test @Test
@ -396,8 +428,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteFileInFolderAndCommit(); deleteFileInFolderAndCommit();
rewriteFileInFolderIgnored(); rewriteFileInFolderIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
@ -406,8 +439,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteAllAndCommit(); deleteAllAndCommit();
rewriteFileInFolderAllIgnored(); rewriteFileInFolderAllIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FILE_IN_FOLDER); assertPaths(treeWalk, FILE_IN_FOLDER);
}
} }
@Test @Test
@ -416,15 +450,17 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = createEmptyFolderAndCommit(); RevCommit commit = createEmptyFolderAndCommit();
deleteFolderAndCommit(); deleteFolderAndCommit();
recreateEmptyFolderIgnored(); recreateEmptyFolderIgnored();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertFalse(treeWalk.next()); assertFalse(treeWalk.next());
}
} }
@Test @Test
public void testFileInFolderCommittedNonRecursive() throws Exception { public void testFileInFolderCommittedNonRecursive() throws Exception {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
TreeWalk treeWalk = createNonRecursiveTreeWalk(commit); try (TreeWalk treeWalk = createNonRecursiveTreeWalk(commit)) {
assertPaths(treeWalk, FOLDER); assertPaths(treeWalk, FOLDER);
}
} }
@Test @Test
@ -432,8 +468,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteAll(); deleteAll();
writeFileWithFolderName(); writeFileWithFolderName();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER); assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER);
}
} }
@Test @Test
@ -442,8 +479,9 @@ public class IndexDiffFilterTest extends RepositoryTestCase {
RevCommit commit = writeFileInFolderAndCommit(); RevCommit commit = writeFileInFolderAndCommit();
deleteAll(); deleteAll();
writeFileWithFolderNameAndCommit(); writeFileWithFolderNameAndCommit();
TreeWalk treeWalk = createTreeWalk(commit); try (TreeWalk treeWalk = createTreeWalk(commit)) {
assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER); assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER);
}
} }
private void writeFile() throws Exception { private void writeFile() throws Exception {

Loading…
Cancel
Save