void (final @NotNull List<VirtualFile> addedFiles, final @NotNull Map<VirtualFile, VirtualFile> copyFromMap) { saveUnsavedVcsIgnoreFiles(); // if a file is copied from another repository, then 'hg add' should be used instead of 'hg copy'. // Thus here we remove such files from the copyFromMap. for (Iterator<Map.Entry<VirtualFile, VirtualFile>> it = copyFromMap.entrySet().iterator(); it.hasNext(); ) { final Map.Entry<VirtualFile, VirtualFile> entry = it.next(); final VirtualFile rootFrom = HgUtil.getHgRootOrNull(myProject, entry.getKey()); final VirtualFile rootTo = HgUtil.getHgRootOrNull(myProject, entry.getValue()); if (rootTo == null || !rootTo.equals(rootFrom)) { it.remove(); } } // exclude files which are added to a directory which is not version controlled for (Iterator<VirtualFile> it = addedFiles.iterator(); it.hasNext(); ) { if (HgUtil.getHgRootOrNull(myProject, it.next()) == null) { it.remove(); } } // exclude files which are ignored in .hgignore in background and execute adding after that final Map<VirtualFile, Collection<VirtualFile>> sortedFiles = HgUtil.sortByHgRoots(myProject, addedFiles); final HashSet<VirtualFile> untrackedFiles = new HashSet<>(); new Task.Backgroundable(myProject, HgBundle.message("hg4idea.progress.checking.ignored"), false) { @Override public void run(@NotNull ProgressIndicator pi) { for (Map.Entry<VirtualFile, Collection<VirtualFile>> e : sortedFiles.entrySet()) { VirtualFile repo = e.getKey(); final Collection<VirtualFile> files = e.getValue(); pi.setText(repo.getPresentableUrl()); Collection<VirtualFile> untrackedForRepo = new HgStatusCommand.Builder(false).unknown(true).removed(true).build(myProject) .getFiles(repo, new ArrayList<>(files)); untrackedFiles.addAll(untrackedForRepo); } addedFiles.retainAll(untrackedFiles); // select files to add if there is something to select if (!addedFiles.isEmpty() || !copyFromMap.isEmpty()) { performAddingWithConfirmation(addedFiles, copyFromMap); } } }.queue(); }