Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Arès2016-02-04 13:55:20 +0000
committerHugo Arès2016-02-04 15:27:50 +0000
commitdf904a4227360741635bf7aa6a6ad5e39057b343 (patch)
tree767c9c9ee9f874de8038e1aa2ddff8eec5b32c8f
parent3e2aff196e4f20183c13fd0c219101b6604477e8 (diff)
downloadjgit-df904a4227360741635bf7aa6a6ad5e39057b343.tar.gz
jgit-df904a4227360741635bf7aa6a6ad5e39057b343.tar.xz
jgit-df904a4227360741635bf7aa6a6ad5e39057b343.zip
Fix diff for added and removed submodule
Since If13f7b406, submodule difference are shown as a hunk. The issue was that added and removed submodule were considered as Edit.REPLACE instead of Edit.INSERT and Edit.DELETE in the DiffFormatter result. Change-Id: I4330c2aa3f10e29d7d6b0b2e5286e59293a06239 Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java62
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java3
2 files changed, 65 insertions, 0 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 24b0f8141e..58348d5117 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
@@ -260,6 +260,68 @@ public class DiffFormatterTest extends RepositoryTestCase {
}
@Test
+ public void testCreateFileHeader_AddGitLink() throws Exception {
+ ObjectId adId = blob("a\nd\n");
+ DiffEntry ent = DiffEntry.add("FOO", adId);
+ ent.newMode = FileMode.GITLINK;
+ FileHeader fh = df.toFileHeader(ent);
+
+ String diffHeader = "diff --git a/FOO b/FOO\n" //
+ + "new file mode " + GITLINK + "\n"
+ + "index "
+ + ObjectId.zeroId().abbreviate(8).name()
+ + ".."
+ + adId.abbreviate(8).name() + "\n" //
+ + "--- /dev/null\n"//
+ + "+++ b/FOO\n";
+ assertEquals(diffHeader, RawParseUtils.decode(fh.getBuffer()));
+
+ assertEquals(1, fh.getHunks().size());
+ HunkHeader hh = fh.getHunks().get(0);
+
+ EditList el = hh.toEditList();
+ assertEquals(1, el.size());
+
+ Edit e = el.get(0);
+ assertEquals(0, e.getBeginA());
+ assertEquals(0, e.getEndA());
+ assertEquals(0, e.getBeginB());
+ assertEquals(1, e.getEndB());
+ assertEquals(Edit.Type.INSERT, e.getType());
+ }
+
+ @Test
+ public void testCreateFileHeader_DeleteGitLink() throws Exception {
+ ObjectId adId = blob("a\nd\n");
+ DiffEntry ent = DiffEntry.delete("FOO", adId);
+ ent.oldMode = FileMode.GITLINK;
+ FileHeader fh = df.toFileHeader(ent);
+
+ String diffHeader = "diff --git a/FOO b/FOO\n" //
+ + "deleted file mode " + GITLINK + "\n"
+ + "index "
+ + adId.abbreviate(8).name()
+ + ".."
+ + ObjectId.zeroId().abbreviate(8).name() + "\n" //
+ + "--- a/FOO\n"//
+ + "+++ /dev/null\n";
+ assertEquals(diffHeader, RawParseUtils.decode(fh.getBuffer()));
+
+ assertEquals(1, fh.getHunks().size());
+ HunkHeader hh = fh.getHunks().get(0);
+
+ EditList el = hh.toEditList();
+ assertEquals(1, el.size());
+
+ Edit e = el.get(0);
+ assertEquals(0, e.getBeginA());
+ assertEquals(1, e.getEndA());
+ assertEquals(0, e.getBeginB());
+ assertEquals(0, e.getEndB());
+ assertEquals(Edit.Type.DELETE, e.getType());
+ }
+
+ @Test
public void testCreateFileHeaderWithoutIndexLine() throws Exception {
DiffEntry m = DiffEntry.modify(PATH_A);
m.oldMode = FileMode.REGULAR_FILE;
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 4c0ed386e8..fc701f3a54 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -666,6 +666,9 @@ public class DiffFormatter implements AutoCloseable {
}
private static byte[] writeGitLinkText(AbbreviatedObjectId id) {
+ if (id.toObjectId().equals(ObjectId.zeroId())) {
+ return EMPTY;
+ }
return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$
+ "\n"); //$NON-NLS-1$
}

Back to the top