private long replaceByFile(WorkingCopy workingCopy) throws SVNException {
    final File workingCopyDirectory = workingCopy.getWorkingCopyDirectory();

    final File trunk = new File(workingCopyDirectory, "trunk");
    final File node = new File(trunk, "node");
    SVNFileUtil.deleteAll(node, true);
    workingCopy.delete(node);

    SVNFileUtil.createFile(node, "This is trunk/node", "UTF-8");
    workingCopy.add(node);

    return workingCopy.commit("Replaced by file");
  }
Esempio n. 2
0
  @Test
  public void testLocksUnderRemovedDirectoryAreRemoved() throws Exception {
    final TestOptions options = TestOptions.getInstance();

    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    final Sandbox sandbox =
        Sandbox.createWithCleanup(
            getTestName() + ".testLocksUnderRemovedDirectoryAreRemoved", options);
    try {
      final SVNURL url = sandbox.createSvnRepository();

      final CommitBuilder commitBuilder = new CommitBuilder(url);
      commitBuilder.addFile("directory/file");
      commitBuilder.commit();

      final WorkingCopy workingCopy = sandbox.checkoutNewWorkingCopy(url);
      final File workingCopyDirectory = workingCopy.getWorkingCopyDirectory();
      final File directory = workingCopy.getFile("directory");
      final File file = workingCopy.getFile("directory/file");

      final SvnSetLock setLock = svnOperationFactory.createSetLock();
      setLock.setSingleTarget(SvnTarget.fromFile(file));
      setLock.run();

      workingCopy.delete(directory);
      workingCopy.commit("");

      SVNFileUtil.ensureDirectoryExists(directory);
      TestUtil.writeFileContentsString(file, "");

      final SvnScheduleForAddition scheduleForAddition =
          svnOperationFactory.createScheduleForAddition();
      scheduleForAddition.setAddParents(true);
      scheduleForAddition.setSingleTarget(SvnTarget.fromFile(file));
      scheduleForAddition.run();

      workingCopy.commit("");

      final Map<File, SvnStatus> statuses =
          TestUtil.getStatuses(svnOperationFactory, workingCopyDirectory);
      final SvnStatus status = statuses.get(file);
      Assert.assertNull(status.getLock());

    } finally {
      svnOperationFactory.dispose();
      sandbox.dispose();
    }
  }
Esempio n. 3
0
  @Test
  public void testMoveFileOutOfVersionControl() throws Exception {
    // SVNKIT-295
    final TestOptions options = TestOptions.getInstance();

    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    final Sandbox sandbox =
        Sandbox.createWithCleanup(getTestName() + ".testMoveFileOutOfVersionControl", options);
    try {
      final SVNURL url = sandbox.createSvnRepository();

      final CommitBuilder commitBuilder = new CommitBuilder(url);
      commitBuilder.addFile("file");
      commitBuilder.commit();

      final WorkingCopy workingCopy = sandbox.checkoutNewWorkingCopy(url);
      final File file = workingCopy.getFile("file");

      final File unversionedDirectory = workingCopy.getFile("unversionedDirectory");
      final File targetFile = new File(unversionedDirectory, "file");

      final SVNClientManager clientManager = SVNClientManager.newInstance();
      try {
        final SVNMoveClient moveClient = clientManager.getMoveClient();
        moveClient.doMove(file, targetFile);

        final Map<File, SvnStatus> statuses =
            TestUtil.getStatuses(svnOperationFactory, workingCopy.getWorkingCopyDirectory());
        Assert.assertEquals(SVNStatusType.STATUS_DELETED, statuses.get(file).getNodeStatus());
        Assert.assertEquals(
            SVNStatusType.STATUS_UNVERSIONED, statuses.get(unversionedDirectory).getNodeStatus());
        Assert.assertNull(statuses.get(targetFile));
      } finally {
        clientManager.dispose();
      }
    } finally {
      svnOperationFactory.dispose();
      sandbox.dispose();
    }
  }
Esempio n. 4
0
  @Test
  public void testRelocateCleansDavCache() throws Exception {
    final TestOptions options = TestOptions.getInstance();
    Assume.assumeTrue(TestUtil.areAllApacheOptionsSpecified(options));
    Assume.assumeTrue(TestUtil.isNewWorkingCopyTest());

    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    final Sandbox sandbox =
        Sandbox.createWithCleanup(getTestName() + ".testRelocateCleansDavCache", options);
    try {
      final SVNURL url = sandbox.createSvnRepositoryWithDavAccess();

      final CommitBuilder commitBuilder = new CommitBuilder(url);
      commitBuilder.addFile("file");
      commitBuilder.commit();

      final WorkingCopy workingCopy = sandbox.checkoutNewWorkingCopy(url);
      final File workingCopyDirectory = workingCopy.getWorkingCopyDirectory();

      final File file = new File(workingCopyDirectory, "file");

      final SVNURL fsfsUrl = sandbox.getFSFSAccessUrl(url);

      final String wcUrlBeforeRelocate = getWcUrl(svnOperationFactory, file);
      Assert.assertNotNull(wcUrlBeforeRelocate);

      final SvnRelocate relocate = svnOperationFactory.createRelocate();
      relocate.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
      relocate.setToUrl(fsfsUrl);
      relocate.run();

      final String wcUrlAfterRelocate = getWcUrl(svnOperationFactory, file);
      Assert.assertNull(wcUrlAfterRelocate);

    } finally {
      svnOperationFactory.dispose();
      sandbox.dispose();
    }
  }