コード例 #1
0
  @NotNull
  public Change[] getSelectedChanges() {
    Set<Change> changes = new LinkedHashSet<Change>();

    final TreePath[] paths = getSelectionPaths();
    if (paths == null) {
      return new Change[0];
    }

    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent();
      changes.addAll(node.getAllChangesUnder());
    }

    if (changes.isEmpty()) {
      final List<VirtualFile> selectedModifiedWithoutEditing = getSelectedModifiedWithoutEditing();
      if (selectedModifiedWithoutEditing != null && !selectedModifiedWithoutEditing.isEmpty()) {
        for (VirtualFile file : selectedModifiedWithoutEditing) {
          AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file);
          if (vcs == null) continue;
          final VcsCurrentRevisionProxy before =
              VcsCurrentRevisionProxy.create(file, myProject, vcs.getKeyInstanceMethod());
          if (before != null) {
            ContentRevision afterRevision = new CurrentContentRevision(new FilePathImpl(file));
            changes.add(new Change(before, afterRevision, FileStatus.HIJACKED));
          }
        }
      }
    }

    return changes.toArray(new Change[changes.size()]);
  }
コード例 #2
0
 private List<FilePath> getSelectedFilePaths(final Object tag) {
   Set<FilePath> files = new HashSet<FilePath>();
   final TreePath[] paths = getSelectionPaths();
   if (paths != null) {
     for (TreePath path : paths) {
       if (path.getPathCount() > 1) {
         ChangesBrowserNode firstNode = (ChangesBrowserNode) path.getPathComponent(1);
         if (tag == null || firstNode.getUserObject() == tag) {
           ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent();
           files.addAll(node.getAllFilePathsUnder());
         }
       }
     }
   }
   return new ArrayList<FilePath>(files);
 }
コード例 #3
0
 private List<LocallyDeletedChange> getSelectedLocallyDeletedChanges() {
   Set<LocallyDeletedChange> files = new HashSet<LocallyDeletedChange>();
   final TreePath[] paths = getSelectionPaths();
   if (paths != null) {
     for (TreePath path : paths) {
       if (path.getPathCount() > 1) {
         ChangesBrowserNode firstNode = (ChangesBrowserNode) path.getPathComponent(1);
         if (firstNode.getUserObject() == TreeModelBuilder.LOCALLY_DELETED_NODE) {
           ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent();
           final List<LocallyDeletedChange> objectsUnder =
               node.getAllObjectsUnder(LocallyDeletedChange.class);
           files.addAll(objectsUnder);
         }
       }
     }
   }
   return new ArrayList<LocallyDeletedChange>(files);
 }
コード例 #4
0
 public List<VcsException> commit(
     @NotNull List<Change> changes,
     @NotNull String message,
     @NotNull NullableFunction<Object, Object> parametersHolder,
     Set<String> feedback) {
   List<VcsException> exceptions = new ArrayList<VcsException>();
   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()) {
     final VirtualFile root = entry.getKey();
     try {
       File messageFile = createMessageFile(root, message);
       try {
         final Set<FilePath> added = new HashSet<FilePath>();
         final Set<FilePath> removed = new HashSet<FilePath>();
         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();
               added.add(afterPath);
               if (!GitFileUtils.shouldIgnoreCaseChange(
                   afterPath.getPath(), beforePath.getPath())) {
                 removed.add(beforePath);
               }
               break;
             default:
               throw new IllegalStateException("Unknown change type: " + change.getType());
           }
         }
         try {
           try {
             Set<FilePath> files = new HashSet<FilePath>();
             files.addAll(added);
             files.addAll(removed);
             commit(
                 myProject,
                 root,
                 files,
                 messageFile,
                 myNextCommitAuthor,
                 myNextCommitAmend,
                 myNextCommitAuthorDate);
           } 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;
             }
           }
         } finally {
           if (!messageFile.delete()) {
             log.warn("Failed to remove temporary file: " + messageFile);
           }
         }
       } catch (VcsException e) {
         exceptions.add(e);
       }
     } catch (IOException ex) {
       //noinspection ThrowableInstanceNeverThrown
       exceptions.add(new VcsException("Creation of commit message file failed", ex));
     }
   }
   if (myNextCommitIsPushed != null
       && myNextCommitIsPushed.booleanValue()
       && exceptions.isEmpty()) {
     // push
     UIUtil.invokeLaterIfNeeded(
         new Runnable() {
           public void run() {
             GitPusher.showPushDialogAndPerformPush(
                 myProject, ServiceManager.getService(myProject, GitPlatformFacade.class));
           }
         });
   }
   return exceptions;
 }
コード例 #5
0
  @CalledInAwt
  public static ApplyPatchStatus executePatchGroup(
      final Collection<PatchApplier> group, final LocalChangeList localChangeList) {
    if (group.isEmpty()) return ApplyPatchStatus.SUCCESS; // ?
    final Project project = group.iterator().next().myProject;

    ApplyPatchStatus result = ApplyPatchStatus.SUCCESS;
    for (PatchApplier patchApplier : group) {
      result = ApplyPatchStatus.and(result, patchApplier.nonWriteActionPreCheck());
    }
    final Label beforeLabel = LocalHistory.getInstance().putSystemLabel(project, "Before patch");
    final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(project);
    final Ref<ApplyPatchStatus> refStatus = new Ref<>(result);
    try {
      CommandProcessor.getInstance()
          .executeCommand(
              project,
              new Runnable() {
                @Override
                public void run() {
                  for (PatchApplier applier : group) {
                    refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.createFiles()));
                    applier.addSkippedItems(trigger);
                  }
                  trigger.prepare();
                  if (refStatus.get() == ApplyPatchStatus.SUCCESS) {
                    // all pre-check results are valuable only if not successful; actual status we
                    // can receive after executeWritable
                    refStatus.set(null);
                  }
                  for (PatchApplier applier : group) {
                    refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.executeWritable()));
                    if (refStatus.get() == ApplyPatchStatus.ABORT) break;
                  }
                }
              },
              VcsBundle.message("patch.apply.command"),
              null);
    } finally {
      VcsFileListenerContextHelper.getInstance(project).clearContext();
      LocalHistory.getInstance().putSystemLabel(project, "After patch");
    }
    result = refStatus.get();
    result = result == null ? ApplyPatchStatus.FAILURE : result;

    trigger.processIt();
    final Set<FilePath> directlyAffected = new HashSet<>();
    final Set<VirtualFile> indirectlyAffected = new HashSet<>();
    for (PatchApplier applier : group) {
      directlyAffected.addAll(applier.getDirectlyAffected());
      indirectlyAffected.addAll(applier.getIndirectlyAffected());
    }
    directlyAffected.addAll(trigger.getAffected());
    final Consumer<Collection<FilePath>> mover =
        localChangeList == null ? null : createMover(project, localChangeList);
    refreshPassedFilesAndMoveToChangelist(project, directlyAffected, indirectlyAffected, mover);
    if (result == ApplyPatchStatus.FAILURE) {
      suggestRollback(project, group, beforeLabel);
    } else if (result == ApplyPatchStatus.ABORT) {
      rollbackUnderProgress(project, project.getBaseDir(), beforeLabel);
    }
    showApplyStatus(project, result);
    return result;
  }