summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Janik <janikpiotrek@gmail.com>2011-05-18 16:22:08 +0200
committerChris Aniszczyk <caniszczyk@gmail.com>2011-05-18 10:35:25 -0500
commit7449b9a297af193107560c42508c53d7adb00226 (patch)
treee7618c016f797d744299fbc2a36dbaffe7da5da4
parentd781554b79b50e5c3fe468373e87edf8957d7578 (diff)
downloadjgit-7449b9a297af193107560c42508c53d7adb00226.tar.gz
jgit-7449b9a297af193107560c42508c53d7adb00226.zip
Fix path filtering in LogCommand
Bug: 346257 Change-Id: Ib897e1b4962162da9670164479a844aeea7dfcd1 Signed-off-by: Piotr Janik <janikpiotrek@gmail.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java55
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java5
2 files changed, 58 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
index ffb36c38ba..fa97198d8c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
@@ -50,7 +50,6 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
-
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException;
@@ -112,6 +111,60 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
assertTrue(reader.getLastEntry().getComment().startsWith("commit:"));
}
+ @Test
+ public void testLogWithFilter() throws IOException, NoFilepatternException,
+ NoHeadException, NoMessageException, ConcurrentRefUpdateException,
+ JGitInternalException, WrongRepositoryStateException {
+
+ Git git = new Git(db);
+
+ // create first file
+ File file = new File(db.getWorkTree(), "a.txt");
+ FileUtils.createNewFile(file);
+ PrintWriter writer = new PrintWriter(file);
+ writer.print("content1");
+ writer.close();
+
+ // First commit - a.txt file
+ git.add().addFilepattern("a.txt").call();
+ git.commit().setMessage("commit1").setCommitter(committer).call();
+
+ // create second file
+ file = new File(db.getWorkTree(), "b.txt");
+ FileUtils.createNewFile(file);
+ writer = new PrintWriter(file);
+ writer.print("content2");
+ writer.close();
+
+ // Second commit - b.txt file
+ git.add().addFilepattern("b.txt").call();
+ git.commit().setMessage("commit2").setCommitter(committer).call();
+
+ // First log - a.txt filter
+ int count = 0;
+ for (RevCommit c : git.log().addPath("a.txt").call()) {
+ assertEquals("commit1", c.getFullMessage());
+ count++;
+ }
+ assertEquals(1, count);
+
+ // Second log - b.txt filter
+ count = 0;
+ for (RevCommit c : git.log().addPath("b.txt").call()) {
+ assertEquals("commit2", c.getFullMessage());
+ count++;
+ }
+ assertEquals(1, count);
+
+ // Third log - without filter
+ count = 0;
+ for (RevCommit c : git.log().call()) {
+ assertEquals(committer, c.getCommitterIdent());
+ count++;
+ }
+ assertEquals(2, count);
+ }
+
// try to do a commit without specifying a message. Should fail!
@Test
public void testWrongParams() throws UnmergedPathException,
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
index 9b39d52a2a..cbdfe56106 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
@@ -58,8 +58,10 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
/**
* A class used to execute a {@code Log} command. It has setters for all
@@ -103,7 +105,8 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
JGitInternalException {
checkCallable();
if (pathFilters.size() > 0)
- walk.setTreeFilter(PathFilterGroup.create(pathFilters));
+ walk.setTreeFilter(AndTreeFilter.create(
+ PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF));
if (!startSpecified) {
try {
ObjectId headId = repo.resolve(Constants.HEAD);