summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2015-11-17 03:27:53 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2015-11-17 03:27:55 -0500
commitd45ee995467709f539bf01607854d1afad11e3b7 (patch)
treee8f940b66b6ae06978589349a2ef6e17c5e6cd25
parent4acff5a59e38eb13d4c7c17117526b5272c6e74f (diff)
parente18444de30f1f019b5f7f0a463da42a884cb6a9a (diff)
downloadjgit-d45ee995467709f539bf01607854d1afad11e3b7.tar.gz
jgit-d45ee995467709f539bf01607854d1afad11e3b7.zip
Merge "Fix MissingObjectException in RenameDetector"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java31
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/ContentSource.java6
2 files changed, 36 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
index e83ef772ff..4315be9e49 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
@@ -48,6 +48,7 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
@@ -227,6 +228,19 @@ public class RenameDetectorTest extends RepositoryTestCase {
}
@Test
+ public void testExactRename_UnstagedFile() throws Exception {
+ ObjectId aId = blob("foo");
+ DiffEntry a = DiffEntry.delete(PATH_A, aId);
+ DiffEntry b = DiffEntry.add(PATH_B, aId);
+
+ rd.addAll(Arrays.asList(a, b));
+ List<DiffEntry> entries = rd.compute();
+
+ assertEquals(1, entries.size());
+ assertRename(a, b, 100, entries.get(0));
+ }
+
+ @Test
public void testInexactRename_OnePair() throws Exception {
ObjectId aId = blob("foo\nbar\nbaz\nblarg\n");
ObjectId bId = blob("foo\nbar\nbaz\nblah\n");
@@ -430,6 +444,23 @@ public class RenameDetectorTest extends RepositoryTestCase {
}
@Test
+ public void testNoRenames_UntrackedFile() throws Exception {
+ ObjectId aId = blob("foo");
+ ObjectId bId = ObjectId
+ .fromString("3049eb6eee7e1318f4e78e799bf33f1e54af9cbf");
+
+ DiffEntry a = DiffEntry.delete(PATH_A, aId);
+ DiffEntry b = DiffEntry.add(PATH_B, bId);
+
+ rd.addAll(Arrays.asList(a, b));
+ List<DiffEntry> entries = rd.compute();
+
+ assertEquals(2, entries.size());
+ assertSame(a, entries.get(0));
+ assertSame(b, entries.get(1));
+ }
+
+ @Test
public void testBreakModify_BreakAll() throws Exception {
ObjectId aId = blob("foo");
ObjectId bId = blob("bar");
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/ContentSource.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/ContentSource.java
index 0dc4b05787..444ab1cb83 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/ContentSource.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/ContentSource.java
@@ -132,7 +132,11 @@ public abstract class ContentSource {
@Override
public long size(String path, ObjectId id) throws IOException {
- return reader.getObjectSize(id, Constants.OBJ_BLOB);
+ try {
+ return reader.getObjectSize(id, Constants.OBJ_BLOB);
+ } catch (MissingObjectException ignore) {
+ return 0;
+ }
}
@Override