Search in sources :

Example 1 with RefNode

use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.

the class AbstractHistoryCommandHandler method getRefNodes.

/**
 * Utility to get a list of Refs from a commit in order to handle ambiguous
 * selections when a Ref is preferred over a commit.
 *
 * @param commit
 * @param repo
 * @param refPrefixes
 *            e.g. "refs/heads/" or ""
 * @return a list of RefNodes
 */
protected List<RefNode> getRefNodes(ObjectId commit, Repository repo, String... refPrefixes) {
    List<Ref> availableBranches = new ArrayList<>();
    List<RefNode> nodes = new ArrayList<>();
    try {
        Map<String, Ref> branches = new HashMap<>();
        for (String refPrefix : refPrefixes) {
            branches.putAll(repo.getRefDatabase().getRefs(refPrefix));
        }
        for (Ref branch : branches.values()) {
            ObjectId objectId = branch.getLeaf().getObjectId();
            if (objectId != null && objectId.equals(commit)) {
                availableBranches.add(branch);
            }
        }
        RepositoryNode repoNode = new RepositoryNode(null, repo);
        for (Ref ref : availableBranches) {
            nodes.add(new RefNode(repoNode, repo, ref));
        }
    } catch (IOException e) {
    // ignore here
    }
    return nodes;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) HashMap(java.util.HashMap) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode)

Example 2 with RefNode

use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.

the class DeleteBranchDialog method refNameFromDialog.

@Override
protected String refNameFromDialog() {
    selectedRefs.clear();
    Set<String> selected = new HashSet<>();
    IStructuredSelection selection = (IStructuredSelection) branchTree.getSelection();
    for (Object sel : selection.toArray()) {
        if (!(sel instanceof RefNode))
            continue;
        RefNode node = (RefNode) sel;
        Ref ref = node.getObject();
        selectedRefs.add(ref);
        selected.add(ref.getName());
    }
    boolean enabled = !selected.isEmpty() && !selected.contains(currentBranch);
    getButton(Window.OK).setEnabled(enabled);
    return null;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashSet(java.util.HashSet) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode)

Example 3 with RefNode

use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.

the class DeleteBranchDialog method buttonPressed.

@Override
protected void buttonPressed(int buttonId) {
    if (buttonId == Window.OK) {
        try {
            int result = deleteBranch(selectedRefs, false);
            if (result == DeleteBranchOperation.REJECTED_UNMERGED) {
                List<RefNode> nodes = extractSelectedRefNodes();
                MessageDialog messageDialog = new UnmergedBranchDialog<>(getShell(), nodes);
                if (messageDialog.open() == Window.OK)
                    deleteBranch(selectedRefs, true);
                else
                    return;
            } else if (result == DeleteBranchOperation.REJECTED_CURRENT)
                Activator.handleError(UIText.DeleteBranchCommand_CannotDeleteCheckedOutBranch, null, true);
        } catch (CoreException e) {
            Activator.handleError(e.getMessage(), e, true);
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode)

Example 4 with RefNode

use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.

the class AbstractBranchSelectionDialog method createRefNode.

private RefNode createRefNode(RepositoryTreeNode<?> root, Repository repository, Ref ref) {
    IContentProvider cp = branchTree.getContentProvider();
    if (cp instanceof RepositoriesViewContentProvider && ((RepositoriesViewContentProvider) cp).isHierarchical()) {
        // Create intermediary BranchHierarchyNodes
        String fullName = ref.getName();
        int i = 0;
        if (fullName.startsWith(Constants.R_HEADS)) {
            i = Constants.R_HEADS.length();
        } else if (fullName.startsWith(Constants.R_REMOTES)) {
            i = Constants.R_REMOTES.length();
        }
        RepositoryTreeNode<?> top = root;
        int l = fullName.length();
        while (i < l) {
            int j = fullName.indexOf('/', i);
            if (j > i) {
                top = new BranchHierarchyNode(top, repository, new Path(fullName.substring(0, j)));
                i = j + 1;
            } else {
                break;
            }
        }
        return new RefNode(top, repository, ref);
    } else {
        return new RefNode(root, repository, ref);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IContentProvider(org.eclipse.jface.viewers.IContentProvider) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) BranchHierarchyNode(org.eclipse.egit.ui.internal.repository.tree.BranchHierarchyNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode)

Example 5 with RefNode

use of org.eclipse.egit.ui.internal.repository.tree.RefNode in project egit by eclipse.

the class MergeCommand method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode node = getSelectedNodes(event).get(0);
    final Repository repository = node.getRepository();
    if (!MergeActionHandler.checkMergeIsPossible(repository, getShell(event)) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
        return null;
    }
    BasicConfigurationDialog.show(repository);
    String targetRef;
    if (node instanceof RefNode) {
        String refName = ((RefNode) node).getObject().getName();
        try {
            if (refName.equals(repository.getFullBranch()))
                targetRef = null;
            else
                targetRef = refName;
        } catch (IOException e) {
            targetRef = null;
        }
    } else if (node instanceof TagNode)
        targetRef = ((TagNode) node).getObject().getName();
    else
        targetRef = null;
    final String refName;
    final MergeOperation op;
    if (targetRef != null) {
        refName = targetRef;
        op = new MergeOperation(repository, refName);
    } else {
        MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog(getShell(event), repository);
        if (mergeTargetSelectionDialog.open() != IDialogConstants.OK_ID)
            return null;
        refName = mergeTargetSelectionDialog.getRefName();
        op = new MergeOperation(repository, refName);
        op.setSquash(mergeTargetSelectionDialog.isMergeSquash());
        op.setFastForwardMode(mergeTargetSelectionDialog.getFastForwardMode());
        op.setCommit(mergeTargetSelectionDialog.isCommit());
    }
    String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName);
    Job job = new WorkspaceJob(jobname) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
            } catch (final CoreException e) {
                return e.getStatus();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent jobEvent) {
            IStatus result = jobEvent.getJob().getResult();
            if (result.getSeverity() == IStatus.CANCEL)
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        // don't use getShell(event) here since
                        // the active shell has changed since the
                        // execution has been triggered.
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MessageDialog.openInformation(shell, UIText.MergeAction_MergeCanceledTitle, UIText.MergeAction_MergeCanceledMessage);
                    }
                });
            else if (!result.isOK())
                Activator.handleError(result.getMessage(), result.getException(), true);
            else
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MergeResultDialog.getDialog(shell, repository, op.getResult()).open();
                    }
                });
        }
    });
    job.schedule();
    return null;
}
Also used : MergeOperation(org.eclipse.egit.core.op.MergeOperation) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) MergeTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) CoreException(org.eclipse.core.runtime.CoreException) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Aggregations

RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)13 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)6 TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)5 FileNode (org.eclipse.egit.ui.internal.repository.tree.FileNode)4 Ref (org.eclipse.jgit.lib.Ref)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 AdditionalRefNode (org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode)3 RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)3 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)3 Repository (org.eclipse.jgit.lib.Repository)3 File (java.io.File)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 BranchHierarchyNode (org.eclipse.egit.ui.internal.repository.tree.BranchHierarchyNode)2 FetchNode (org.eclipse.egit.ui.internal.repository.tree.FetchNode)2 FolderNode (org.eclipse.egit.ui.internal.repository.tree.FolderNode)2 PushNode (org.eclipse.egit.ui.internal.repository.tree.PushNode)2