Browse Source

Enhance test coverage when core.filemode is false

Some branches in WorkingTreeIterator.getIndexFileMode() have not been
covered by tests. Enhance the tests to increase test coverage.

Change-Id: I400a221048f0f6cbaa987350eaf998b0ebb50a4e
stable-4.5
Christian Halstrick 9 years ago committed by Matthias Sohn
parent
commit
d7a8831785
  1. 78
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

78
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

@ -45,7 +45,6 @@ package org.eclipse.jgit.api;
import static org.eclipse.jgit.util.FileUtils.RECURSIVE; import static org.eclipse.jgit.util.FileUtils.RECURSIVE;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -955,7 +954,11 @@ public class AddCommandTest extends RepositoryTestCase {
} }
public boolean canExecute(File f) { public boolean canExecute(File f) {
return true; try {
return read(f).startsWith("binary:");
} catch (IOException e) {
return false;
}
} }
@Override @Override
@ -966,61 +969,40 @@ public class AddCommandTest extends RepositoryTestCase {
Git git = Git.open(db.getDirectory(), executableFs); Git git = Git.open(db.getDirectory(), executableFs);
String path = "a.txt"; String path = "a.txt";
String path2 = "a.sh";
writeTrashFile(path, "content"); writeTrashFile(path, "content");
git.add().addFilepattern(path).call(); writeTrashFile(path2, "binary: content");
git.add().addFilepattern(path).addFilepattern(path2).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 = new TreeWalk(db)) {
assertNotNull(walk); walk.addTree(commit1.getTree());
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); walk.next();
assertEquals(path2, walk.getPathString());
FS nonExecutableFs = new FS() { assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
walk.next();
public boolean supportsExecute() { assertEquals(path, walk.getPathString());
return false; assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
} }
public boolean setExecute(File f, boolean canExec) {
return false;
}
public ProcessBuilder runInShell(String cmd, String[] args) {
return null;
}
public boolean retryFailedLockFileCommit() {
return false;
}
public FS newInstance() {
return this;
}
protected File discoverGitExe() {
return null;
}
public boolean canExecute(File f) {
return false;
}
@Override
public boolean isCaseSensitive() {
return false;
}
};
config = db.getConfig(); config = db.getConfig();
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_FILEMODE, false); ConfigConstants.CONFIG_KEY_FILEMODE, false);
config.save(); config.save();
Git git2 = Git.open(db.getDirectory(), nonExecutableFs); Git git2 = Git.open(db.getDirectory(), executableFs);
writeTrashFile(path, "content2"); writeTrashFile(path2, "content2");
git2.add().addFilepattern(path).call(); writeTrashFile(path, "binary: content2");
git2.add().addFilepattern(path).addFilepattern(path2).call();
RevCommit commit2 = git2.commit().setMessage("commit2").call(); RevCommit commit2 = git2.commit().setMessage("commit2").call();
walk = TreeWalk.forPath(db, path, commit2.getTree()); try (TreeWalk walk = new TreeWalk(db)) {
assertNotNull(walk); walk.addTree(commit2.getTree());
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); walk.next();
assertEquals(path2, walk.getPathString());
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
walk.next();
assertEquals(path, walk.getPathString());
assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
}
} }
@Test @Test

Loading…
Cancel
Save