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"); }
@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(); } }