void (VirtualFile source, VirtualFile target) { VirtualFile sourceRepo = VcsUtil.getVcsRootFor(myProject, source); VirtualFile targetRepo = VcsUtil.getVcsRootFor(myProject, target); HgCommandExecutor executor = new HgCommandExecutor(myProject, VcsFileUtil.relativeOrFullPath(sourceRepo, source)); if (sourceRepo != null && targetRepo != null && sourceRepo.equals(targetRepo)) { HgCommandResult result; int attempt = 0; do { result = executor.executeInCurrentThread(sourceRepo, "copy", Arrays.asList("--after", VcsFileUtil.relativeOrFullPath(sourceRepo, source), VcsFileUtil.relativeOrFullPath(targetRepo, target))); } while (HgErrorUtil.isWLockError(result) && attempt++ < 2); } else { // copying from one repository to another => 'hg add' in new repo if (targetRepo != null) { new HgAddCommand(myProject).executeInCurrentThread(Collections.singleton(target)); } } }