示例#1
0
  // on EDT, dispose checked
  public void execute(final UpdatedFiles updatedFiles) {
    if (myConflictedVirtualFiles.isEmpty()) {
      return;
    }
    final AbstractVcsHelper vcsHelper = AbstractVcsHelper.getInstance(myProject);

    List<VirtualFile> mergedFiles =
        vcsHelper.showMergeDialog(myConflictedVirtualFiles, new SvnMergeProvider(myProject));

    final FileGroup mergedGroup = updatedFiles.getGroupById(FileGroup.MERGED_ID);
    final FileGroup conflictedGroup = updatedFiles.getGroupById(FileGroup.MERGED_WITH_CONFLICT_ID);
    final VcsKey vcsKey = SvnVcs.getKey();

    for (final VirtualFile mergedFile : mergedFiles) {
      String path = FileUtil.toSystemDependentName(mergedFile.getPresentableUrl());
      conflictedGroup.remove(path);
      mergedGroup.add(path, vcsKey, null);

      mergedFile.refresh(false, false);
      // for additionally created files removal to be detected
      mergedFile.getParent().refresh(false, false);

      if (myChangesUnderProjectRoot) {
        myDirtyScopeManager.fileDirty(mergedFile);
      }
    }
  }
  private void processDeletedFiles(Project project) {
    final List<Pair<FilePath, WorkingCopyFormat>> deletedFiles =
        new ArrayList<Pair<FilePath, WorkingCopyFormat>>();
    final Collection<FilePath> filesToProcess = new ArrayList<FilePath>();
    List<VcsException> exceptions = new ArrayList<VcsException>();
    final AbstractVcsHelper vcsHelper = AbstractVcsHelper.getInstance(project);

    try {
      fillDeletedFiles(project, deletedFiles, filesToProcess);
      if (deletedFiles.isEmpty() && filesToProcess.isEmpty() || myUndoingMove) return;
      SvnVcs vcs = SvnVcs.getInstance(project);
      final VcsShowConfirmationOption.Value value = vcs.getDeleteConfirmation().getValue();
      if (value != VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) {
        if (!deletedFiles.isEmpty()) {
          final Collection<FilePath> confirmed =
              promptAboutDeletion(deletedFiles, vcs, value, vcsHelper);
          if (confirmed != null) {
            filesToProcess.addAll(confirmed);
          }
        }
        if (filesToProcess != null && !filesToProcess.isEmpty()) {
          runInBackground(
              project,
              "Deleting files from Subversion",
              createDeleteRunnable(project, vcs, filesToProcess, exceptions));
        }
        final List<FilePath> deletedFilesFiles =
            ObjectsConvertor.convert(
                deletedFiles,
                new Convertor<Pair<FilePath, WorkingCopyFormat>, FilePath>() {
                  @Override
                  public FilePath convert(Pair<FilePath, WorkingCopyFormat> o) {
                    return o.getFirst();
                  }
                });
        for (FilePath file : deletedFilesFiles) {
          final FilePath parent = file.getParentPath();
          if (parent != null) {
            myFilesToRefresh.add(parent.getVirtualFile());
          }
        }
        if (filesToProcess != null) {
          deletedFilesFiles.removeAll(filesToProcess);
        }
        for (FilePath file : deletedFilesFiles) {
          FileUtil.delete(file.getIOFile());
        }
      }
    } catch (SVNException e) {
      exceptions.add(new VcsException(e));
    }
    if (!exceptions.isEmpty()) {
      vcsHelper.showErrors(exceptions, SvnBundle.message("delete.files.errors.title"));
    }
  }
示例#3
0
 /** Registers HgMockVcsHelper as the AbstractVcsHelper. */
 protected HgMockVcsHelper registerMockVcsHelper() {
   final String key = "com.intellij.openapi.vcs.AbstractVcsHelper";
   final MutablePicoContainer picoContainer = (MutablePicoContainer) myProject.getPicoContainer();
   picoContainer.unregisterComponent(key);
   picoContainer.registerComponentImplementation(key, HgMockVcsHelper.class);
   return (HgMockVcsHelper) AbstractVcsHelper.getInstance(myProject);
 }
 private Collection<VirtualFile> promptAboutAddition(
     SvnVcs vcs,
     List<VirtualFile> addedVFiles,
     VcsShowConfirmationOption.Value value,
     AbstractVcsHelper vcsHelper) {
   Collection<VirtualFile> filesToProcess;
   if (value == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY) {
     filesToProcess = addedVFiles;
   } else {
     final String singleFilePrompt;
     if (addedVFiles.size() == 1 && addedVFiles.get(0).isDirectory()) {
       singleFilePrompt = SvnBundle.getString("confirmation.text.add.dir");
     } else {
       singleFilePrompt = SvnBundle.getString("confirmation.text.add.file");
     }
     filesToProcess =
         vcsHelper.selectFilesToProcess(
             addedVFiles,
             SvnBundle.message("confirmation.title.add.multiple.files"),
             null,
             SvnBundle.message("confirmation.title.add.file"),
             singleFilePrompt,
             vcs.getAddConfirmation());
   }
   return filesToProcess;
 }
 @Override
 public void run(ContinuationContext context) {
   final StringBuilder message =
       new StringBuilder().append("Theirs changes merged for ").append(myOldPresentation);
   VcsBalloonProblemNotifier.showOverChangesView(
       myVcs.getProject(), message.toString(), MessageType.INFO);
   if (!myWarnings.isEmpty()) {
     AbstractVcsHelper.getInstance(myVcs.getProject())
         .showErrors(myWarnings, TreeConflictRefreshablePanel.TITLE);
   }
 }
 private void showMergeDialog(@NotNull final Collection<VirtualFile> initiallyUnmergedFiles) {
   ApplicationManager.getApplication()
       .invokeAndWait(
           () -> {
             MergeProvider mergeProvider = new GitMergeProvider(myProject, myParams.reverse);
             myVcsHelper.showMergeDialog(
                 new ArrayList<>(initiallyUnmergedFiles),
                 mergeProvider,
                 myParams.myMergeDialogCustomizer);
           },
           ModalityState.defaultModalityState());
 }
  @Override
  protected void actionPerformed(@NotNull VcsContext context) {
    Project project = context.getProject();
    Pair<FilePath, VirtualFile> pair = getPathAndParentFile(context);
    FilePath path = assertNotNull(pair.first);
    VirtualFile fileOrParent = assertNotNull(pair.second);
    AbstractVcs vcs = assertNotNull(ChangesUtil.getVcsForFile(fileOrParent, project));
    VcsHistoryProvider provider = assertNotNull(vcs.getVcsHistoryProvider());

    AbstractVcsHelper.getInstance(project)
        .showFileHistory(provider, vcs.getAnnotationProvider(), path, null, vcs);
  }
 public GitConflictResolver(
     @NotNull Project project,
     @NotNull Git git,
     @NotNull Collection<VirtualFile> roots,
     @NotNull Params params) {
   myProject = project;
   myGit = git;
   myRoots = roots;
   myParams = params;
   myRepositoryManager = GitUtil.getRepositoryManager(myProject);
   myVcsHelper = AbstractVcsHelper.getInstance(project);
   myVcs = assertNotNull(GitVcs.getInstance(myProject));
 }
    private void doRun() {
      myIndicator = ProgressManager.getInstance().getProgressIndicator();

      final List<Change> changesToRefresh = new ArrayList<Change>();
      try {
        ChangesUtil.processChangesByVcs(
            myProject,
            myChanges,
            new ChangesUtil.PerVcsProcessor<Change>() {
              public void process(AbstractVcs vcs, List<Change> changes) {
                final RollbackEnvironment environment = vcs.getRollbackEnvironment();
                if (environment != null) {
                  changesToRefresh.addAll(changes);

                  if (myIndicator != null) {
                    myIndicator.setText(vcs.getDisplayName() + ": performing rollback...");
                    myIndicator.setIndeterminate(false);
                    myIndicator.checkCanceled();
                  }
                  environment.rollbackChanges(
                      changes,
                      myExceptions,
                      new RollbackProgressModifier(changes.size(), myIndicator));
                  if (myIndicator != null) {
                    myIndicator.setText2("");
                    myIndicator.checkCanceled();
                  }

                  if (myExceptions.isEmpty() && myDeleteLocallyAddedFiles) {
                    deleteAddedFilesLocally(changes);
                  }
                }
              }
            });
      } catch (ProcessCanceledException e) {
        // still do refresh
      }

      if (myIndicator != null) {
        myIndicator.startNonCancelableSection();
        myIndicator.setIndeterminate(true);
        myIndicator.setText2("");
        myIndicator.setText(VcsBundle.message("progress.text.synchronizing.files"));
      }

      doRefresh(myProject, changesToRefresh);

      AbstractVcsHelper.getInstance(myProject)
          .showErrors(myExceptions, VcsBundle.message("changes.action.rollback.text"));
    }
 private void processAddedFiles(Project project) {
   SvnVcs vcs = SvnVcs.getInstance(project);
   List<VirtualFile> addedVFiles = new ArrayList<VirtualFile>();
   Map<VirtualFile, File> copyFromMap = new HashMap<VirtualFile, File>();
   final Set<VirtualFile> recursiveItems = new HashSet<VirtualFile>();
   fillAddedFiles(project, vcs, addedVFiles, copyFromMap, recursiveItems);
   if (addedVFiles.isEmpty()) return;
   final VcsShowConfirmationOption.Value value = vcs.getAddConfirmation().getValue();
   if (value != VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) {
     final AbstractVcsHelper vcsHelper = AbstractVcsHelper.getInstance(project);
     final Collection<VirtualFile> filesToProcess =
         promptAboutAddition(vcs, addedVFiles, value, vcsHelper);
     if (filesToProcess != null && !filesToProcess.isEmpty()) {
       final List<VcsException> exceptions = new ArrayList<VcsException>();
       runInBackground(
           project,
           "Adding files to Subversion",
           createAdditionRunnable(project, vcs, copyFromMap, filesToProcess, exceptions));
       if (!exceptions.isEmpty()) {
         vcsHelper.showErrors(exceptions, SvnBundle.message("add.files.errors.title"));
       }
     }
   }
 }
  @Override
  public void actionPerformed(@NotNull AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
      return;
    }

    final Set<VirtualFile> conflictedFiles =
        new TreeSet<VirtualFile>(
            new Comparator<VirtualFile>() {
              @Override
              public int compare(@NotNull VirtualFile f1, @NotNull VirtualFile f2) {
                return f1.getPresentableUrl().compareTo(f2.getPresentableUrl());
              }
            });
    for (Change change : ChangeListManager.getInstance(project).getAllChanges()) {
      if (change.getFileStatus() != FileStatus.MERGED_WITH_CONFLICTS) {
        continue;
      }
      final ContentRevision before = change.getBeforeRevision();
      final ContentRevision after = change.getAfterRevision();
      if (before != null) {
        final VirtualFile file = before.getFile().getVirtualFile();
        if (file != null) {
          conflictedFiles.add(file);
        }
      }
      if (after != null) {
        final VirtualFile file = after.getFile().getVirtualFile();
        if (file != null) {
          conflictedFiles.add(file);
        }
      }
    }

    AbstractVcsHelper.getInstance(project)
        .showMergeDialog(
            new ArrayList<VirtualFile>(conflictedFiles),
            GitVcs.getInstance(project).getMergeProvider());
    for (VirtualFile conflictedFile : conflictedFiles) {
      final GitRepository repo =
          GitRepositoryManager.getInstance(project).getRepositoryForFile(conflictedFile);
      if (repo != null) {
        repo.update(GitRepository.TrackedTopic.ALL_CURRENT);
      }
    }
  }
 protected GitUpdater(
     @NotNull Project project,
     @NotNull Git git,
     @NotNull VirtualFile root,
     @NotNull Map<VirtualFile, GitBranchPair> trackedBranches,
     @NotNull ProgressIndicator progressIndicator,
     @NotNull UpdatedFiles updatedFiles) {
   myProject = project;
   myGit = git;
   myRoot = root;
   myTrackedBranches = trackedBranches;
   myProgressIndicator = progressIndicator;
   myUpdatedFiles = updatedFiles;
   myVcsHelper = AbstractVcsHelper.getInstance(project);
   myVcs = GitVcs.getInstance(project);
   myRepositoryManager = GitUtil.getRepositoryManager(myProject);
 }
  @Override
  public void onSuccess() {
    if (myProject.isDisposed()) {
      return;
    }

    if (!myExceptions.isEmpty()) {
      final List<String> messages = new ArrayList<String>();
      for (Throwable exception : myExceptions) {
        messages.add(exception.getMessage());
      }
      AbstractVcsHelper.getInstance(myProject)
          .showErrors(
              Collections.singletonList(new VcsException(messages)),
              SvnBundle.message("action.change.wcopy.format.task.title"));
    }
  }
  void commandFinished(final Project project) {
    checkOverwrites(project);
    if (myAddedFiles.containsKey(project)) {
      processAddedFiles(project);
    }
    processMovedFiles(project);
    if (myDeletedFiles.containsKey(project)) {
      processDeletedFiles(project);
    }

    final List<VcsException> exceptionList = myMoveExceptions.get(project);
    if (exceptionList != null && !exceptionList.isEmpty()) {
      AbstractVcsHelper.getInstance(project)
          .showErrors(exceptionList, SvnBundle.message("move.files.errors.title"));
    }

    if (!myFilesToRefresh.isEmpty()) {
      refreshFiles(project);
    }
  }
  private Collection<FilePath> chooseBinaryFiles(List<Change> converted, Set<FilePath> paths) {
    String singleMessage = "";
    if (paths.size() == 1) {
      final Change change = converted.get(0);
      final FileStatus status = change.getFileStatus();
      final FilePath path = ChangesUtil.getFilePath(change);
      final String stringPath = TreeConflictRefreshablePanel.filePath(path);
      if (FileStatus.DELETED.equals(status)) {
        singleMessage = "Delete binary file " + stringPath + " (according to theirs changes)?";
      } else if (FileStatus.ADDED.equals(status)) {
        singleMessage = "Create binary file " + stringPath + " (according to theirs changes)?";
      } else {
        singleMessage =
            "Apply changes to binary file " + stringPath + " (according to theirs changes)?";
      }
    }
    return AbstractVcsHelper.getInstance(myVcs.getProject())
        .selectFilePathsToProcess(
            new ArrayList<FilePath>(paths),
            TreeConflictRefreshablePanel.TITLE,
            "Select binary files to patch",
            TreeConflictRefreshablePanel.TITLE,
            singleMessage,
            new VcsShowConfirmationOption() {

              @Override
              public Value getValue() {
                return null;
              }

              @Override
              public void setValue(Value value) {}

              @Override
              public boolean isPersistent() {
                return false;
              }
            });
  }
  private Collection<FilePath> promptAboutDeletion(
      List<Pair<FilePath, WorkingCopyFormat>> deletedFiles,
      SvnVcs vcs,
      VcsShowConfirmationOption.Value value,
      AbstractVcsHelper vcsHelper) {
    final Convertor<Pair<FilePath, WorkingCopyFormat>, FilePath> convertor =
        new Convertor<Pair<FilePath, WorkingCopyFormat>, FilePath>() {
          @Override
          public FilePath convert(Pair<FilePath, WorkingCopyFormat> o) {
            return o.getFirst();
          }
        };
    Collection<FilePath> filesToProcess;
    if (value == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY) {
      filesToProcess = ObjectsConvertor.convert(deletedFiles, convertor);
    } else {

      final String singleFilePrompt;
      if (deletedFiles.size() == 1 && deletedFiles.get(0).getFirst().isDirectory()) {
        singleFilePrompt =
            WorkingCopyFormat.ONE_DOT_SEVEN.equals(deletedFiles.get(0).getSecond())
                ? SvnBundle.getString("confirmation.text.delete.dir.17")
                : SvnBundle.getString("confirmation.text.delete.dir");
      } else {
        singleFilePrompt = SvnBundle.getString("confirmation.text.delete.file");
      }
      final Collection<FilePath> files =
          vcsHelper.selectFilePathsToProcess(
              ObjectsConvertor.convert(deletedFiles, convertor),
              SvnBundle.message("confirmation.title.delete.multiple.files"),
              null,
              SvnBundle.message("confirmation.title.delete.file"),
              singleFilePrompt,
              vcs.getDeleteConfirmation());
      filesToProcess = files == null ? null : new ArrayList<FilePath>(files);
    }
    return filesToProcess;
  }
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    assert vFile != null;
    AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
    assert vcs != null;
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    assert provider != null;
    ChangeBrowserSettings settings = provider.createDefaultSettings();
    CommittedChangesFilterDialog dlg =
        new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
    dlg.show();
    if (!dlg.isOK()) return;

    int maxCount = 0;
    if (!settings.isAnyFilterSpecified()) {
      int rc =
          Messages.showYesNoCancelDialog(
              project,
              VcsBundle.message("browse.changes.no.filter.prompt"),
              VcsBundle.message("browse.changes.title"),
              VcsBundle.message("browse.changes.show.recent.button"),
              VcsBundle.message("browse.changes.show.all.button"),
              CommonBundle.getCancelButtonText(),
              Messages.getQuestionIcon());
      if (rc == Messages.CANCEL) {
        return;
      }
      if (rc == Messages.YES) {
        maxCount = 50;
      }
    }

    AbstractVcsHelper.getInstance(project)
        .openCommittedChangesTab(vcs, vFile, settings, maxCount, null);
  }
 /**
  * Show errors on the tab
  *
  * @param project the context project
  * @param title the operation title
  * @param errors the errors to display
  */
 public static void showTabErrors(Project project, String title, List<VcsException> errors) {
   AbstractVcsHelper.getInstance(project).showErrors(errors, title);
 }