Search in sources :

Example 6 with EmptyTreeIterator

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"));
    }
}
Also used : Git(org.eclipse.jgit.api.Git) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 7 with EmptyTreeIterator

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"));
    }
}
Also used : Git(org.eclipse.jgit.api.Git) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 8 with EmptyTreeIterator

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));
    }
}
Also used : Git(org.eclipse.jgit.api.Git) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 9 with EmptyTreeIterator

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"));
    }
}
Also used : Git(org.eclipse.jgit.api.Git) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 10 with EmptyTreeIterator

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;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) NotIgnoredFilter(org.eclipse.jgit.treewalk.filter.NotIgnoredFilter) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) DirCacheIterator(org.eclipse.jgit.dircache.DirCacheIterator) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) FileTreeIterator(org.eclipse.jgit.treewalk.FileTreeIterator)

Aggregations

EmptyTreeIterator (org.eclipse.jgit.treewalk.EmptyTreeIterator)16 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Git (org.eclipse.jgit.api.Git)6 Test (org.junit.Test)6 ObjectId (org.eclipse.jgit.lib.ObjectId)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 IOException (java.io.IOException)4 DiffEntry (org.eclipse.jgit.diff.DiffEntry)4 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)4 ArrayList (java.util.ArrayList)3 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)3 DirCacheIterator (org.eclipse.jgit.dircache.DirCacheIterator)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2 Repository (org.eclipse.jgit.lib.Repository)2 RevTree (org.eclipse.jgit.revwalk.RevTree)2 AbstractTreeIterator (org.eclipse.jgit.treewalk.AbstractTreeIterator)2 RefModel (com.gitblit.models.RefModel)1