private void fillAddedFiles(
      Project project,
      SvnVcs vcs,
      List<VirtualFile> addedVFiles,
      Map<VirtualFile, File> copyFromMap,
      Set<VirtualFile> recursiveItems) {
    final Collection<AddedFileInfo> addedFileInfos = myAddedFiles.remove(project);
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);

    for (AddedFileInfo addedFileInfo : addedFileInfos) {
      final File ioFile = new File(getIOFile(addedFileInfo.myDir), addedFileInfo.myName);
      VirtualFile addedFile = addedFileInfo.myDir.findChild(addedFileInfo.myName);
      if (addedFile == null) {
        addedFile = myLfs.refreshAndFindFileByIoFile(ioFile);
      }
      if (addedFile != null) {
        final SVNStatus fileStatus = getFileStatus(vcs, ioFile);
        if (fileStatus == null || !SvnVcs.svnStatusIs(fileStatus, SVNStatusType.STATUS_IGNORED)) {
          boolean isIgnored = changeListManager.isIgnoredFile(addedFile);
          if (!isIgnored) {
            addedVFiles.add(addedFile);
            copyFromMap.put(addedFile, addedFileInfo.myCopyFrom);
            if (addedFileInfo.myRecursive) {
              recursiveItems.add(addedFile);
            }
          }
        }
      }
    }
  }
Esempio n. 2
0
  public SvnVcs(
      final Project project,
      MessageBus bus,
      SvnConfiguration svnConfiguration,
      final SvnLoadedBrachesStorage storage) {
    super(project, VCS_NAME);
    myLoadedBranchesStorage = storage;
    LOG.debug("ct");
    myRootsToWorkingCopies = new RootsToWorkingCopies(this);
    myConfiguration = svnConfiguration;
    myAuthNotifier = new SvnAuthenticationNotifier(this);

    dumpFileStatus(FileStatus.ADDED);
    dumpFileStatus(FileStatus.DELETED);
    dumpFileStatus(FileStatus.MERGE);
    dumpFileStatus(FileStatus.MODIFIED);
    dumpFileStatus(FileStatus.NOT_CHANGED);
    dumpFileStatus(FileStatus.UNKNOWN);

    dumpFileStatus(SvnFileStatus.REPLACED);
    dumpFileStatus(SvnFileStatus.EXTERNAL);
    dumpFileStatus(SvnFileStatus.OBSTRUCTED);

    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    myAddConfirmation =
        vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, this);
    myDeleteConfirmation =
        vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, this);
    myCheckoutOptions =
        vcsManager.getStandardOption(VcsConfiguration.StandardOption.CHECKOUT, this);

    if (myProject.isDefault()) {
      myChangeListListener = null;
      myEntriesFileListener = null;
    } else {
      myEntriesFileListener = new SvnEntriesFileListener(project);
      upgradeIfNeeded(bus);

      myChangeListListener = new SvnChangelistListener(myProject, this);

      myVcsListener =
          new VcsListener() {
            @Override
            public void directoryMappingChanged() {
              invokeRefreshSvnRoots(true);
            }
          };
    }

    myFrameStateListener =
        project.isDefault()
            ? null
            : new MyFrameStateListener(
                ChangeListManager.getInstance(project), VcsDirtyScopeManager.getInstance(project));
    myWorkingCopiesContent = new WorkingCopiesContent(this);

    // remove used some time before old notification group ids
    correctNotificationIds();
    myChecker = new SvnExecutableChecker(myProject);
  }
  @CalledInAwt
  public static void refreshPassedFilesAndMoveToChangelist(
      @NotNull final Project project,
      final Collection<FilePath> directlyAffected,
      final Collection<VirtualFile> indirectlyAffected,
      final Consumer<Collection<FilePath>> targetChangelistMover) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    for (FilePath filePath : directlyAffected) {
      lfs.refreshAndFindFileByIoFile(filePath.getIOFile());
    }
    if (project.isDisposed()) return;

    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (!directlyAffected.isEmpty() && targetChangelistMover != null) {
      changeListManager.invokeAfterUpdate(
          new Runnable() {
            @Override
            public void run() {
              targetChangelistMover.consume(directlyAffected);
            }
          },
          InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE,
          VcsBundle.message("change.lists.manager.move.changes.to.list"),
          new Consumer<VcsDirtyScopeManager>() {
            @Override
            public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) {
              markDirty(vcsDirtyScopeManager, directlyAffected, indirectlyAffected);
            }
          },
          null);
    } else {
      markDirty(VcsDirtyScopeManager.getInstance(project), directlyAffected, indirectlyAffected);
    }
  }
  private boolean stash() {
    if (!mySyncResult.hasLocalRepository()) {
      LOG.error("unexpected null local repro in call to stash");
      return false;
    }

    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    if (changeListManager.isFreezedWithNotification("Can not stash changes now")) return false;

    final GitLineHandler handler =
        new GitLineHandler(myProject, mySourceRepository.getRoot(), GitCommand.STASH);
    handler.addParameters("save");
    handler.addParameters("--keep-index");
    String date =
        DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date());
    myStashMessage =
        "Cloud Debugger saved changes from branch " + myOriginalBranchName + " at " + date;
    handler.addParameters(myStashMessage);
    AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
    try {
      GitHandlerUtil.doSynchronously(
          handler, GitBundle.getString("stashing.title"), handler.printableCommandLine());
    } finally {
      DvcsUtil.workingTreeChangeFinished(myProject, token);
    }
    return true;
  }
Esempio n. 5
0
 /**
  * Given the list of paths converts them to the list of {@link Change Changes} found in the {@link
  * ChangeListManager}, i.e. this works only for local changes. </br> Paths can be absolute or
  * relative to the repository. If a path is not found in the local changes, it is ignored, but the
  * fact is logged.
  */
 @NotNull
 public static List<Change> findLocalChangesForPaths(
     @NotNull Project project,
     @NotNull VirtualFile root,
     @NotNull Collection<String> affectedPaths,
     boolean relativePaths) {
   ChangeListManagerEx changeListManager =
       (ChangeListManagerEx) ChangeListManager.getInstance(project);
   List<Change> affectedChanges = new ArrayList<Change>();
   for (String path : affectedPaths) {
     String absolutePath = relativePaths ? toAbsolute(root, path) : path;
     VirtualFile file = findRefreshFileOrLog(absolutePath);
     if (file != null) {
       Change change = changeListManager.getChange(file);
       if (change != null) {
         affectedChanges.add(change);
       } else {
         String message = "Change is not found for " + file.getPath();
         if (changeListManager.isInUpdate()) {
           message += " because ChangeListManager is being updated.";
         }
         LOG.warn(message);
       }
     }
   }
   return affectedChanges;
 }
 public ChangesBrowserChangeListNode(
     Project project, ChangeList userObject, final ChangeListRemoteState changeListRemoteState) {
   super(userObject);
   myChangeListRemoteState = changeListRemoteState;
   myClManager = (ChangeListManagerEx) ChangeListManager.getInstance(project);
   myDecorators = ComponentsPackage.getComponents(project, ChangeListDecorator.class);
 }
 @NotNull
 private Map<VirtualFile, GitUpdater> tryFastForwardMergeForRebaseUpdaters(
     @NotNull Map<VirtualFile, GitUpdater> updaters) {
   Map<VirtualFile, GitUpdater> modifiedUpdaters = new HashMap<VirtualFile, GitUpdater>();
   Map<VirtualFile, Collection<Change>> changesUnderRoots =
       new LocalChangesUnderRoots(
               ChangeListManager.getInstance(myProject),
               ProjectLevelVcsManager.getInstance(myProject))
           .getChangesUnderRoots(updaters.keySet());
   for (Map.Entry<VirtualFile, GitUpdater> updaterEntry : updaters.entrySet()) {
     VirtualFile root = updaterEntry.getKey();
     GitUpdater updater = updaterEntry.getValue();
     Collection<Change> changes = changesUnderRoots.get(root);
     if (updater instanceof GitRebaseUpdater && changes != null && !changes.isEmpty()) {
       // check only if there are local changes, otherwise stash won't happen anyway and there
       // would be no optimization
       GitRebaseUpdater rebaseUpdater = (GitRebaseUpdater) updater;
       if (rebaseUpdater.fastForwardMerge()) {
         continue;
       }
     }
     modifiedUpdaters.put(root, updater);
   }
   return modifiedUpdaters;
 }
  @Test
  public void testRenameList() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand("a.txt", "old content");
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    changeListManager.ensureUpToDate(false);

    final LocalChangeList list = changeListManager.addChangeList("test", null);
    changeListManager.moveChangesTo(list, new Change[] {changeListManager.getChange(file)});

    final String newName = "renamed";

    myScheme.doTest(
        new Runnable() {
          @Override
          public void run() {
            changeListManager.editName(list.getName(), newName);
            checkFilesAreInList(new VirtualFile[] {file}, newName, changeListManager);
          }
        });

    checkFilesAreInList(new VirtualFile[] {file}, newName, changeListManager);

    changeListManager.ensureUpToDate(false);
    checkFilesAreInList(new VirtualFile[] {file}, newName, changeListManager);
  }
  @Nullable
  public LocalChangeList getSelectedList(Project project) {
    ChangeListManager manager = ChangeListManager.getInstance(project);
    if (myRbNew.isSelected()) {
      String newText = myNewListPanel.getChangeListName();
      if (manager.findChangeList(newText) != null) {
        Messages.showErrorDialog(
            project,
            VcsBundle.message("changes.newchangelist.warning.already.exists.text", newText),
            VcsBundle.message("changes.newchangelist.warning.already.exists.title"));
        return null;
      }
    }
    final boolean existingSelected = myRbExisting.isSelected();
    VcsConfiguration.getInstance(myProject).PRESELECT_EXISTING_CHANGELIST = existingSelected;

    if (existingSelected) {
      return (LocalChangeList) myExistingListsCombo.getSelectedItem();
    } else {
      LocalChangeList changeList =
          manager.addChangeList(
              myNewListPanel.getChangeListName(), myNewListPanel.getDescription());
      myNewListPanel.changelistCreatedOrChanged(changeList);
      if (myNewListPanel.getMakeActiveCheckBox().isSelected()) {
        manager.setDefaultChangeList(changeList);
      }
      VcsConfiguration.getInstance(project).MAKE_NEW_CHANGELIST_ACTIVE =
          myNewListPanel.getMakeActiveCheckBox().isSelected();

      return changeList;
    }
  }
  @Test
  public void testSetActive() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand("a.txt", "old content");
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    changeListManager.ensureUpToDate(false);

    final LocalChangeList list = changeListManager.addChangeList("test", null);
    final LocalChangeList target = changeListManager.addChangeList("target", null);
    changeListManager.moveChangesTo(list, new Change[] {changeListManager.getChange(file)});

    myScheme.doTest(
        new Runnable() {
          @Override
          public void run() {
            changeListManager.setDefaultChangeList(target);
            assert changeListManager.getDefaultChangeList().getName().equals(target.getName());
          }
        });

    assert changeListManager.getDefaultChangeList().getName().equals(target.getName());

    changeListManager.ensureUpToDate(false);
    assert changeListManager.getDefaultChangeList().getName().equals(target.getName());
  }
  /** call in setUp */
  public DuringChangeListManagerUpdateTestScheme(final Project project, final String tmpDirPath) {
    final MockAbstractVcs vcs = new MockAbstractVcs(project);
    myChangeProvider = new MockDelayingChangeProvider();
    vcs.setChangeProvider(myChangeProvider);

    final File mockVcsRoot = new File(tmpDirPath, "mock");
    mockVcsRoot.mkdir();
    final VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(mockVcsRoot);

    final ProjectLevelVcsManagerImpl projectLevelVcsManager =
        (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project);
    projectLevelVcsManager.registerVcs(vcs);
    // projectLevelVcsManager.setDirectoryMapping(mockVcsRoot.getAbsolutePath(), vcs.getName());
    final ArrayList<VcsDirectoryMapping> list =
        new ArrayList<VcsDirectoryMapping>(projectLevelVcsManager.getDirectoryMappings());
    list.add(new VcsDirectoryMapping(vRoot.getPath(), vcs.getName()));
    projectLevelVcsManager.setDirectoryMappings(list);

    AbstractVcs vcsFound = projectLevelVcsManager.findVcsByName(vcs.getName());
    final VirtualFile[] roots = projectLevelVcsManager.getRootsUnderVcs(vcsFound);
    assert roots.length == 1
        : Arrays.asList(roots)
            + "; "
            + vcs.getName()
            + "; "
            + Arrays.toString(AllVcses.getInstance(project).getAll());

    myDirtyScopeManager = VcsDirtyScopeManager.getInstance(project);
    myClManager = ChangeListManager.getInstance(project);
  }
Esempio n. 12
0
  @Override
  public void deactivate() {
    FrameStateManager.getInstance().removeListener(myFrameStateListener);

    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
    if (myVcsListener != null) {
      vcsManager.removeVcsListener(myVcsListener);
    }

    if (myEntriesFileListener != null) {
      VirtualFileManager.getInstance().removeVirtualFileListener(myEntriesFileListener);
    }
    SvnApplicationSettings.getInstance().svnDeactivated();
    if (myCommittedChangesProvider != null) {
      myCommittedChangesProvider.deactivate();
    }
    if (myChangeListListener != null && !myProject.isDefault()) {
      ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListListener);
    }
    vcsManager.removeVcsListener(myRootsToWorkingCopies);
    myRootsToWorkingCopies.clear();

    myAuthNotifier.stop();
    myAuthNotifier.clear();

    mySvnBranchPointsCalculator.deactivate();
    mySvnBranchPointsCalculator = null;
    myWorkingCopiesContent.deactivate();
    myLoadedBranchesStorage.deactivate();
    myPool.dispose();
    myPool = null;
  }
  @Override
  public void rebuildList() {
    if (myInRebuildList) return;
    try {
      myInRebuildList = true;
      if (myChangesToDisplay == null) {
        // changes set not fixed === local changes
        final ChangeListManager manager = ChangeListManager.getInstance(myProject);
        myChangeListsMap = new HashMap<Change, LocalChangeList>();
        final List<LocalChangeList> lists = manager.getChangeListsCopy();
        Collection<Change> allChanges = new ArrayList<Change>();
        for (LocalChangeList list : lists) {
          final Collection<Change> changes = list.getChanges();
          allChanges.addAll(changes);
          for (Change change : changes) {
            myChangeListsMap.put(change, list);
          }
        }
        myAllChanges = allChanges;
        // refresh selected list also
        updateListsInChooser();
      }

      super.rebuildList();
      if (myRebuildListListener != null) {
        myRebuildListListener.run();
      }
    } finally {
      myInRebuildList = false;
    }
  }
  @Test
  public void testEditComment() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand("a.txt", "old content");
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    changeListManager.ensureUpToDate(false);

    final String listName = "test";
    final LocalChangeList list = changeListManager.addChangeList(listName, null);
    changeListManager.moveChangesTo(list, new Change[] {changeListManager.getChange(file)});

    final String finalText = "final text";

    myScheme.doTest(
        new Runnable() {
          public void run() {
            final String intermediate = "intermediate text";
            changeListManager.editComment(list.getName(), intermediate);
            assert changeListManager.findChangeList(listName) != null;
            LocalChangeList list = changeListManager.findChangeList(listName);
            assert intermediate.equals(list.getComment());

            changeListManager.editComment(list.getName(), finalText);
            list = changeListManager.findChangeList(listName);
            assert finalText.equals(list.getComment());
          }
        });

    LocalChangeList changedList = changeListManager.findChangeList(listName);
    assert finalText.equals(changedList.getComment());

    changeListManager.ensureUpToDate(false);
    changedList = changeListManager.findChangeList(listName);
    assert finalText.equals(changedList.getComment());
  }
  @Test
  public void testDoubleMove() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand("a.txt", "old content");
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    changeListManager.ensureUpToDate(false);

    final LocalChangeList list = changeListManager.addChangeList("test", null);
    final LocalChangeList target = changeListManager.addChangeList("target", null);
    final LocalChangeList target2 = changeListManager.addChangeList("target2", null);
    changeListManager.moveChangesTo(list, new Change[] {changeListManager.getChange(file)});

    myScheme.doTest(
        new Runnable() {
          public void run() {
            changeListManager.moveChangesTo(
                target, new Change[] {changeListManager.getChange(file)});
            checkFilesAreInList(new VirtualFile[] {file}, target.getName(), changeListManager);
            changeListManager.moveChangesTo(
                target2, new Change[] {changeListManager.getChange(file)});
            checkFilesAreInList(new VirtualFile[] {file}, target2.getName(), changeListManager);
          }
        });

    checkFilesAreInList(new VirtualFile[] {file}, target2.getName(), changeListManager);

    changeListManager.ensureUpToDate(false);
    checkFilesAreInList(new VirtualFile[] {file}, target2.getName(), changeListManager);
  }
  @Test
  public void testRemove() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand("a.txt", "old content");
    final VirtualFile fileB = createFileInCommand("b.txt", "old content");
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    changeListManager.ensureUpToDate(false);

    final LocalChangeList list = changeListManager.addChangeList("test", null);
    changeListManager.moveChangesTo(list, new Change[] {changeListManager.getChange(file)});

    myScheme.doTest(
        new Runnable() {
          public void run() {
            changeListManager.removeChangeList(list.getName());
            assert changeListManager.findChangeList(list.getName()) == null;
            checkFilesAreInList(
                new VirtualFile[] {file, fileB}, myDefaulListName, changeListManager);
          }
        });

    assert changeListManager.findChangeList(list.getName()) == null;
    checkFilesAreInList(new VirtualFile[] {file, fileB}, myDefaulListName, changeListManager);

    changeListManager.ensureUpToDate(false);
    assert changeListManager.findChangeList(list.getName()) == null;
    checkFilesAreInList(new VirtualFile[] {file, fileB}, myDefaulListName, changeListManager);
  }
  // todo terrible constructor
  public MultipleChangeListBrowser(
      Project project,
      List<? extends ChangeList> changeLists,
      List<Change> changes,
      Disposable parentDisposable,
      ChangeList initialListSelection,
      boolean capableOfExcludingChanges,
      boolean highlightProblems,
      Runnable rebuildListListener,
      @Nullable Runnable inclusionListener,
      AnAction... additionalActions) {
    super(
        project,
        changeLists,
        changes,
        initialListSelection,
        capableOfExcludingChanges,
        highlightProblems,
        inclusionListener,
        MyUseCase.LOCAL_CHANGES,
        null);
    myParentDisposable = parentDisposable;
    myRebuildListListener = rebuildListListener;

    myChangeListChooser = new ChangeListChooser(changeLists);
    myHeaderPanel.add(myChangeListChooser, BorderLayout.EAST);
    myShowingAllChangeLists =
        Comparing.haveEqualElements(
            changeLists, ChangeListManager.getInstance(project).getChangeLists());
    ChangeListManager.getInstance(myProject).addChangeListListener(myChangeListListener);

    myExtender = new Extender(project, this, additionalActions);

    ActionManager actionManager = ActionManager.getInstance();
    final AnAction moveAction = actionManager.getAction(IdeActions.MOVE_TO_ANOTHER_CHANGE_LIST);
    actionManager.addAnActionListener(
        new AnActionListener.Adapter() {
          @Override
          public void afterActionPerformed(
              AnAction action, DataContext dataContext, AnActionEvent event) {
            if (moveAction.equals(action)) {
              rebuildList();
            }
          }
        },
        myParentDisposable);
  }
 @Nullable
 private static Consumer<Collection<FilePath>> createMover(
     final Project project, final LocalChangeList targetChangeList) {
   final ChangeListManager clm = ChangeListManager.getInstance(project);
   if (targetChangeList == null || clm.getDefaultListName().equals(targetChangeList.getName()))
     return null;
   return new FilesMover(clm, targetChangeList);
 }
 private VcsRootProblemNotifier(@NotNull Project project) {
   myProject = project;
   mySettings = VcsConfiguration.getInstance(myProject);
   myChangeListManager = ChangeListManager.getInstance(project);
   myProjectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
   myVcsManager = ProjectLevelVcsManager.getInstance(project);
   myReportedUnregisteredRoots = new HashSet<>(mySettings.IGNORED_UNREGISTERED_ROOTS);
 }
Esempio n. 20
0
 @Override
 public boolean fileIsUnderVcs(FilePath path) {
   final ChangeListManager clManager = ChangeListManager.getInstance(myProject);
   final VirtualFile file = path.getVirtualFile();
   if (file == null) {
     return false;
   }
   return !SvnStatusUtil.isIgnoredInAnySense(clManager, file) && !clManager.isUnversioned(file);
 }
 @Nullable
 private static Change[] loadFakeRevisions(final Project project, final Change[] changes) {
   List<Change> matchingChanges = new ArrayList<Change>();
   for (Change change : changes) {
     matchingChanges.addAll(
         ChangeListManager.getInstance(project).getChangesIn(ChangesUtil.getFilePath(change)));
   }
   return matchingChanges.toArray(new Change[matchingChanges.size()]);
 }
 public static HgFile getOriginalHgFile(Project project, VirtualFile root) {
   HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
   if (project.isDisposed()) {
     return hgFile;
   }
   FilePath originalFileName =
       HgUtil.getOriginalFileName(hgFile.toFilePath(), ChangeListManager.getInstance(project));
   return new HgFile(hgFile.getRepo(), originalFileName);
 }
Esempio n. 23
0
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) return;
    final ShelvedChangeList[] changeLists =
        e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY);
    List<ShelvedChange> changes = e.getData(ShelvedChangesViewManager.SHELVED_CHANGE_KEY);
    List<ShelvedBinaryFile> binaryFiles =
        e.getData(ShelvedChangesViewManager.SHELVED_BINARY_FILE_KEY);
    if (changes != null && binaryFiles != null && changes.size() == 0 && binaryFiles.size() == 0) {
      changes = null;
      binaryFiles = null;
    }
    LOG.assertTrue(changeLists != null);

    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    final List<LocalChangeList> allChangeLists = changeListManager.getChangeListsCopy();
    String defaultName = changeLists[0].DESCRIPTION;
    LocalChangeList list = null;
    if (changeLists.length == 1) {
      final LocalChangeList sameNamedList = changeListManager.findChangeList(defaultName);
      if (sameNamedList != null) {
        list = sameNamedList;
      }
    }
    if (list == null) {
      list = changeListManager.getDefaultChangeList();
    }
    final ChangeListChooser chooser =
        new ChangeListChooser(
            project,
            allChangeLists,
            list,
            VcsBundle.message("unshelve.changelist.chooser.title"),
            defaultName);
    chooser.show();
    if (!chooser.isOK()) {
      return;
    }

    FileDocumentManager.getInstance().saveAllDocuments();

    final List<ShelvedBinaryFile> finalBinaryFiles = binaryFiles;
    final List<ShelvedChange> finalChanges = changes;
    ProgressManager.getInstance()
        .run(
            new Task.Backgroundable(
                project, "Unshelve changes", true, BackgroundFromStartOption.getInstance()) {
              @Override
              public void run(@NotNull ProgressIndicator indicator) {
                for (ShelvedChangeList changeList : changeLists) {
                  ShelveChangesManager.getInstance(project)
                      .unshelveChangeList(
                          changeList, finalChanges, finalBinaryFiles, chooser.getSelectedList());
                }
              }
            });
  }
Esempio n. 24
0
 private void disposeListeners() {
   FileStatusManager.getInstance(myProject).removeFileStatusListener(myFileStatusListener);
   VirtualFileManager.getInstance().removeVirtualFileListener(myFileListener);
   VirtualFileManager.getInstance().removeVirtualFileManagerListener(myVirtualFileManagerListener);
   myProject
       .getComponent(ProjectLevelVcsManager.class)
       .removeVcsListener(myDirectoryMappingListener);
   ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListListener);
   myMessageBusConnection.disconnect();
 }
  @NotNull
  public AnalysisScope getScope(
      @NotNull AnalysisUIOptions uiOptions,
      @NotNull AnalysisScope defaultScope,
      @NotNull 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;
  }
  @Test
  public void testComplex() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand("a.txt", "old content");
    final VirtualFile fileB = createFileInCommand("b.txt", "old content");
    final VirtualFile fileC = createFileInCommand("c.txt", "old content");
    final VirtualFile fileD = createFileInCommand("d.txt", "old content");

    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);

    final LocalChangeList list = changeListManager.addChangeList("test", null);
    final LocalChangeList toBeDeletedList =
        changeListManager.addChangeList("toBeDeletedList", null);
    changeListManager.moveChangesTo(
        list, new Change[] {changeListManager.getChange(file), changeListManager.getChange(fileB)});
    changeListManager.moveChangesTo(
        toBeDeletedList,
        new Change[] {changeListManager.getChange(fileC), changeListManager.getChange(fileD)});
    changeListManager.ensureUpToDate(false);

    final String targetName = "target";
    final String finalName = "final list name";

    myScheme.doTest(
        new Runnable() {
          @Override
          public void run() {
            final LocalChangeList target = changeListManager.addChangeList(targetName, null);
            changeListManager.moveChangesTo(
                target,
                new Change[] {
                  changeListManager.getChange(file), changeListManager.getChange(fileB)
                });
            checkFilesAreInList(new VirtualFile[] {file, fileB}, targetName, changeListManager);
            changeListManager.editName(targetName, finalName);
            checkFilesAreInList(new VirtualFile[] {file, fileB}, finalName, changeListManager);
            changeListManager.removeChangeList(toBeDeletedList.getName());
            checkFilesAreInList(
                new VirtualFile[] {fileC, fileD}, myDefaulListName, changeListManager);
            changeListManager.moveChangesTo(
                LocalChangeList.createEmptyChangeList(myProject, finalName),
                new Change[] {changeListManager.getChange(fileC)});
            checkFilesAreInList(
                new VirtualFile[] {file, fileB, fileC}, finalName, changeListManager);
            checkFilesAreInList(new VirtualFile[] {fileD}, myDefaulListName, changeListManager);
          }
        });

    checkFilesAreInList(new VirtualFile[] {file, fileB, fileC}, finalName, changeListManager);
    checkFilesAreInList(new VirtualFile[] {fileD}, myDefaulListName, changeListManager);

    changeListManager.ensureUpToDate(false);
    checkFilesAreInList(new VirtualFile[] {file, fileB, fileC}, finalName, changeListManager);
    checkFilesAreInList(new VirtualFile[] {fileD}, myDefaulListName, changeListManager);
  }
Esempio n. 27
0
  public void doRollback(
      final Collection<Change> changes,
      final boolean deleteLocallyAddedFiles,
      @Nullable final Runnable afterVcsRefreshInAwt,
      @Nullable final String localHistoryActionName) {
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    final Runnable notifier = changeListManager.prepareForChangeDeletion(changes);
    final Runnable afterRefresh =
        new Runnable() {
          public void run() {
            changeListManager.invokeAfterUpdate(
                new Runnable() {
                  public void run() {
                    notifier.run();
                    if (afterVcsRefreshInAwt != null) {
                      afterVcsRefreshInAwt.run();
                    }
                  }
                },
                InvokeAfterUpdateMode.SILENT,
                "Refresh change lists after update",
                ModalityState.current());
          }
        };

    final Runnable rollbackAction =
        new MyRollbackRunnable(
            changes, deleteLocallyAddedFiles, afterRefresh, localHistoryActionName);

    if (ApplicationManager.getApplication().isDispatchThread()) {
      ProgressManager.getInstance()
          .run(
              new Task.Backgroundable(
                  myProject,
                  VcsBundle.message("changes.action.rollback.text"),
                  true,
                  new PerformInBackgroundOption() {
                    public boolean shouldStartInBackground() {
                      return VcsConfiguration.getInstance(myProject).PERFORM_ROLLBACK_IN_BACKGROUND;
                    }

                    public void processSentToBackground() {
                      VcsConfiguration.getInstance(myProject).PERFORM_ROLLBACK_IN_BACKGROUND = true;
                    }
                  }) {
                public void run(@NotNull ProgressIndicator indicator) {
                  rollbackAction.run();
                }
              });
    } else {
      rollbackAction.run();
    }
    ((ChangeListManagerImpl) changeListManager).showLocalChangesInvalidated();
  }
 /**
  * Get name of the file in the last commit. If file was renamed, returns the previous name.
  *
  * @param project the context project
  * @param path the path to check
  * @return the name of file in the last commit or argument
  */
 public static FilePath getLastCommitName(final Project project, FilePath path) {
   if (project.isDefault()) return path;
   final ChangeListManager changeManager = ChangeListManager.getInstance(project);
   final Change change = changeManager.getChange(path);
   if (change != null && change.getType() == Change.Type.MOVED) {
     // GitContentRevision r = (GitContentRevision)change.getBeforeRevision();
     assert change.getBeforeRevision() != null : "Move change always have beforeRevision";
     path = change.getBeforeRevision().getFile();
   }
   return path;
 }
  @Override
  public void setUp() throws Exception {
    super.setUp();

    clManager = (ChangeListManagerImpl) ChangeListManager.getInstance(myProject);

    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
    myVcs = SvnVcs.getInstance(myProject);
    myMainUrl = myRepoUrl + "/root/source";
    myExternalURL = myRepoUrl + "/root/target";
  }
  @Test
  public void testSwitchedFileAndFolder() throws Exception {
    final String branchUrl = prepareBranchesStructure();

    final SubTree tree = new SubTree(myWorkingCopyDir);

    verify(runSvn("switch", branchUrl + "/root/source/s1.txt", tree.myS1File.getPath()));
    verify(runSvn("switch", branchUrl + "/root/target", tree.myTargetDir.getPath()));

    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    changeListManager.ensureUpToDate(false);

    final Runnable check =
        new Runnable() {
          @Override
          public void run() {
            Assert.assertEquals(FileStatus.SWITCHED, changeListManager.getStatus(tree.myS1File));
            Assert.assertEquals(FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.myS2File));
            Assert.assertEquals(
                FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.mySourceDir));
            Assert.assertEquals(FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetDir));
            Assert.assertEquals(
                FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetFiles.get(1)));
          }
        };
    myScheme.doTest(check);

    changeListManager.ensureUpToDate(false);
    check.run();

    editFileInCommand(myProject, tree.myS1File, "1234543534543 3543 ");
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    changeListManager.ensureUpToDate(false);

    final Runnable check2 =
        new Runnable() {
          @Override
          public void run() {
            Assert.assertEquals(FileStatus.MODIFIED, changeListManager.getStatus(tree.myS1File));
            Assert.assertEquals(FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.myS2File));
            Assert.assertEquals(
                FileStatus.NOT_CHANGED, changeListManager.getStatus(tree.mySourceDir));
            Assert.assertEquals(FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetDir));
            Assert.assertEquals(
                FileStatus.SWITCHED, changeListManager.getStatus(tree.myTargetFiles.get(1)));
          }
        };
    myScheme.doTest(check2);

    changeListManager.ensureUpToDate(false);
    check2.run();
  }