Search in sources :

Example 1 with Commit

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

the class GitChangeSetSorter method compare.

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    if (e1 instanceof GitModelBlob && !(e2 instanceof GitModelBlob))
        return 1;
    if (e2 instanceof GitModelBlob && !(e1 instanceof GitModelBlob))
        return -1;
    if (e1 instanceof GitModelWorkingTree)
        return -1;
    if (e2 instanceof GitModelWorkingTree)
        return 1;
    if (e1 instanceof GitModelCache)
        return -2;
    if (e2 instanceof GitModelCache)
        return 2;
    if ((e1 instanceof GitModelTree && e2 instanceof GitModelTree) || (e1 instanceof GitModelBlob && e2 instanceof GitModelBlob))
        return super.compare(viewer, e1, e2);
    if (e1 instanceof GitModelTree && e2 instanceof GitModelCommit)
        return 1;
    if (e1 instanceof GitModelCommit && e2 instanceof GitModelCommit) {
        Commit rc1 = ((GitModelCommit) e1).getCachedCommitObj();
        Commit rc2 = ((GitModelCommit) e2).getCachedCommitObj();
        return rc2.getCommitDate().compareTo(rc1.getCommitDate());
    }
    return super.compare(viewer, e1, e2);
}
Also used : GitModelCache(org.eclipse.egit.ui.internal.synchronize.model.GitModelCache) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob) GitModelWorkingTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree)

Example 2 with Commit

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

the class GitChangeSetSorterTest method shouldOrderCommitsByCommitDate.

/*
	 * Test for commit chronological order
	 */
@Test
public void shouldOrderCommitsByCommitDate() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelCommit commit1 = mock(GitModelCommit.class);
    GitModelCommit commit2 = mock(GitModelCommit.class);
    Commit mockCommit1 = mock(Commit.class);
    Commit mockCommit2 = mock(Commit.class);
    when(mockCommit1.getCommitDate()).thenReturn(new Date(333333L));
    when(mockCommit2.getCommitDate()).thenReturn(new Date(555555L));
    when(commit1.getCachedCommitObj()).thenReturn(mockCommit1);
    when(commit2.getCachedCommitObj()).thenReturn(mockCommit2);
    // when
    int actual1 = sorter.compare(viewer, commit1, commit2);
    int actual2 = sorter.compare(viewer, commit2, commit1);
    // then
    assertTrue(actual1 > 0);
    assertTrue(actual2 < 0);
}
Also used : Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Commit

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

the class GitCommitsModelCacheTest method shouldListChangeInCommit.

@Test
public void shouldListChangeInCommit() throws Exception {
    // given
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "content");
    git.add().addFilepattern("a.txt").call();
    RevCommit c1 = commit(git, "first commit");
    writeTrashFile(db, "a.txt", "new content");
    RevCommit c2 = commit(git, "second commit");
    // when
    List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null);
    List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null);
    // then
    // left assertions
    assertThat(leftResult, notNullValue());
    assertCommit(leftResult.get(0), c2, 1);
    assertFileChange(c2, c1, leftResult.get(0).getChildren().get("a.txt"), "a.txt", LEFT);
    // right asserts
    assertThat(rightResult, notNullValue());
    assertCommit(rightResult.get(0), c2, 1);
    assertFileChange(c2, c1, rightResult.get(0).getChildren().get("a.txt"), "a.txt", RIGHT);
}
Also used : Git(org.eclipse.jgit.api.Git) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 4 with Commit

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

the class GitCommitsModelCacheTest method shouldListAdditionsOrDeletionsInsideSeparateFoldersInCommit.

@Test
public void shouldListAdditionsOrDeletionsInsideSeparateFoldersInCommit() throws Exception {
    // given
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "content");
    writeTrashFile(db, "folder2/b.txt", "b content");
    git.add().addFilepattern("folder/a.txt").call();
    git.add().addFilepattern("folder2/b.txt").call();
    RevCommit c = commit(git, "first commit");
    // when
    List<Commit> leftResult = GitCommitsModelCache.build(db, initialTagId(), c, null);
    List<Commit> rightResult = GitCommitsModelCache.build(db, c, initialTagId(), null);
    // then
    // left assertions
    assertThat(leftResult, notNullValue());
    assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1)));
    assertThat(leftResult.get(0).getShortMessage(), is("first commit"));
    assertThat(leftResult.get(0).getChildren(), notNullValue());
    assertThat(leftResult.get(0).getChildren().size(), is(2));
    assertFileAddition(c, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT);
    assertFileAddition(c, leftResult.get(0).getChildren().get("folder2/b.txt"), "b.txt", LEFT);
    // right asserts, after changing sides addition becomes deletion
    assertThat(rightResult, notNullValue());
    assertThat(Integer.valueOf(rightResult.size()), is(Integer.valueOf(1)));
    assertThat(rightResult.get(0).getShortMessage(), is("first commit"));
    assertThat(rightResult.get(0).getChildren(), notNullValue());
    assertThat(rightResult.get(0).getChildren().size(), is(2));
    assertFileAddition(c, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT);
    assertFileAddition(c, rightResult.get(0).getChildren().get("folder2/b.txt"), "b.txt", RIGHT);
}
Also used : Git(org.eclipse.jgit.api.Git) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 5 with Commit

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

the class GitCommitsModelCacheTest method shouldListChangesInsideFolderInCommit.

@Test
public void shouldListChangesInsideFolderInCommit() throws Exception {
    // given
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "content");
    writeTrashFile(db, "folder/b.txt", "b content");
    git.add().addFilepattern("folder").call();
    RevCommit c1 = commit(git, "first commit");
    writeTrashFile(db, "folder/a.txt", "new content");
    writeTrashFile(db, "folder/b.txt", "new b content");
    RevCommit c2 = commit(git, "second commit");
    // when
    List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null);
    List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null);
    // then
    // left assertions
    assertThat(leftResult, notNullValue());
    assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1)));
    assertCommit(leftResult.get(0), c2, 2);
    assertFileChange(c2, c1, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT);
    assertFileChange(c2, c1, leftResult.get(0).getChildren().get("folder/b.txt"), "b.txt", LEFT);
    // right asserts
    assertThat(rightResult, notNullValue());
    assertThat(Integer.valueOf(rightResult.size()), is(Integer.valueOf(1)));
    assertCommit(rightResult.get(0), c2, 2);
    assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT);
    assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder/b.txt"), "b.txt", RIGHT);
}
Also used : Git(org.eclipse.jgit.api.Git) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

Commit (org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 Test (org.junit.Test)15 Git (org.eclipse.jgit.api.Git)14 GitModelCommit (org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit)3 Repository (org.eclipse.jgit.lib.Repository)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 IProject (org.eclipse.core.resources.IProject)1 GitModelBlob (org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)1 GitModelCache (org.eclipse.egit.ui.internal.synchronize.model.GitModelCache)1 GitModelTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelTree)1 GitModelWorkingTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree)1 StyledString (org.eclipse.jface.viewers.StyledString)1 Viewer (org.eclipse.jface.viewers.Viewer)1 AbbreviatedObjectId (org.eclipse.jgit.lib.AbbreviatedObjectId)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 PathFilter (org.eclipse.jgit.treewalk.filter.PathFilter)1