|
|
|
@ -45,13 +45,21 @@ package org.eclipse.jgit.diff;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
import java.io.BufferedOutputStream; |
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
|
|
import org.eclipse.jgit.api.Git; |
|
|
|
|
import org.eclipse.jgit.diff.DiffEntry.ChangeType; |
|
|
|
|
import org.eclipse.jgit.dircache.DirCacheIterator; |
|
|
|
|
import org.eclipse.jgit.junit.TestRepository; |
|
|
|
|
import org.eclipse.jgit.lib.FileMode; |
|
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
|
import org.eclipse.jgit.lib.RepositoryTestCase; |
|
|
|
|
import org.eclipse.jgit.patch.FileHeader; |
|
|
|
|
import org.eclipse.jgit.patch.HunkHeader; |
|
|
|
|
import org.eclipse.jgit.treewalk.FileTreeIterator; |
|
|
|
|
import org.eclipse.jgit.treewalk.filter.PathFilter; |
|
|
|
|
import org.eclipse.jgit.util.RawParseUtils; |
|
|
|
|
import org.eclipse.jgit.util.io.DisabledOutputStream; |
|
|
|
|
import org.junit.After; |
|
|
|
@ -247,6 +255,38 @@ public class DiffFormatterTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(0, hh.toEditList().size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDiff() throws Exception { |
|
|
|
|
write(new File(db.getDirectory().getParent(), "test.txt"), "test"); |
|
|
|
|
File folder = new File(db.getDirectory().getParent(), "folder"); |
|
|
|
|
folder.mkdir(); |
|
|
|
|
write(new File(folder, "folder.txt"), "folder"); |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
git.add().addFilepattern(".").call(); |
|
|
|
|
git.commit().setMessage("Initial commit").call(); |
|
|
|
|
write(new File(folder, "folder.txt"), "folder change"); |
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
|
|
|
|
DiffFormatter df = new DiffFormatter(new BufferedOutputStream(os)); |
|
|
|
|
df.setRepository(db); |
|
|
|
|
df.setPathFilter(PathFilter.create("folder")); |
|
|
|
|
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache()); |
|
|
|
|
FileTreeIterator newTree = new FileTreeIterator(db); |
|
|
|
|
df.format(oldTree, newTree); |
|
|
|
|
df.flush(); |
|
|
|
|
|
|
|
|
|
String actual = os.toString(); |
|
|
|
|
String expected = |
|
|
|
|
"diff --git a/folder/folder.txt b/folder/folder.txt\n" |
|
|
|
|
+ "index 0119635..95c4c65 100644\n" |
|
|
|
|
+ "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" |
|
|
|
|
+ "@@ -1 +1 @@\n" + "-folder\n" |
|
|
|
|
+ "\\ No newline at end of file\n" + "+folder change\n" |
|
|
|
|
+ "\\ No newline at end of file\n"; |
|
|
|
|
|
|
|
|
|
assertEquals(expected.toString(), actual); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String makeDiffHeader(String pathA, String pathB, ObjectId aId, |
|
|
|
|
ObjectId bId) { |
|
|
|
|
String a = aId.abbreviate(8).name(); |
|
|
|
|