From: Christian Halstrick Date: Mon, 4 Apr 2016 13:14:10 +0000 (+0200) Subject: Enhance test coverage when core.filemode is false X-Git-Tag: v4.5.0.201609210915-r~99 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F41%2F69841%2F3;p=jgit.git 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 --- diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java index eb2ee08787..42601aaa9f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java +++ b/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.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -955,7 +954,11 @@ public class AddCommandTest extends RepositoryTestCase { } public boolean canExecute(File f) { - return true; + try { + return read(f).startsWith("binary:"); + } catch (IOException e) { + return false; + } } @Override @@ -966,61 +969,40 @@ public class AddCommandTest extends RepositoryTestCase { Git git = Git.open(db.getDirectory(), executableFs); String path = "a.txt"; + String path2 = "a.sh"; 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(); - TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree()); - assertNotNull(walk); - assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); - - FS nonExecutableFs = new FS() { - - public boolean supportsExecute() { - return false; - } - - 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; - } - }; + try (TreeWalk walk = new TreeWalk(db)) { + walk.addTree(commit1.getTree()); + 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)); + } config = db.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); - Git git2 = Git.open(db.getDirectory(), nonExecutableFs); - writeTrashFile(path, "content2"); - git2.add().addFilepattern(path).call(); + Git git2 = Git.open(db.getDirectory(), executableFs); + writeTrashFile(path2, "content2"); + writeTrashFile(path, "binary: content2"); + git2.add().addFilepattern(path).addFilepattern(path2).call(); RevCommit commit2 = git2.commit().setMessage("commit2").call(); - walk = TreeWalk.forPath(db, path, commit2.getTree()); - assertNotNull(walk); - assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); + try (TreeWalk walk = new TreeWalk(db)) { + walk.addTree(commit2.getTree()); + 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