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>
This commit is contained in:
Christian Halstrick 2015-10-08 18:17:30 +02:00 committed by Matthias Sohn
parent cd1b00e3fc
commit 227b78f087
1 changed files with 21 additions and 3 deletions

View File

@ -78,6 +78,7 @@
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 void testDontOverwriteDirtyFile() throws IOException {
}
}
@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 void testFileModeChangeAndContentChangeNoConflict() throws Exception {
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 void assertWorkDir(HashMap<String, String> i) throws CorruptObjectExcepti
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 void assertWorkDir(HashMap<String, String> i) throws CorruptObjectExcepti
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);