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
tags/v4.5.0.201609210915-r
Christian Halstrick 8 years ago
parent
commit
d7a8831785
1 changed files with 30 additions and 48 deletions
  1. 30
    48
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

+ 30
- 48
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java View 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

Loading…
Cancel
Save