@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);
  }
  @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);
  }
  @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());
  }
  @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);
  }
 /**
  * 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;
 }
Пример #8
0
    @Override
    public void consume(Collection<FilePath> directlyAffected) {
      List<Change> changes = new ArrayList<>();
      for (FilePath file : directlyAffected) {
        final Change change = myChangeListManager.getChange(file);
        if (change != null) {
          changes.add(change);
        }
      }

      myChangeListManager.moveChangesTo(
          myTargetChangeList, changes.toArray(new Change[changes.size()]));
    }