Browse Source

Report diff entries for files that only change mode

This also updates DiffFormatter to not write path lines
for entries that have the same object id

Bug: 361570
Change-Id: I830a78e2babf472503630a7aa020ebfd5c7e69c6
stable-1.3
Kevin Sawicki 13 years ago
parent
commit
78bc526d9b
  1. 42
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
  2. 3
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffEntry.java
  3. 3
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

42
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java

@ -46,13 +46,20 @@ import static org.eclipse.jgit.diff.DiffEntry.DEV_NULL;
import static org.eclipse.jgit.util.FileUtils.delete;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
@ -295,4 +302,39 @@ public class DiffEntryTest extends RepositoryTestCase {
DiffEntry.scan(walk, true);
}
@Test
public void shouldReportFileModeChange() throws Exception {
writeTrashFile("a.txt", "content");
Git git = new Git(db);
git.add().addFilepattern("a.txt").call();
RevCommit c1 = git.commit().setMessage("initial commit").call();
DirCache cache = db.lockDirCache();
DirCacheEditor editor = cache.editor();
final TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.setRecursive(true);
assertTrue(walk.next());
editor.add(new PathEdit("a.txt") {
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.EXECUTABLE_FILE);
ent.setObjectId(walk.getObjectId(0));
}
});
assertTrue(editor.commit());
RevCommit c2 = git.commit().setMessage("second commit").call();
walk.reset();
walk.addTree(c1.getTree());
walk.addTree(c2.getTree());
List<DiffEntry> diffs = DiffEntry.scan(walk, false);
assertEquals(1, diffs.size());
DiffEntry diff = diffs.get(0);
assertEquals(ChangeType.MODIFY,diff.getChangeType());
assertEquals(diff.getOldId(), diff.getNewId());
assertEquals("a.txt", diff.getOldPath());
assertEquals(diff.getOldPath(), diff.getNewPath());
assertEquals(FileMode.EXECUTABLE_FILE, diff.getNewMode());
assertEquals(FileMode.REGULAR_FILE, diff.getOldMode());
}
}

3
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffEntry.java

@ -172,6 +172,9 @@ public class DiffEntry {
r.add(entry);
else
r.addAll(breakModify(entry));
} else if (entry.oldMode != entry.newMode) {
entry.changeType = ChangeType.MODIFY;
r.add(entry);
}
if (includeTrees && walk.isSubtree())

3
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -1088,6 +1088,9 @@ public class DiffFormatter {
private void formatOldNewPaths(ByteArrayOutputStream o, DiffEntry ent)
throws IOException {
if (ent.oldId.equals(ent.newId))
return;
final String oldp;
final String newp;

Loading…
Cancel
Save