public void acceptMerge()

in src/org/jetbrains/tfsIntegration/core/tfs/conflicts/ResolveConflictHelper.java [63:150]


  public void acceptMerge(final @NotNull Conflict conflict) throws TfsException, VcsException {
    TFSVcs.assertTrue(canMerge(conflict));

    final WorkspaceInfo workspace = myConflict2Workspace.get(conflict);

    @NotNull final FilePath localPath = VersionControlPath
      .getFilePath(conflict.getSrclitem() != null ? conflict.getSrclitem() : conflict.getTgtlitem(),
                   conflict.getYtype() == ItemType.Folder);

    final ContentTriplet contentTriplet = new ContentTriplet();
    VcsRunnable runnable = new VcsRunnable() {
      @Override
      public void run() throws VcsException {
        // virtual file can be out of the current project so force its discovery
        TfsFileUtil.refreshAndFindFile(localPath);
        try {
          if (conflict.getYtype() == ItemType.File) {
            byte[] current;
            byte[] last;
            if (conflict.getCtype() == ConflictType.Merge) {
              current = TFSContentRevision.create(myProject, workspace, conflict.getTver(), conflict.getTitemid()).getContentAsBytes();
              last = TFSContentRevision.create(myProject, workspace, conflict.getYver(), conflict.getYitemid()).getContentAsBytes();
            }
            else {
              current = ((CurrentContentRevision)CurrentContentRevision.create(localPath)).getContentAsBytes();
              last = TFSContentRevision.create(myProject, workspace, conflict.getTver(), conflict.getTitemid()).getContentAsBytes();
            }
            byte[] original = TFSContentRevision.create(myProject, workspace, conflict.getBver(), conflict.getBitemid()).getContentAsBytes();
            contentTriplet.baseContent = original != null ? original : ArrayUtilRt.EMPTY_BYTE_ARRAY;
            contentTriplet.localContent = current != null ? current : ArrayUtilRt.EMPTY_BYTE_ARRAY;
            contentTriplet.serverContent = last != null ? last : ArrayUtilRt.EMPTY_BYTE_ARRAY;
          }
        }
        catch (TfsException e) {
          throw new VcsException(TFSBundle.message("cannot.load.revisions", localPath.getPresentableUrl(), e.getMessage()));
        }
      }

    };

    if (isContentConflict(conflict)) {
      // we will need content only if it conflicts
      VcsUtil.runVcsProcessWithProgress(runnable, "Preparing merge data...", false, myProject);
    }

    // merge names
    final String localName;
    if (isNameConflict(conflict)) {
      // TODO proper type?
      final String mergedServerPath = ConflictsEnvironment.getNameMerger().mergeName(workspace, conflict, myProject);
      if (mergedServerPath == null) {
        // user cancelled
        return;
      }
      //noinspection ConstantConditions
      @NotNull FilePath mergedLocalPath =
        workspace.findLocalPathByServerPath(mergedServerPath, conflict.getYtype() == ItemType.Folder, myProject);
      localName = mergedLocalPath.getPath();
    }
    else {
      localName = VersionControlPath.localPathFromTfsRepresentation(conflict.getTgtlitem());
    }

    boolean resolved = true;
    // merge content
    if (isContentConflict(conflict)) {
      TFSVcs.assertTrue(conflict.getYtype() == ItemType.File);
      VirtualFile vFile = localPath.getVirtualFile();
      if (vFile != null) {
        try {
          TfsFileUtil.setReadOnly(vFile, false);
          resolved = ConflictsEnvironment.getContentMerger()
            .mergeContent(conflict, contentTriplet, myProject, vFile, localName, new TfsRevisionNumber(conflict.getTver(),
                                                                                                           conflict.getTitemid()));
        }
        catch (IOException e) {
          throw new VcsException(e);
        }
      }
      else {
        String errorMessage = MessageFormat.format("File ''{0}'' is missing", localPath.getPresentableUrl());
        throw new VcsException(errorMessage);
      }
    }
    if (resolved) {
      conflictResolved(conflict, Resolution.AcceptMerge, localName, isNameConflict(conflict));
    }
  }