Merge branch 'stable-4.1' into stable-4.2
* stable-4.1: Fix diff for added and removed submodule Change-Id: I37dd71ed19b06e9bbcffe37370081ab875c6d8d4 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
commit
26012958a3
|
@ -259,6 +259,68 @@ public void testCreateFileHeader_GitLink() throws Exception {
|
||||||
assertEquals(1, hh.toEditList().size());
|
assertEquals(1, hh.toEditList().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testCreateFileHeaderWithoutIndexLine() throws Exception {
|
public void testCreateFileHeaderWithoutIndexLine() throws Exception {
|
||||||
DiffEntry m = DiffEntry.modify(PATH_A);
|
DiffEntry m = DiffEntry.modify(PATH_A);
|
||||||
|
|
|
@ -666,6 +666,9 @@ public void format(DiffEntry ent) throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] writeGitLinkText(AbbreviatedObjectId id) {
|
private static byte[] writeGitLinkText(AbbreviatedObjectId id) {
|
||||||
|
if (id.toObjectId().equals(ObjectId.zeroId())) {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$
|
return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$
|
||||||
+ "\n"); //$NON-NLS-1$
|
+ "\n"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue