summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2013-05-16 18:41:52 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2013-05-16 18:41:52 -0400
commit84ad4957c6a1479032ad24a216904f87f1e02f40 (patch)
tree2ea3525650efef8e4dab3d18e664930a1a3f0efa
parente7fc19fc0c8099a7076d883798d3439403bdbb6e (diff)
parent92189b2df42e3eb9ba651b7f9d989ab556f49396 (diff)
downloadjgit-84ad4957c6a1479032ad24a216904f87f1e02f40.tar.gz
jgit-84ad4957c6a1479032ad24a216904f87f1e02f40.zip
Merge "Fix DiffFormatter NPEs for DiffEntry without content change" into stable-3.0
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java31
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java7
2 files changed, 36 insertions, 2 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");
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index 11848e2c99..f660d6bbd9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -912,6 +912,11 @@ public class DiffFormatter {
editList = new EditList();
type = PatchType.UNIFIED;
+ } else if (ent.getOldId() == null || ent.getNewId() == null) {
+ // Content not changed (e.g. only mode, pure rename)
+ editList = new EditList();
+ type = PatchType.UNIFIED;
+
} else {
assertHaveRepository();
@@ -1106,7 +1111,7 @@ public class DiffFormatter {
o.write('\n');
}
- if (!ent.getOldId().equals(ent.getNewId())) {
+ if (ent.getOldId() != null && !ent.getOldId().equals(ent.getNewId())) {
formatIndexLine(o, ent);
}
}