Java Code Examples for com.intellij.openapi.vcs.changes.ChangeListManager#getAffectedFiles()
The following examples show how to use
com.intellij.openapi.vcs.changes.ChangeListManager#getAffectedFiles() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportPageModelImpl.java From azure-devops-intellij with MIT License | 4 votes |
private boolean doFirstCommitIfRequired(final Project project, final GitRepository localRepository, final VirtualFile rootVirtualFile, final ServerContext localContext, final ProgressIndicator indicator) { //Do first commit if there are no commits in the repository if (localRepository.isFresh()) { try { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project); final List<VirtualFile> trackedFiles = changeListManager.getAffectedFiles(); final Collection<VirtualFile> untrackedFiles = ContainerUtil.filter(localRepository.getUntrackedFilesHolder().retrieveUntrackedFiles(), new Condition<VirtualFile>() { @Override public boolean value(VirtualFile file) { return !changeListManager.isIgnoredFile(file) && !vcsManager.isIgnored(file); } }); trackedFiles.removeAll(untrackedFiles); final List<VirtualFile> allFiles = new ArrayList<VirtualFile>(); allFiles.addAll(trackedFiles); allFiles.addAll(untrackedFiles); final List<VirtualFile> filesToCommit = new ArrayList<VirtualFile>(); IdeaHelper.runOnUIThread(() -> { Collection<VirtualFile> selectedFiles = IdeaFileSelector.getInstance().selectFiles( project, allFiles, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_SELECT_FILES), VcsShowConfirmationOption.STATIC_SHOW_CONFIRMATION, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_SELECT_FILES_DIALOG_TITLE)); if (selectedFiles != null) filesToCommit.addAll(selectedFiles); }, true, indicator.getModalityState()); indicator.setText(TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_ADDING_FILES, project.getName())); GitFileUtils.addFiles(project, rootVirtualFile, filesToCommit); if (filesToCommit.size() > 0) { final GitSimpleHandler hCommit = new GitSimpleHandler(project, rootVirtualFile, GitCommand.COMMIT); hCommit.addParameters("-m", TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_ADDING_FILES, project.getName())); GitHandlerUtil.runInCurrentThread(hCommit, null, true, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_ADDING_FILES, project.getName())); if (hCommit.getExitCode() != 0) { //unable to commit logger.error("doFirstCommitIfRequired: git commit failed for project: {}, repoRoot: {} with error: {}", project.getName(), rootVirtualFile.getUrl(), hCommit.getStderr()); notifyImportError(project, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_ADDING_FILES_ERROR, project.getName(), hCommit.getStderr())); return false; } VfsUtil.markDirtyAndRefresh(false, true, false, ArrayUtil.toObjectArray(filesToCommit, VirtualFile.class)); VcsFileUtil.markFilesDirty(project, getFilePaths(filesToCommit)); } else { logger.error("doFirstCommitIfRequired: No files to do first commit in project: {}, repoRoot: {}", project.getName(), rootVirtualFile.getUrl()); notifyImportError(project, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_NO_SELECTED_FILES)); return false; } } catch (VcsException ve) { logger.error("doFirstCommitIfRequired: VcsException occurred when trying to do a commit on project: {}, repoRoot: {}", project.getName(), rootVirtualFile.getUrl()); logger.warn("doFirstCommitIfRequired", ve); notifyImportError(project, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_ADDING_FILES_ERROR, project.getName(), ve.getMessage())); return false; } } return true; }
Example 2
Source File: BaseAnalysisActionDialog.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public AnalysisScope getScope(@Nonnull AnalysisUIOptions uiOptions, @Nonnull AnalysisScope defaultScope, @Nonnull Project project, Module module) { AnalysisScope scope; if (isProjectScopeSelected()) { scope = new AnalysisScope(project); uiOptions.SCOPE_TYPE = AnalysisScope.PROJECT; } else { final SearchScope customScope = getCustomScope(); if (customScope != null) { scope = new AnalysisScope(customScope, project); uiOptions.SCOPE_TYPE = AnalysisScope.CUSTOM; uiOptions.CUSTOM_SCOPE_NAME = customScope.getDisplayName(); } else if (isModuleScopeSelected()) { scope = new AnalysisScope(module); uiOptions.SCOPE_TYPE = AnalysisScope.MODULE; } else if (isUncommitedFilesSelected()) { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); List<VirtualFile> files; if (myChangeLists.getSelectedItem() == ALL) { files = changeListManager.getAffectedFiles(); } else { files = new ArrayList<VirtualFile>(); for (ChangeList list : changeListManager.getChangeListsCopy()) { if (!Comparing.strEqual(list.getName(), (String)myChangeLists.getSelectedItem())) continue; final Collection<Change> changes = list.getChanges(); for (Change change : changes) { final ContentRevision afterRevision = change.getAfterRevision(); if (afterRevision != null) { final VirtualFile vFile = afterRevision.getFile().getVirtualFile(); if (vFile != null) { files.add(vFile); } } } } } scope = new AnalysisScope(project, new HashSet<VirtualFile>(files)); uiOptions.SCOPE_TYPE = AnalysisScope.UNCOMMITTED_FILES; } else { scope = defaultScope; uiOptions.SCOPE_TYPE = defaultScope.getScopeType();//just not project scope } } uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources(); scope.setIncludeTestSource(isInspectTestSources()); scope.setScope(getCustomScope()); FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName()); return scope; }