Search in sources :

Example 1 with CommitDialog

use of org.eclipse.egit.ui.internal.dialogs.CommitDialog in project egit by eclipse.

the class CommitUI method commit.

/**
 * Performs a commit
 *
 * @return true if a commit operation was triggered
 */
public boolean commit() {
    // ask the user if they want to save or abort
    if (!UIUtils.saveAllEditors(repo))
        return false;
    BasicConfigurationDialog.show(new Repository[] { repo });
    resetState();
    final IProject[] projects = getProjectsOfRepositories();
    try {
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    buildIndexHeadDiffList(projects, monitor);
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        Activator.handleError(UIText.CommitAction_errorComputingDiffs, e.getCause(), true);
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    CommitHelper commitHelper = new CommitHelper(repo);
    if (!commitHelper.canCommit()) {
        MessageDialog.openError(shell, UIText.CommitAction_cannotCommit, commitHelper.getCannotCommitMessage());
        return false;
    }
    boolean amendAllowed = commitHelper.amendAllowed();
    if (files.isEmpty()) {
        if (amendAllowed && commitHelper.getPreviousCommit() != null) {
            boolean result = MessageDialog.openQuestion(shell, UIText.CommitAction_noFilesToCommit, UIText.CommitAction_amendCommit);
            if (!result)
                return false;
            amending = true;
        } else {
            MessageDialog.openWarning(shell, UIText.CommitAction_noFilesToCommit, UIText.CommitAction_amendNotPossible);
            return false;
        }
    }
    CommitDialog commitDialog = new CommitDialog(shell);
    commitDialog.setAmending(amending);
    commitDialog.setAmendAllowed(amendAllowed);
    commitDialog.setFiles(repo, files, indexDiff);
    commitDialog.setPreselectedFiles(getSelectedFiles(repo, files, selectedResources));
    commitDialog.setPreselectAll(preselectAll);
    commitDialog.setAuthor(commitHelper.getAuthor());
    commitDialog.setCommitter(commitHelper.getCommitter());
    commitDialog.setAllowToChangeSelection(!commitHelper.isMergedResolved && !commitHelper.isCherryPickResolved);
    commitDialog.setCommitMessage(commitHelper.getCommitMessage());
    if (commitDialog.open() != IDialogConstants.OK_ID)
        return false;
    final CommitOperation commitOperation;
    try {
        commitOperation = new CommitOperation(repo, commitDialog.getSelectedFiles(), notTracked, commitDialog.getAuthor(), commitDialog.getCommitter(), commitDialog.getCommitMessage());
    } catch (CoreException e1) {
        Activator.handleError(UIText.CommitUI_commitFailed, e1, true);
        return false;
    }
    if (commitDialog.isAmending())
        commitOperation.setAmending(true);
    final boolean gerritMode = commitDialog.getCreateChangeId();
    PushMode pushMode = null;
    if (commitDialog.isPushRequested()) {
        pushMode = gerritMode ? PushMode.GERRIT : PushMode.UPSTREAM;
    }
    commitOperation.setComputeChangeId(gerritMode);
    commitOperation.setCommitAll(commitHelper.isMergedResolved);
    if (commitHelper.isMergedResolved)
        commitOperation.setRepository(repo);
    Job commitJob = new CommitJob(repo, commitOperation).setPushUpstream(pushMode);
    commitJob.schedule();
    return true;
}
Also used : CommitDialog(org.eclipse.egit.ui.internal.dialogs.CommitDialog) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) PushMode(org.eclipse.egit.ui.internal.push.PushMode) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) CommitOperation(org.eclipse.egit.core.op.CommitOperation) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 CommitOperation (org.eclipse.egit.core.op.CommitOperation)1 CommitDialog (org.eclipse.egit.ui.internal.dialogs.CommitDialog)1 PushMode (org.eclipse.egit.ui.internal.push.PushMode)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1