aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Baars2013-03-04 06:14:16 (EST)
committerArthur Baars2013-03-31 10:36:47 (EDT)
commit2b9c440fd1a08158b5e69d3a9e1a5bed4a17b286 (patch)
treed16361f7929fc9fea6e977a9649221ad832deeb9
parent4796fe70432d882f1d51d9fec59c111107be44f8 (diff)
downloadjgit-2b9c440fd1a08158b5e69d3a9e1a5bed4a17b286.zip
jgit-2b9c440fd1a08158b5e69d3a9e1a5bed4a17b286.tar.gz
jgit-2b9c440fd1a08158b5e69d3a9e1a5bed4a17b286.tar.bz2
LogCommand.all(), peel references before using themrefs/changes/13/10813/5
Problem: LogCommand.all() throws an IncorrectObjectTypeException when there are tag references, and the repository does not contain the file "packed-refs". It seems that the references were not properly peeled before being added to the markStart() method. Solution: Call getRepository().peel() on every Ref that has isPeeled()==false in LogCommand.all() . Added test case for LogCommand.all() on repo with a tag. 1. I have authored 100% of the content I'm contributing, 2. I have the rights to donate the content to Eclipse, 3. I contribute the content under the EDL Bug: 402025 Change-Id: Idb8881eeb6ccce8530f2837b25296e8e83636eb7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java25
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java2
2 files changed, 27 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
index 1f53645..c6402e7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
@@ -51,6 +51,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -89,6 +90,30 @@ public class LogCommandTest extends RepositoryTestCase {
assertFalse(log.hasNext());
}
+ @Test
+ public void logAllCommitsWithTag() throws Exception {
+ List<RevCommit> commits = new ArrayList<RevCommit>();
+ Git git = Git.wrap(db);
+
+ writeTrashFile("Test.txt", "Hello world");
+ git.add().addFilepattern("Test.txt").call();
+ commits.add(git.commit().setMessage("initial commit").call());
+
+ TagCommand tagCmd = git.tag();
+ tagCmd.setName("tagname");
+ tagCmd.setObjectId(commits.get(0));
+ tagCmd.setTagger(new PersonIdent(db));
+ Ref tag = tagCmd.call();
+
+ Iterator<RevCommit> log = git.log().all().call().iterator();
+ assertTrue(log.hasNext());
+ RevCommit commit = log.next();
+ tag = db.peel(tag);
+
+ assertEquals(commit.getName(), tag.getPeeledObjectId().getName());
+ assertTrue(commits.contains(commit));
+ }
+
private List<RevCommit> createCommits(Git git) throws Exception {
List<RevCommit> commits = new ArrayList<RevCommit>();
writeTrashFile("Test.txt", "Hello world");
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 6d4b347..70b3658 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
@@ -239,6 +239,8 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
*/
public LogCommand all() throws IOException {
for (Ref ref : getRepository().getAllRefs().values()) {
+ if(!ref.isPeeled())
+ ref = getRepository().peel(ref);
ObjectId objectId = ref.getPeeledObjectId();
if (objectId == null)
objectId = ref.getObjectId();