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");
  }
  @Nullable
  public SVNURL getWcUrl(final AuthenticationRequest obj) {
    if (obj.isOutsideCopies()) return null;
    if (obj.getWcUrl() != null) return obj.getWcUrl();

    final WorkingCopy copy = myRootsToWorkingCopies.getMatchingCopy(obj.getUrl());
    if (copy != null) {
      obj.setOutsideCopies(false);
      obj.setWcUrl(copy.getUrl());
    } else {
      obj.setOutsideCopies(true);
    }
    return copy == null ? null : copy.getUrl();
  }
  /** Bases on presence of notifications! */
  public ThreeState isAuthenticatedFor(final VirtualFile vf) {
    final WorkingCopy wcCopy = myRootsToWorkingCopies.getWcRoot(vf);
    if (wcCopy == null) return ThreeState.UNSURE;

    // check there's no cancellation yet
    final boolean haveCancellation = getStateFor(wcCopy.getUrl());
    if (haveCancellation) return ThreeState.NO;

    final Boolean keptResult = myCopiesPassiveResults.get(wcCopy.getUrl());
    if (Boolean.TRUE.equals(keptResult)) return ThreeState.YES;
    if (Boolean.FALSE.equals(keptResult)) return ThreeState.NO;

    // check have credentials
    final boolean calculatedResult = passiveValidation(myVcs.getProject(), wcCopy.getUrl());
    myCopiesPassiveResults.put(wcCopy.getUrl(), calculatedResult);
    return calculatedResult ? ThreeState.YES : ThreeState.NO;
  }
Exemple #4
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();
    }
  }
Exemple #5
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();
    }
  }
Exemple #6
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();
    }
  }