Search in sources :

Example 1 with CommitJob

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

the class StagingView method commit.

private void commit(boolean pushUpstream) {
    if (!isCommitWithoutFilesAllowed()) {
        MessageDialog md = new MessageDialog(getSite().getShell(), UIText.StagingView_committingNotPossible, null, UIText.StagingView_noStagedFiles, MessageDialog.ERROR, new String[] { IDialogConstants.CLOSE_LABEL }, 0);
        md.open();
        return;
    }
    if (!commitMessageComponent.checkCommitInfo())
        return;
    if (!UIUtils.saveAllEditors(currentRepository, UIText.StagingView_cancelCommitAfterSaving))
        return;
    String commitMessage = commitMessageComponent.getCommitMessage();
    CommitOperation commitOperation = null;
    try {
        commitOperation = new CommitOperation(currentRepository, commitMessageComponent.getAuthor(), commitMessageComponent.getCommitter(), commitMessage);
    } catch (CoreException e) {
        Activator.handleError(UIText.StagingView_commitFailed, e, true);
        return;
    }
    if (amendPreviousCommitAction.isChecked())
        commitOperation.setAmending(true);
    final boolean gerritMode = addChangeIdAction.isChecked();
    commitOperation.setComputeChangeId(gerritMode);
    PushMode pushMode = null;
    if (pushUpstream) {
        pushMode = gerritMode ? PushMode.GERRIT : PushMode.UPSTREAM;
    }
    Job commitJob = new CommitJob(currentRepository, commitOperation).setOpenCommitEditor(openNewCommitsAction.isChecked()).setPushUpstream(pushMode);
    // don't allow to do anything as long as commit is in progress
    enableAllWidgets(false);
    commitJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            asyncExec(() -> {
                enableAllWidgets(true);
                if (event.getResult().isOK()) {
                    commitMessageText.setText(EMPTY_STRING);
                }
            });
        }
    });
    schedule(commitJob, true);
    CommitMessageHistory.saveCommitHistory(commitMessage);
    clearCommitMessageToggles();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CommitOperation(org.eclipse.egit.core.op.CommitOperation) CommitJob(org.eclipse.egit.ui.internal.commit.CommitJob) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) CommitJob(org.eclipse.egit.ui.internal.commit.CommitJob) Job(org.eclipse.core.runtime.jobs.Job) PushMode(org.eclipse.egit.ui.internal.push.PushMode)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 CommitOperation (org.eclipse.egit.core.op.CommitOperation)1 CommitJob (org.eclipse.egit.ui.internal.commit.CommitJob)1 PushMode (org.eclipse.egit.ui.internal.push.PushMode)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 WorkbenchJob (org.eclipse.ui.progress.WorkbenchJob)1