assertEquals(expected, fh.getScriptText());
}
+ @Test
+ public void testCreateFileHeaderForRenameModeChange()
+ throws Exception {
+ DiffEntry a = DiffEntry.delete(PATH_A, ObjectId.zeroId());
+ DiffEntry b = DiffEntry.add(PATH_B, ObjectId.zeroId());
+ b.oldMode = FileMode.REGULAR_FILE;
+ b.newMode = FileMode.EXECUTABLE_FILE;
+ DiffEntry m = DiffEntry.pair(ChangeType.RENAME, a, b, 100);
+ m.oldId = null;
+ m.newId = null;
+
+ FileHeader fh = df.toFileHeader(m);
+ //@formatter:off
+ String expected = DIFF + "a/src/a b/src/b\n" +
+ "old mode 100644\n" +
+ "new mode 100755\n" +
+ "similarity index 100%\n" +
+ "rename from src/a\n" +
+ "rename to src/b\n";
+ //@formatter:on
+ assertEquals(expected, fh.getScriptText());
+ }
+
@Test
public void testDiff() throws Exception {
write(new File(db.getDirectory().getParent(), "test.txt"), "test");
formatGitDiffFirstHeaderLine(o, type, oldp, newp);
+ if ((type == MODIFY || type == COPY || type == RENAME)
+ && !oldMode.equals(newMode)) {
+ o.write(encodeASCII("old mode ")); //$NON-NLS-1$
+ oldMode.copyTo(o);
+ o.write('\n');
+
+ o.write(encodeASCII("new mode ")); //$NON-NLS-1$
+ newMode.copyTo(o);
+ o.write('\n');
+ }
+
switch (type) {
case ADD:
o.write(encodeASCII("new file mode ")); //$NON-NLS-1$
o.write(encode("copy to " + quotePath(newp))); //$NON-NLS-1$
o.write('\n');
-
- if (!oldMode.equals(newMode)) {
- o.write(encodeASCII("new file mode ")); //$NON-NLS-1$
- newMode.copyTo(o);
- o.write('\n');
- }
break;
case MODIFY:
break;
}
- if ((type == MODIFY || type == RENAME) && !oldMode.equals(newMode)) {
- o.write(encodeASCII("old mode ")); //$NON-NLS-1$
- oldMode.copyTo(o);
- o.write('\n');
-
- o.write(encodeASCII("new mode ")); //$NON-NLS-1$
- newMode.copyTo(o);
- o.write('\n');
- }
-
if (ent.getOldId() != null && !ent.getOldId().equals(ent.getNewId())) {
formatIndexLine(o, ent);
}