aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff
diff options
context:
space:
mode:
authorKevin Sawicki <kevin@github.com>2011-12-14 17:51:42 -0800
committerKevin Sawicki <kevin@github.com>2011-12-14 17:51:42 -0800
commit78bc526d9b7e5063d267a76b0bbefaa989139bf3 (patch)
treecdbc3b2b8157701e0292138698ff400970b2117c /org.eclipse.jgit.test/tst/org/eclipse/jgit/diff
parent84c80be1dc45885969e2d0fa0421f709b8706453 (diff)
downloadjgit-78bc526d9b7e5063d267a76b0bbefaa989139bf3.tar.gz
jgit-78bc526d9b7e5063d267a76b0bbefaa989139bf3.zip
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
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/diff')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
index 21069efa56..cb7cad8340 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
+++ b/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());
+ }
}