summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorRobin Stocker <robin@nibor.org>2013-05-10 18:16:36 +0200
committerRobin Stocker <robin@nibor.org>2013-05-15 12:23:40 +0200
commit92189b2df42e3eb9ba651b7f9d989ab556f49396 (patch)
treea13cb5184b804ee0f2ce1fedf479158f494100bf /org.eclipse.jgit.test/tst
parentc93a59330249677cd990820b59558a39f747009f (diff)
downloadjgit-92189b2df42e3eb9ba651b7f9d989ab556f49396.tar.gz
jgit-92189b2df42e3eb9ba651b7f9d989ab556f49396.zip
Fix DiffFormatter NPEs for DiffEntry without content change
DiffEntry.getOldId() returns null for a diff without an index line (e.g. only mode changed, rename without content change). Bug: 407743 Change-Id: I42eac87421f2a53c985af260a253338f578492bc
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
index 820c0c6d78..00e5f06747 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, Google Inc.
+ * Copyright (C) 2010, 2013 Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -257,6 +257,35 @@ public class DiffFormatterTest extends RepositoryTestCase {
}
@Test
+ public void testCreateFileHeaderWithoutIndexLine() throws Exception {
+ DiffEntry m = DiffEntry.modify(PATH_A);
+ m.oldMode = FileMode.REGULAR_FILE;
+ m.newMode = FileMode.EXECUTABLE_FILE;
+
+ FileHeader fh = df.toFileHeader(m);
+ String expected = DIFF + "a/src/a b/src/a\n" + //
+ "old mode 100644\n" + //
+ "new mode 100755\n";
+ assertEquals(expected, fh.getScriptText());
+ }
+
+ @Test
+ public void testCreateFileHeaderForRenameWithoutContentChange() throws Exception {
+ DiffEntry a = DiffEntry.delete(PATH_A, ObjectId.zeroId());
+ DiffEntry b = DiffEntry.add(PATH_B, ObjectId.zeroId());
+ DiffEntry m = DiffEntry.pair(ChangeType.RENAME, a, b, 100);
+ m.oldId = null;
+ m.newId = null;
+
+ FileHeader fh = df.toFileHeader(m);
+ String expected = DIFF + "a/src/a b/src/b\n" + //
+ "similarity index 100%\n" + //
+ "rename from src/a\n" + //
+ "rename to src/b\n";
+ assertEquals(expected, fh.getScriptText());
+ }
+
+ @Test
public void testDiff() throws Exception {
write(new File(db.getDirectory().getParent(), "test.txt"), "test");
File folder = new File(db.getDirectory().getParent(), "folder");