Browse Source

Add utility method allowing to check for empty folders in workdir

Previously the method DirCacheCheckoutTest#assertWorkDir() silently
skipped over empty folders. If tests would have left unexpected empty
folders in the worktree this would be overlooked. Now empty folders have
to be specified by something like mkmap("<foldername>", "/", ...]

Change-Id: Idb8b270e92daf02ecdc381d148a5958bd83ec057
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.2
Christian Halstrick 9 years ago committed by Matthias Sohn
parent
commit
227b78f087
  1. 24
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

24
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

@ -78,6 +78,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
public class DirCacheCheckoutTest extends RepositoryTestCase {
@ -982,6 +983,14 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
}
}
@Test
public void testDontOverwriteEmptyFolder() throws IOException {
setupCase(mk("foo"), mk("foo"), mk("foo"));
FileUtils.mkdir(new File(db.getWorkTree(), "d"));
checkout();
assertWorkDir(mkmap("foo", "foo", "d", "/"));
}
@Test
public void testOverwriteUntrackedIgnoredFile() throws IOException,
GitAPIException {
@ -1213,7 +1222,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
public void assertWorkDir(HashMap<String, String> i) throws CorruptObjectException,
IOException {
TreeWalk walk = new TreeWalk(db);
walk.setRecursive(true);
walk.setRecursive(false);
walk.addTree(new FileTreeIterator(db));
String expectedValue;
String path;
@ -1223,11 +1232,11 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
ft = walk.getTree(0, FileTreeIterator.class);
path = ft.getEntryPathString();
expectedValue = i.get(path);
assertNotNull("found unexpected file for path " + path
+ " in workdir", expectedValue);
File file = new File(db.getWorkTree(), path);
assertTrue(file.exists());
if (file.isFile()) {
assertNotNull("found unexpected file for path " + path
+ " in workdir", expectedValue);
FileInputStream is = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length()];
int offset = 0;
@ -1241,6 +1250,15 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
assertArrayEquals("unexpected content for path " + path
+ " in workDir. ", buffer, i.get(path).getBytes());
nrFiles++;
} else if (file.isDirectory()) {
if (file.list().length == 0) {
assertEquals("found unexpected empty folder for path "
+ path + " in workDir. ", "/", i.get(path));
nrFiles++;
}
}
if (walk.isSubtree()) {
walk.enterSubtree();
}
}
assertEquals("WorkDir has not the right size.", i.size(), nrFiles);

Loading…
Cancel
Save