private boolean canCommit(File repository) { boolean commitPermitted = true; RepositoryInfo info = RepositoryInfo.getInstance(repository); GitRepositoryState state = info.getRepositoryState(); if (!state.canCommit()) { commitPermitted = false; Map<File, GitStatus> conflicts = Collections.emptyMap(); if (state.equals(GitRepositoryState.MERGING)) { try { GitClient client = Git.getInstance().getClient(repository); conflicts = client.getConflicts(new File[] {repository}, GitUtils.NULL_PROGRESS_MONITOR); } catch (GitException ex) { LOG.log(Level.INFO, null, ex); } } NotifyDescriptor nd; if (conflicts.isEmpty()) { nd = new NotifyDescriptor.Confirmation( NbBundle.getMessage( CommitAction.class, "LBL_CommitAction_CommitNotAllowed_State", state.toString()), // NOI18N NbBundle.getMessage(CommitAction.class, "LBL_CommitAction_CannotCommit"), NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE); // NOI18N } else { nd = new NotifyDescriptor.Confirmation( NbBundle.getMessage( CommitAction.class, "LBL_CommitAction_CommitNotAllowed_Conflicts"), // NOI18N NbBundle.getMessage(CommitAction.class, "LBL_CommitAction_CannotCommit"), NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE); // NOI18N } Object retval = DialogDisplayer.getDefault().notify(nd); if (retval == NotifyDescriptor.YES_OPTION) { GitUtils.openInVersioningView( conflicts.keySet(), repository, GitUtils.NULL_PROGRESS_MONITOR); } } return commitPermitted; }
@Override public void perform() { try { List<File> addCandidates = new LinkedList<File>(); List<File> deleteCandidates = new LinkedList<File>(); List<File> commitCandidates = new LinkedList<File>(); GitCommitParameters parameters = panel.getParameters(); GitClient client = getClient(); populateCandidates(addCandidates, deleteCandidates, commitCandidates); if (isCanceled()) { return; } String message = parameters.getCommitMessage(); GitUser author = parameters.getAuthor(); GitUser commiter = parameters.getCommiter(); Collection<GitHook> hooks = panel.getHooks(); try { outputInRed(NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_TITLE")); // NOI18N outputInRed(NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_TITLE_SEP")); // NOI18N if (addCandidates.size() > 0) { client.add(addCandidates.toArray(new File[addCandidates.size()]), getProgressMonitor()); } if (deleteCandidates.size() > 0) { client.remove( deleteCandidates.toArray(new File[deleteCandidates.size()]), false, getProgressMonitor()); } if (GitModuleConfig.getDefault().getSignOff() && commiter != null) { message += "\nSigned-off-by:" + GitCommitParameters.getUserString(commiter); // NOI18N } String origMessage = message; message = beforeCommitHook(commitCandidates, hooks, message); GitRevisionInfo info = commit(commitCandidates, message, author, commiter); GitModuleConfig.getDefault() .putRecentCommitAuthors(GitCommitParameters.getUserString(author)); GitModuleConfig.getDefault() .putRecentCommiter(GitCommitParameters.getUserString(commiter)); afterCommitHook(commitCandidates, hooks, info, origMessage); } catch (GitException ex) { GitClientExceptionHandler.notifyException(ex, true); } finally { refreshFS(commitCandidates); Git.getInstance().getFileStatusCache().refreshAllRoots(commitCandidates); outputInRed(NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_DONE")); // NOI18N output(""); // NOI18N Git.getInstance() .getHistoryProvider() .fireHistoryChange(commitCandidates.toArray(new File[commitCandidates.size()])); } } catch (GitException ex) { LOG.log(Level.WARNING, null, ex); } }