Search in sources :

Example 16 with Change

use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.

the class StagedChangeCacheTest method shouldListTwoWorkspaceDeletions.

@Test
public void shouldListTwoWorkspaceDeletions() throws Exception {
    // given
    try (Git git = new Git(db)) {
        writeTrashFile(db, "a.txt", "trash");
        writeTrashFile(db, "b.txt", "trash");
        git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();
        git.commit().setMessage("new commit").call();
        git.rm().addFilepattern("a.txt").addFilepattern("b.txt").call();
    }
    // when
    Map<String, Change> result = StagedChangeCache.build(db);
    // then
    assertThat(result.size(), is(2));
    assertFileDeletion(result, "a.txt", "a.txt");
    assertFileDeletion(result, "b.txt", "b.txt");
}
Also used : Git(org.eclipse.jgit.api.Git) Change(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change) Test(org.junit.Test)

Example 17 with Change

use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.

the class StagedChangeCacheTest method shouldListSingleWorkspaceChange.

@Test
public void shouldListSingleWorkspaceChange() throws Exception {
    // given
    try (Git git = new Git(db)) {
        writeTrashFile(db, "a.txt", "trash");
        git.add().addFilepattern("a.txt").call();
        git.commit().setMessage("initial a.txt commit").call();
        writeTrashFile(db, "a.txt", "modification");
        git.add().addFilepattern("a.txt").call();
    }
    // when
    Map<String, Change> result = StagedChangeCache.build(db);
    // then
    assertThat(result.size(), is(1));
    assertFileChange(result, "a.txt", "a.txt");
}
Also used : Git(org.eclipse.jgit.api.Git) Change(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change) Test(org.junit.Test)

Example 18 with Change

use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.

the class WorkingTreeChangeCache method build.

/**
 * @param repo
 *            with should be scanned
 * @return list of changes in working tree
 */
public static Map<String, Change> build(Repository repo) {
    try (TreeWalk tw = new TreeWalk(repo)) {
        int fileNth = tw.addTree(new FileTreeIterator(repo));
        int cacheNth = tw.addTree(new DirCacheIterator(repo.readDirCache()));
        tw.setFilter(new IndexDiffFilter(cacheNth, fileNth));
        tw.setRecursive(true);
        Map<String, Change> result = new HashMap<String, Change>();
        MutableObjectId idBuf = new MutableObjectId();
        while (tw.next()) {
            Change change = new Change();
            change.name = tw.getNameString();
            tw.getObjectId(idBuf, 0);
            change.objectId = AbbreviatedObjectId.fromObjectId(idBuf);
            tw.getObjectId(idBuf, 1);
            change.remoteObjectId = AbbreviatedObjectId.fromObjectId(idBuf);
            calculateAndSetChangeKind(RIGHT, change);
            result.put(tw.getPathString(), change);
        }
        return result;
    } catch (IOException e) {
        Activator.logError(e.getMessage(), e);
        return new HashMap<String, GitCommitsModelCache.Change>(0);
    }
}
Also used : MutableObjectId(org.eclipse.jgit.lib.MutableObjectId) IndexDiffFilter(org.eclipse.jgit.treewalk.filter.IndexDiffFilter) HashMap(java.util.HashMap) DirCacheIterator(org.eclipse.jgit.dircache.DirCacheIterator) Change(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change) IOException(java.io.IOException) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) FileTreeIterator(org.eclipse.jgit.treewalk.FileTreeIterator)

Example 19 with Change

use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.

the class ChangeTest method shouldNotBeEqualWhenOneRemoteObjectIsNull.

@Test
public void shouldNotBeEqualWhenOneRemoteObjectIsNull() {
    // given
    Change c1 = new Change();
    Change c2 = new Change();
    c1.objectId = c2.commitId = ZERO_ID;
    c1.remoteObjectId = MISC_ID;
    // when
    boolean result = c1.equals(c2);
    // then
    assertFalse(result);
    assertFalse(c1.hashCode() == c2.hashCode());
}
Also used : Change(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change) Test(org.junit.Test)

Example 20 with Change

use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.

the class ChangeTest method shouldBeEqualWhenBothIdsAreNull.

@Test
public void shouldBeEqualWhenBothIdsAreNull() {
    // given
    Change change = new Change();
    // when
    boolean result = change.equals(new Change());
    // then
    assertTrue(result);
}
Also used : Change(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change) Test(org.junit.Test)

Aggregations

Change (org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change)35 Test (org.junit.Test)29 Git (org.eclipse.jgit.api.Git)21 HashMap (java.util.HashMap)3 Repository (org.eclipse.jgit.lib.Repository)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IPath (org.eclipse.core.runtime.IPath)2 DirCacheIterator (org.eclipse.jgit.dircache.DirCacheIterator)2 MutableObjectId (org.eclipse.jgit.lib.MutableObjectId)2 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)2 Map (java.util.Map)1 Path (org.eclipse.core.runtime.Path)1 FileModelFactory (org.eclipse.egit.ui.internal.synchronize.model.TreeBuilder.FileModelFactory)1 TreeModelFactory (org.eclipse.egit.ui.internal.synchronize.model.TreeBuilder.TreeModelFactory)1 AbbreviatedObjectId (org.eclipse.jgit.lib.AbbreviatedObjectId)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 EmptyTreeIterator (org.eclipse.jgit.treewalk.EmptyTreeIterator)1