@Override protected IStatus run(IProgressMonitor monitor) { RevCommit commit = null; try { commitOperation.execute(monitor); commit = commitOperation.getCommit(); CommitMessageComponentStateManager.deleteState(repository); RepositoryMapping mapping = RepositoryMapping.findRepositoryMapping(repository); if (mapping != null) mapping.fireRepositoryChanged(); } catch (CoreException e) { if (e.getCause() instanceof JGitInternalException) return Activator.createErrorStatus(e.getLocalizedMessage(), e.getCause()); return Activator.createErrorStatus(UIText.CommitAction_CommittingFailed, e); } finally { GitLightweightDecorator.refresh(); } if (commit != null) { if (openCommitEditor) openCommitEditor(commit); if (pushUpstream) pushUpstream(commit); } return Status.OK_STATUS; }
private static RevCommit commit( IProject project, String commitMessage, Repository repository, IProgressMonitor monitor) throws CoreException { Assert.isLegal(project != null, "Could not commit project. No project provided"); Assert.isLegal( repository != null, MessageFormat.format( "Could not commit. Project \"{0}\" is not connected to a repository (call #connect(project, repository) first)", project.getName())); /** TODO: add capability to commit selectively */ UserConfig userConfig = getUserConfig(repository); CommitOperation op = new CommitOperation( null, null, null, getFormattedUser(userConfig.getAuthorName(), userConfig.getAuthorEmail()), getFormattedUser(userConfig.getCommitterName(), userConfig.getCommitterEmail()), commitMessage); op.setCommitAll(true); op.setRepository(repository); op.execute(monitor); return op.getCommit(); }
/** * 1 Performs a commit * * @return true if a commit operation was triggered */ public boolean commit() { // let's see if there is any dirty editor around and // 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() { 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()); 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); commitOperation.setComputeChangeId(commitDialog.getCreateChangeId()); commitOperation.setCommitAll(commitHelper.isMergedResolved); if (commitHelper.isMergedResolved) commitOperation.setRepository(repo); Job commitJob = new CommitJob(repo, commitOperation).setPushUpstream(commitDialog.isPushRequested()); commitJob.schedule(); return true; }