use of com.intellij.dvcs.push.ui.VcsPushDialog in project intellij-community by JetBrains.
the class GitCheckinEnvironment method commit.
public List<VcsException> commit(@NotNull List<Change> changes, @NotNull String message, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
List<VcsException> exceptions = new ArrayList<>();
Map<VirtualFile, Collection<Change>> sortedChanges = sortChangesByGitRoot(changes, exceptions);
LOG.assertTrue(!sortedChanges.isEmpty(), "Trying to commit an empty list of changes: " + changes);
for (Map.Entry<VirtualFile, Collection<Change>> entry : sortedChanges.entrySet()) {
VirtualFile root = entry.getKey();
File messageFile;
try {
messageFile = createMessageFile(root, message);
} catch (IOException ex) {
//noinspection ThrowableInstanceNeverThrown
exceptions.add(new VcsException("Creation of commit message file failed", ex));
continue;
}
Set<FilePath> added = new HashSet<>();
Set<FilePath> removed = new HashSet<>();
final Set<Change> caseOnlyRenames = new HashSet<>();
for (Change change : entry.getValue()) {
switch(change.getType()) {
case NEW:
case MODIFICATION:
added.add(change.getAfterRevision().getFile());
break;
case DELETED:
removed.add(change.getBeforeRevision().getFile());
break;
case MOVED:
FilePath afterPath = change.getAfterRevision().getFile();
FilePath beforePath = change.getBeforeRevision().getFile();
if (!SystemInfo.isFileSystemCaseSensitive && GitUtil.isCaseOnlyChange(beforePath.getPath(), afterPath.getPath())) {
caseOnlyRenames.add(change);
} else {
added.add(afterPath);
removed.add(beforePath);
}
break;
default:
throw new IllegalStateException("Unknown change type: " + change.getType());
}
}
try {
if (!caseOnlyRenames.isEmpty()) {
List<VcsException> exs = commitWithCaseOnlyRename(myProject, root, caseOnlyRenames, added, removed, messageFile, myNextCommitAuthor);
exceptions.addAll(map(exs, GitCheckinEnvironment::cleanupExceptionText));
} else {
try {
Set<FilePath> files = new HashSet<>();
files.addAll(added);
files.addAll(removed);
commit(myProject, root, files, messageFile);
} catch (VcsException ex) {
PartialOperation partialOperation = isMergeCommit(ex);
if (partialOperation == PartialOperation.NONE) {
throw ex;
}
if (!mergeCommit(myProject, root, added, removed, messageFile, myNextCommitAuthor, exceptions, partialOperation)) {
throw ex;
}
}
}
} catch (VcsException e) {
exceptions.add(cleanupExceptionText(e));
} finally {
if (!messageFile.delete()) {
LOG.warn("Failed to remove temporary file: " + messageFile);
}
}
}
if (myNextCommitIsPushed != null && myNextCommitIsPushed.booleanValue() && exceptions.isEmpty()) {
GitRepositoryManager manager = getRepositoryManager(myProject);
Collection<GitRepository> repositories = GitUtil.getRepositoriesFromRoots(manager, sortedChanges.keySet());
final List<GitRepository> preselectedRepositories = newArrayList(repositories);
GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, GitBranchUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
}
return exceptions;
}
use of com.intellij.dvcs.push.ui.VcsPushDialog in project intellij-community by JetBrains.
the class VcsPushAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
VcsRepositoryManager manager = VcsRepositoryManager.getInstance(project);
Collection<Repository> repositories = e.getData(CommonDataKeys.EDITOR) != null ? ContainerUtil.<Repository>emptyList() : collectRepositories(manager, e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
VirtualFile selectedFile = DvcsUtil.getSelectedFile(project);
new VcsPushDialog(project, DvcsUtil.sortRepositories(repositories), selectedFile != null ? manager.getRepositoryForFile(selectedFile) : null).show();
}
use of com.intellij.dvcs.push.ui.VcsPushDialog in project intellij-community by JetBrains.
the class HgCheckinEnvironment method commit.
public List<VcsException> commit(List<Change> changes, String preparedComment, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
List<VcsException> exceptions = new LinkedList<>();
Map<HgRepository, Set<HgFile>> repositoriesMap = getFilesByRepository(changes);
addRepositoriesWithoutChanges(repositoriesMap);
for (Map.Entry<HgRepository, Set<HgFile>> entry : repositoriesMap.entrySet()) {
HgRepository repo = entry.getKey();
Set<HgFile> selectedFiles = entry.getValue();
HgCommitTypeCommand command = myMqNewPatch ? new HgQNewCommand(myProject, repo, preparedComment, myNextCommitAmend) : new HgCommitCommand(myProject, repo, preparedComment, myNextCommitAmend, myCloseBranch, myShouldCommitSubrepos && !selectedFiles.isEmpty());
if (isMergeCommit(repo.getRoot())) {
//partial commits are not allowed during merges
//verifyResult that all changed files in the repo are selected
//If so, commit the entire repository
//If not, abort
Set<HgFile> changedFilesNotInCommit = getChangedFilesNotInCommit(repo.getRoot(), selectedFiles);
boolean partial = !changedFilesNotInCommit.isEmpty();
if (partial) {
final StringBuilder filesNotIncludedString = new StringBuilder();
for (HgFile hgFile : changedFilesNotInCommit) {
filesNotIncludedString.append("<li>");
filesNotIncludedString.append(hgFile.getRelativePath());
filesNotIncludedString.append("</li>");
}
if (!mayCommitEverything(filesNotIncludedString.toString())) {
//abort
return exceptions;
}
//firstly selected changes marked dirty in CommitHelper -> postRefresh, so we need to mark others
VcsDirtyScopeManager dirtyManager = VcsDirtyScopeManager.getInstance(myProject);
for (HgFile hgFile : changedFilesNotInCommit) {
dirtyManager.fileDirty(hgFile.toFilePath());
}
}
// else : all was included, or it was OK to commit everything,
// so no need to set the files on the command, because then mercurial will complain
} else {
command.setFiles(selectedFiles);
}
try {
command.executeInCurrentThread();
} catch (HgCommandException e) {
exceptions.add(new VcsException(e));
} catch (VcsException e) {
exceptions.add(e);
}
}
// push if needed
if (myNextCommitIsPushed && exceptions.isEmpty()) {
final List<HgRepository> preselectedRepositories = ContainerUtil.newArrayList(repositoriesMap.keySet());
GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, HgUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
}
return exceptions;
}
Aggregations