]> source.dussan.org Git - jgit.git/commitdiff
Enhance test coverage when core.filemode is false 41/69841/3
authorChristian Halstrick <christian.halstrick@sap.com>
Mon, 4 Apr 2016 13:14:10 +0000 (15:14 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 1 Jul 2016 20:48:29 +0000 (22:48 +0200)
Some branches in WorkingTreeIterator.getIndexFileMode() have not been
covered by tests. Enhance the tests to increase test coverage.

Change-Id: I400a221048f0f6cbaa987350eaf998b0ebb50a4e

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

index eb2ee0878784d0de18d3200ff495f590b80377b0..42601aaa9fcf1c9e4ac00b1a5b06673594a81043 100644 (file)
@@ -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