use of org.eclipse.jgit.treewalk.EmptyTreeIterator in project egit by eclipse.
the class ThreeWayDiffEntryTest method shouldListOutgoingDelete.
@Test
public void shouldListOutgoingDelete() throws Exception {
// given
writeTrashFile("a.txt", "content");
RevCommit c;
try (Git git = new Git(db)) {
git.add().addFilepattern("a.txt").call();
c = git.commit().setMessage("initial commit").call();
}
// when
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(new EmptyTreeIterator());
walk.addTree(c.getTree());
walk.addTree(c.getTree());
List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);
// then
assertThat(result, notNullValue());
assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));
ThreeWayDiffEntry entry = result.get(0);
assertThat(entry.getDirection(), is(Direction.OUTGOING));
assertThat(entry.getChangeType(), is(ChangeType.DELETE));
assertThat(entry.getPath(), is("a.txt"));
}
}
use of org.eclipse.jgit.treewalk.EmptyTreeIterator in project egit by eclipse.
the class ThreeWayDiffEntryTest method shouldListIncomingAddition.
@Test
public void shouldListIncomingAddition() throws Exception {
// given
writeTrashFile("a.txt", "content");
RevCommit c;
try (Git git = new Git(db)) {
git.add().addFilepattern("a.txt").call();
c = git.commit().setMessage("initial commit").call();
}
// when
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(new EmptyTreeIterator());
walk.addTree(new EmptyTreeIterator());
walk.addTree(c.getTree());
List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);
// then
assertThat(result, notNullValue());
assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));
ThreeWayDiffEntry entry = result.get(0);
assertThat(entry.getDirection(), is(Direction.INCOMING));
assertThat(entry.getChangeType(), is(ChangeType.ADD));
assertThat(entry.getPath(), is("a.txt"));
}
}
use of org.eclipse.jgit.treewalk.EmptyTreeIterator in project egit by eclipse.
the class ThreeWayDiffEntryTest method shouldListConflictingChange.
@Test
public void shouldListConflictingChange() throws Exception {
// given
writeTrashFile("a.txt", "content");
RevCommit c;
try (Git git = new Git(db)) {
git.add().addFilepattern("a.txt").call();
c = git.commit().setMessage("initial commit").call();
}
// when
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(new EmptyTreeIterator());
walk.addTree(c.getTree());
walk.addTree(new EmptyTreeIterator());
List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);
// then
assertThat(result, notNullValue());
assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));
ThreeWayDiffEntry entry = result.get(0);
assertThat(entry.getDirection(), is(Direction.CONFLICTING));
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
// assertThat(entry.getNewPath(), is("a.txt"));
// assertThat(entry.getOldPath(), is(DEV_NULL));
}
}
use of org.eclipse.jgit.treewalk.EmptyTreeIterator in project egit by eclipse.
the class ThreeWayDiffEntryTest method shouldListConflictingChange2.
@Test
public void shouldListConflictingChange2() throws Exception {
// given
writeTrashFile("a.txt", "content");
RevCommit c;
try (Git git = new Git(db)) {
git.add().addFilepattern("a.txt").call();
c = git.commit().setMessage("initial commit").call();
}
// when
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(c.getTree());
walk.addTree(new EmptyTreeIterator());
walk.addTree(c.getTree());
List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);
// then
assertThat(result, notNullValue());
assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));
ThreeWayDiffEntry entry = result.get(0);
assertThat(entry.getDirection(), is(Direction.CONFLICTING));
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
assertThat(entry.getPath(), is("a.txt"));
}
}
use of org.eclipse.jgit.treewalk.EmptyTreeIterator in project egit by eclipse.
the class GitSyncCache method loadDataFromGit.
static boolean loadDataFromGit(GitSynchronizeData gsd, TreeFilter filter, GitSyncObjectCache repoCache) {
Repository repo = gsd.getRepository();
try (TreeWalk tw = new TreeWalk(repo)) {
if (filter != null)
tw.setFilter(filter);
// setup local tree
FileTreeIterator fti = null;
if (gsd.shouldIncludeLocal()) {
fti = new FileTreeIterator(repo);
tw.addTree(fti);
if (filter != null)
tw.setFilter(AndTreeFilter.create(filter, new NotIgnoredFilter(0)));
else
tw.setFilter(new NotIgnoredFilter(0));
} else if (gsd.getSrcRevCommit() != null)
tw.addTree(gsd.getSrcRevCommit().getTree());
else
tw.addTree(new EmptyTreeIterator());
// setup base tree
if (gsd.getCommonAncestorRev() != null)
tw.addTree(gsd.getCommonAncestorRev().getTree());
else
tw.addTree(new EmptyTreeIterator());
// setup remote tree
if (gsd.getDstRevCommit() != null)
tw.addTree(gsd.getDstRevCommit().getTree());
else
tw.addTree(new EmptyTreeIterator());
DirCacheIterator dci = null;
if (fti != null) {
dci = new DirCacheIterator(DirCache.read(repo));
tw.addTree(dci);
fti.setDirCacheIterator(tw, 3);
}
List<ThreeWayDiffEntry> diffEntrys = ThreeWayDiffEntry.scan(tw, gsd);
for (ThreeWayDiffEntry diffEntry : diffEntrys) repoCache.addMember(diffEntry);
} catch (Exception e) {
Activator.logError(e.getMessage(), e);
return false;
}
return true;
}
Aggregations