Search in sources :

Example 16 with Commit

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

the class GitCommitsModelCacheTest method shouldListAdditionsOrDeletionsInsideFolderInCommit.

@Test
public void shouldListAdditionsOrDeletionsInsideFolderInCommit() 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 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)));
    assertCommit(leftResult.get(0), c, 2);
    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("folder/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)));
    assertCommit(rightResult.get(0), c, 2);
    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("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)

Example 17 with Commit

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

the class GitModelTestCase method getCommit.

protected Commit getCommit(File repoFile, String rev) throws Exception {
    Repository repo = lookupRepository(repoFile);
    ObjectId revId = repo.resolve(rev);
    Commit commit = mock(Commit.class);
    Mockito.when(commit.getId()).thenReturn(AbbreviatedObjectId.fromObjectId(revId));
    return commit;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) ObjectId(org.eclipse.jgit.lib.ObjectId) AbbreviatedObjectId(org.eclipse.jgit.lib.AbbreviatedObjectId)

Example 18 with Commit

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

the class GitChangeSetLabelProvider method createChangeSetLabel.

private String createChangeSetLabel(GitModelCommit commitModel) {
    String format = store.getString(UIPreferences.SYNC_VIEW_CHANGESET_LABEL_FORMAT);
    Commit commit = commitModel.getCachedCommitObj();
    Map<String, String> bindings = new HashMap<>();
    bindings.put(BINDING_CHANGESET_DATE, dateFormatter.formatDate(commit.getCommitDate()));
    bindings.put(BINDING_CHANGESET_AUTHOR, commit.getAuthorName());
    bindings.put(BINDING_CHANGESET_COMMITTER, commit.getCommitterName());
    bindings.put(BINDING_CHANGESET_SHORT_MESSAGE, commit.getShortMessage());
    return formatName(format, bindings);
}
Also used : Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) HashMap(java.util.HashMap) StyledString(org.eclipse.jface.viewers.StyledString)

Example 19 with Commit

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

the class GitModelRepository method getListOfCommit.

private List<GitModelObjectContainer> getListOfCommit(List<Commit> commitCache) {
    Repository repo = gsd.getRepository();
    Set<IProject> projectsSet = gsd.getProjects();
    IProject[] projects = projectsSet.toArray(new IProject[projectsSet.size()]);
    List<GitModelObjectContainer> result = new ArrayList<>();
    for (Commit commit : commitCache) result.add(new GitModelCommit(this, repo, commit, projects));
    return result;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject)

Example 20 with Commit

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

the class GitModelRepository method getChildren.

@Override
public GitModelObject[] getChildren() {
    List<GitModelObjectContainer> result = new ArrayList<>();
    Repository repo = gsd.getRepository();
    RevCommit srcRevCommit = gsd.getSrcRevCommit();
    RevCommit dstRevCommit = gsd.getDstRevCommit();
    TreeFilter pathFilter = gsd.getPathFilter();
    List<Commit> commitCache;
    if (srcRevCommit != null && dstRevCommit != null)
        try {
            commitCache = GitCommitsModelCache.build(repo, srcRevCommit, dstRevCommit, pathFilter);
        } catch (IOException e) {
            Activator.logError(e.getMessage(), e);
            commitCache = null;
        }
    else
        commitCache = null;
    if (commitCache != null && !commitCache.isEmpty())
        result.addAll(getListOfCommit(commitCache));
    result.addAll(getWorkingChanges());
    disposeOldChildren();
    children = result.toArray(new GitModelObjectContainer[result.size()]);
    return children;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) ArrayList(java.util.ArrayList) TreeFilter(org.eclipse.jgit.treewalk.filter.TreeFilter) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

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