package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
assertEquals(expected.toString(), actual);
}
+ @Test
+ public void testNoOutputStreamSet() throws Exception {
+ File file = writeTrashFile("test.txt", "a");
+ assertTrue(file.setLastModified(file.lastModified() - 5000));
+ Git git = new Git(db);
+ git.add().addFilepattern(".").call();
+ write(file, "b");
+
+ List<DiffEntry> diffs = git.diff().call();
+ assertNotNull(diffs);
+ assertEquals(1, diffs.size());
+ DiffEntry diff = diffs.get(0);
+ assertEquals(ChangeType.MODIFY, diff.getChangeType());
+ assertEquals("test.txt", diff.getOldPath());
+ assertEquals("test.txt", diff.getNewPath());
+ }
+
private AbstractTreeIterator getTreeIterator(String name)
throws IOException {
final ObjectId id = db.resolve(name);
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
+import org.eclipse.jgit.util.io.NullOutputStream;
/**
* Show changes between commits, commit and working tree, etc.
* @return a DiffEntry for each path which is different
*/
public List<DiffEntry> call() throws GitAPIException, IOException {
- final DiffFormatter diffFmt = new DiffFormatter(
- new BufferedOutputStream(out));
+ final DiffFormatter diffFmt;
+ if (out != null && !showNameAndStatusOnly)
+ diffFmt = new DiffFormatter(new BufferedOutputStream(out));
+ else
+ diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
diffFmt.setRepository(repo);
diffFmt.setProgressMonitor(monitor);
try {
}
diffFmt.setPathFilter(pathFilter);
- if (contextLines >= 0)
- diffFmt.setContext(contextLines);
- if (destinationPrefix != null)
- diffFmt.setNewPrefix(destinationPrefix);
- if (sourcePrefix != null)
- diffFmt.setOldPrefix(sourcePrefix);
List<DiffEntry> result = diffFmt.scan(oldTree, newTree);
- if (showNameAndStatusOnly) {
+ if (showNameAndStatusOnly)
return result;
- } else {
+ else {
+ if (contextLines >= 0)
+ diffFmt.setContext(contextLines);
+ if (destinationPrefix != null)
+ diffFmt.setNewPrefix(destinationPrefix);
+ if (sourcePrefix != null)
+ diffFmt.setOldPrefix(sourcePrefix);
diffFmt.format(result);
diffFmt.flush();
return result;