Search in sources :

Example 1 with CheckinEnvironment

use of com.intellij.openapi.vcs.checkin.CheckinEnvironment in project intellij-community by JetBrains.

the class ChangeListManagerImpl method addUnversionedFiles.

// TODO this is for quick-fix for GitAdd problem. To be removed after proper fix
// (which should introduce something like VcsAddRemoveEnvironment)
@Deprecated
@NotNull
public List<VcsException> addUnversionedFiles(final LocalChangeList list, @NotNull final List<VirtualFile> files, @NotNull final Condition<FileStatus> statusChecker, @Nullable Consumer<List<Change>> changesConsumer) {
    final List<VcsException> exceptions = new ArrayList<>();
    final Set<VirtualFile> allProcessedFiles = new HashSet<>();
    ChangesUtil.processVirtualFilesByVcs(myProject, files, (vcs, items) -> {
        final CheckinEnvironment environment = vcs.getCheckinEnvironment();
        if (environment != null) {
            final Set<VirtualFile> descendants = getUnversionedDescendantsRecursively(items, statusChecker);
            Set<VirtualFile> parents = vcs.areDirectoriesVersionedItems() ? getUnversionedParents(items, statusChecker) : Collections.<VirtualFile>emptySet();
            // it is assumed that not-added parents of files passed to scheduleUnversionedFilesForAddition() will also be added to vcs
            // (inside the method) - so common add logic just needs to refresh statuses of parents
            final List<VcsException> result = ContainerUtil.newArrayList();
            ProgressManager.getInstance().run(new Task.Modal(myProject, "Adding files to VCS...", true) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    indicator.setIndeterminate(true);
                    List<VcsException> exs = environment.scheduleUnversionedFilesForAddition(ContainerUtil.newArrayList(descendants));
                    if (exs != null) {
                        ContainerUtil.addAll(result, exs);
                    }
                }
            });
            allProcessedFiles.addAll(descendants);
            allProcessedFiles.addAll(parents);
            exceptions.addAll(result);
        }
    });
    if (!exceptions.isEmpty()) {
        StringBuilder message = new StringBuilder(VcsBundle.message("error.adding.files.prompt"));
        for (VcsException ex : exceptions) {
            message.append("\n").append(ex.getMessage());
        }
        Messages.showErrorDialog(myProject, message.toString(), VcsBundle.message("error.adding.files.title"));
    }
    for (VirtualFile file : allProcessedFiles) {
        myFileStatusManager.fileStatusChanged(file);
    }
    VcsDirtyScopeManager.getInstance(myProject).filesDirty(allProcessedFiles, null);
    final Ref<List<Change>> foundChanges = Ref.create();
    final boolean moveRequired = !list.isDefault();
    boolean syncUpdateRequired = changesConsumer != null;
    if (moveRequired || syncUpdateRequired) {
        // find the changes for the added files and move them to the necessary changelist
        InvokeAfterUpdateMode updateMode = syncUpdateRequired ? InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE : InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE;
        invokeAfterUpdate(() -> {
            ApplicationManager.getApplication().runReadAction(() -> {
                synchronized (myDataLock) {
                    List<Change> newChanges = findChanges(allProcessedFiles);
                    foundChanges.set(newChanges);
                    if (moveRequired && !newChanges.isEmpty()) {
                        moveChangesTo(list, newChanges.toArray(new Change[newChanges.size()]));
                    }
                }
            });
            myChangesViewManager.scheduleRefresh();
        }, updateMode, VcsBundle.message("change.lists.manager.add.unversioned"), null);
        if (changesConsumer != null) {
            changesConsumer.consume(foundChanges.get());
        }
    } else {
        myChangesViewManager.scheduleRefresh();
    }
    return exceptions;
}
Also used : CheckinEnvironment(com.intellij.openapi.vcs.checkin.CheckinEnvironment)

Example 2 with CheckinEnvironment

use of com.intellij.openapi.vcs.checkin.CheckinEnvironment in project intellij-community by JetBrains.

the class TriggerAdditionOrDeletion method processAddition.

private void processAddition() {
    Map<VcsRoot, List<FilePath>> map = groupByRoots(myProject, myExisting, identity());
    myPreparedAddition = new MultiMap<>();
    for (VcsRoot vcsRoot : map.keySet()) {
        if (vcsRoot != null && vcsRoot.getVcs() != null) {
            final CheckinEnvironment localChangesProvider = vcsRoot.getVcs().getCheckinEnvironment();
            if (localChangesProvider == null)
                continue;
            final boolean takeDirs = vcsRoot.getVcs().areDirectoriesVersionedItems();
            final Collection<FilePath> files = map.get(vcsRoot);
            final List<FilePath> toBeAdded;
            if (takeDirs) {
                final RecursiveCheckAdder adder = new RecursiveCheckAdder(vcsRoot.getPath());
                for (FilePath file : files) {
                    adder.process(file);
                }
                toBeAdded = adder.getToBeAdded();
            } else {
                toBeAdded = new LinkedList<>();
                for (FilePath file : files) {
                    if (!file.isDirectory()) {
                        toBeAdded.add(file);
                    }
                }
            }
            if (toBeAdded.isEmpty()) {
                return;
            }
            Collections.sort(toBeAdded, FilePathByPathComparator.getInstance());
            if (!vcsRoot.getVcs().fileListenerIsSynchronous()) {
                for (FilePath filePath : toBeAdded) {
                    myVcsFileListenerContextHelper.ignoreAdded(filePath.getVirtualFile());
                }
            }
            myPreparedAddition.put(vcsRoot, toBeAdded);
        }
    }
}
Also used : CheckinEnvironment(com.intellij.openapi.vcs.checkin.CheckinEnvironment)

Example 3 with CheckinEnvironment

use of com.intellij.openapi.vcs.checkin.CheckinEnvironment in project intellij-community by JetBrains.

the class TriggerAdditionOrDeletion method processDeletion.

private void processDeletion() {
    Map<VcsRoot, List<FilePath>> map = groupByRoots(myProject, myDeleted, identity());
    myPreparedDeletion = new MultiMap<>();
    for (VcsRoot vcsRoot : map.keySet()) {
        if (vcsRoot != null && vcsRoot.getVcs() != null) {
            final CheckinEnvironment localChangesProvider = vcsRoot.getVcs().getCheckinEnvironment();
            if (localChangesProvider == null)
                continue;
            final boolean takeDirs = vcsRoot.getVcs().areDirectoriesVersionedItems();
            final Collection<FilePath> files = map.get(vcsRoot);
            final List<FilePath> toBeDeleted = new LinkedList<>();
            for (FilePath file : files) {
                final FilePath parent = file.getParentPath();
                if ((takeDirs || (!file.isDirectory())) && parent != null && parent.getIOFile().exists()) {
                    toBeDeleted.add(file);
                }
            }
            if (toBeDeleted.isEmpty())
                return;
            if (!vcsRoot.getVcs().fileListenerIsSynchronous()) {
                for (FilePath filePath : toBeDeleted) {
                    myVcsFileListenerContextHelper.ignoreDeleted(filePath);
                }
            }
            myPreparedDeletion.put(vcsRoot, toBeDeleted);
        }
    }
}
Also used : CheckinEnvironment(com.intellij.openapi.vcs.checkin.CheckinEnvironment)

Example 4 with CheckinEnvironment

use of com.intellij.openapi.vcs.checkin.CheckinEnvironment in project intellij-community by JetBrains.

the class TriggerAdditionOrDeletion method processIt.

public void processIt() {
    if (myPreparedDeletion != null) {
        for (Map.Entry<VcsRoot, Collection<FilePath>> entry : myPreparedDeletion.entrySet()) {
            final VcsRoot vcsRoot = entry.getKey();
            final AbstractVcs vcs = ObjectUtils.assertNotNull(vcsRoot.getVcs());
            final CheckinEnvironment localChangesProvider = vcs.getCheckinEnvironment();
            if (localChangesProvider == null)
                continue;
            final Collection<FilePath> filePaths = entry.getValue();
            if (vcs.fileListenerIsSynchronous()) {
                myAffected.addAll(filePaths);
                continue;
            }
            askUserIfNeeded(vcsRoot.getVcs(), (List<FilePath>) filePaths, VcsConfiguration.StandardConfirmation.REMOVE);
            myAffected.addAll(filePaths);
            localChangesProvider.scheduleMissingFileForDeletion((List<FilePath>) filePaths);
        }
    }
    if (myPreparedAddition != null) {
        final List<FilePath> incorrectFilePath = new ArrayList<>();
        for (Map.Entry<VcsRoot, Collection<FilePath>> entry : myPreparedAddition.entrySet()) {
            final VcsRoot vcsRoot = entry.getKey();
            final AbstractVcs vcs = ObjectUtils.assertNotNull(vcsRoot.getVcs());
            final CheckinEnvironment localChangesProvider = vcs.getCheckinEnvironment();
            if (localChangesProvider == null)
                continue;
            final Collection<FilePath> filePaths = entry.getValue();
            if (vcs.fileListenerIsSynchronous()) {
                myAffected.addAll(filePaths);
                continue;
            }
            askUserIfNeeded(vcsRoot.getVcs(), (List<FilePath>) filePaths, VcsConfiguration.StandardConfirmation.ADD);
            myAffected.addAll(filePaths);
            final List<VirtualFile> virtualFiles = new ArrayList<>();
            ContainerUtil.process(filePaths, new Processor<FilePath>() {

                @Override
                public boolean process(FilePath path) {
                    VirtualFile vf = path.getVirtualFile();
                    if (vf == null) {
                        incorrectFilePath.add(path);
                    } else {
                        virtualFiles.add(vf);
                    }
                    return true;
                }
            });
            //virtual files collection shouldn't contain 'null' vf
            localChangesProvider.scheduleUnversionedFilesForAddition(virtualFiles);
        }
        //if some errors occurred  -> notify
        if (!incorrectFilePath.isEmpty()) {
            notifyAndLogFiles("Apply new files error", incorrectFilePath);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CheckinEnvironment(com.intellij.openapi.vcs.checkin.CheckinEnvironment) MultiMap(com.intellij.util.containers.MultiMap)

Example 5 with CheckinEnvironment

use of com.intellij.openapi.vcs.checkin.CheckinEnvironment in project intellij-community by JetBrains.

the class ScheduleForRemovalAction method processFiles.

protected List<VcsException> processFiles(final AbstractVcs vcs, final List<FilePath> files) {
    CheckinEnvironment environment = vcs.getCheckinEnvironment();
    if (environment == null)
        return Collections.emptyList();
    final List<VcsException> result = environment.scheduleMissingFileForDeletion(files);
    if (result == null)
        return Collections.emptyList();
    return result;
}
Also used : CheckinEnvironment(com.intellij.openapi.vcs.checkin.CheckinEnvironment) VcsException(com.intellij.openapi.vcs.VcsException)

Aggregations

CheckinEnvironment (com.intellij.openapi.vcs.checkin.CheckinEnvironment)6 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)1 VcsException (com.intellij.openapi.vcs.VcsException)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MultiMap (com.intellij.util.containers.MultiMap)1 VcsUtil (com.intellij.vcsUtil.VcsUtil)1 ModuleExtKt (com.jetbrains.extensions.ModuleExtKt)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 NotNull (org.jetbrains.annotations.NotNull)1