Search in sources :

Example 6 with RepositoryCommit

use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.

the class RevertHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final List<RevCommit> commits = getSelectedCommits(event);
    Repository repo = getRepository(event);
    if (repo == null)
        return null;
    try {
        boolean allOnCurrentBranch = true;
        for (RevCommit commit : commits) {
            if (!CommitUtil.isCommitInCurrentBranch(commit, repo)) {
                allOnCurrentBranch = false;
                break;
            }
        }
        if (!allOnCurrentBranch) {
            MessageDialog.openError(HandlerUtil.getActiveShellChecked(event), UIText.RevertHandler_Error_Title, UIText.RevertHandler_CommitsNotOnCurrentBranch);
            return null;
        }
    } catch (IOException e) {
        throw new ExecutionException(UIText.RevertHandler_ErrorCheckingIfCommitsAreOnCurrentBranch, e);
    }
    BasicConfigurationDialog.show(repo);
    List<RepositoryCommit> repositoryCommits = new ArrayList<>();
    for (RevCommit commit : commits) repositoryCommits.add(new RepositoryCommit(repo, commit));
    final IStructuredSelection selected = new StructuredSelection(repositoryCommits);
    CommonUtils.runCommand(org.eclipse.egit.ui.internal.commit.command.RevertHandler.ID, selected);
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 7 with RepositoryCommit

use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.

the class SquashHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Repository repository = getRepository(event);
    List<RevCommit> commits = getSelectedCommits(event);
    try {
        if (!CommitUtil.areCommitsInCurrentBranch(commits, repository)) {
            MessageDialog.openError(getPart(event).getSite().getShell(), UIText.SquashHandler_Error_Title, UIText.SquashHandler_CommitsNotOnCurrentBranch);
            return null;
        }
    } catch (IOException e) {
        throw new ExecutionException(UIText.SquashHandler_ErrorCheckingIfCommitsAreOnCurrentBranch, e);
    }
    List<RepositoryCommit> repositoryCommits = new ArrayList<>();
    for (RevCommit commit : commits) repositoryCommits.add(new RepositoryCommit(repository, commit));
    final IStructuredSelection selected = new StructuredSelection(repositoryCommits);
    CommonUtils.runCommand(org.eclipse.egit.ui.internal.commit.command.SquashHandler.ID, selected);
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 8 with RepositoryCommit

use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.

the class CommitResultLabelProvider method getStyledText.

/**
 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
 */
@Override
public StyledString getStyledText(Object element) {
    StyledString styled = new StyledString();
    if (element instanceof RepositoryCommit) {
        RepositoryCommit commit = (RepositoryCommit) element;
        RevCommit revCommit = commit.getRevCommit();
        styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionMessage, commit.abbreviate(), revCommit.getShortMessage()));
        PersonIdent author = revCommit.getAuthorIdent();
        if (author != null)
            styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionAuthor, author.getName(), dateFormatter.formatDate(author)), StyledString.QUALIFIER_STYLER);
        if (layout == AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT)
            styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionRepository, commit.getRepositoryName()), StyledString.DECORATIONS_STYLER);
    } else if (element instanceof RepositoryMatch) {
        RepositoryMatch repository = (RepositoryMatch) element;
        styled.append(repository.getLabel(repository));
        // $NON-NLS-1$
        styled.append(" - ", StyledString.QUALIFIER_STYLER);
        styled.append(repository.getRepository().getDirectory().getAbsolutePath(), StyledString.QUALIFIER_STYLER);
        styled.append(// $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        " ({0})", Integer.valueOf(repository.getMatchCount())), StyledString.COUNTER_STYLER);
    }
    return styled;
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) StyledString(org.eclipse.jface.viewers.StyledString) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 9 with RepositoryCommit

use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.

the class CommitSearchQueryTest method validateResult.

private void validateResult(RevCommit expectedCommit, Repository expectedRepository, ISearchResult result) {
    assertNotNull(result);
    assertTrue(result instanceof CommitSearchResult);
    CommitSearchResult commitResult = (CommitSearchResult) result;
    assertEquals(1, commitResult.getMatchCount());
    Object[] elements = commitResult.getElements();
    assertNotNull(elements);
    assertEquals(1, elements.length);
    assertTrue(elements[0] instanceof RepositoryCommit);
    RepositoryCommit repoCommit = (RepositoryCommit) elements[0];
    assertEquals(expectedRepository.getDirectory(), repoCommit.getRepository().getDirectory());
    assertEquals(expectedCommit, repoCommit.getRevCommit());
}
Also used : RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) CommitSearchResult(org.eclipse.egit.ui.internal.search.CommitSearchResult)

Example 10 with RepositoryCommit

use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.

the class OpenCommand method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final List<RepositoryTreeNode> nodes = getSelectedNodes(event);
    if (nodes.isEmpty())
        return null;
    final RepositoryTreeNode node = nodes.get(0);
    if (node instanceof RefNode || node instanceof TagNode)
        return new CheckoutCommand().execute(event);
    if (node instanceof FileNode)
        return new OpenInEditorCommand().execute(event);
    if (node instanceof StashedCommitNode) {
        RepositoryCommit repositoryCommit = new RepositoryCommit(node.getRepository(), ((StashedCommitNode) node).getObject());
        repositoryCommit.setStash(true);
        CommitEditor.openQuiet(repositoryCommit);
    }
    return null;
}
Also used : RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) StashedCommitNode(org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode) FileNode(org.eclipse.egit.ui.internal.repository.tree.FileNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode)

Aggregations

RepositoryCommit (org.eclipse.egit.ui.internal.commit.RepositoryCommit)34 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 Repository (org.eclipse.jgit.lib.Repository)13 Test (org.junit.Test)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IOException (java.io.IOException)6 ExecutionException (org.eclipse.core.commands.ExecutionException)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6 ArrayList (java.util.ArrayList)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 UIText (org.eclipse.egit.ui.internal.UIText)4 RevWalk (org.eclipse.jgit.revwalk.RevWalk)4 IEditorPart (org.eclipse.ui.IEditorPart)4 CommitEditorInput (org.eclipse.egit.ui.internal.commit.CommitEditorInput)3 PartInitException (org.eclipse.ui.PartInitException)3 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2