IDEA-53288 Idea should support standard Subversion layout: if target remote folder is not new, check whether it is empty

This commit is contained in:
irengrig
2010-08-31 17:45:08 +04:00
parent d3698c52d9
commit f4a9142a20
2 changed files with 57 additions and 9 deletions
@@ -21,6 +21,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vcs.AbstractVcsHelper;
import com.intellij.openapi.vcs.RepositoryLocation;
import com.intellij.openapi.vcs.VcsException;
@@ -36,9 +37,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.branchConfig.SvnBranchConfigurationNew;
import org.jetbrains.idea.svn.dialogs.LockDialog;
import org.jetbrains.idea.svn.dialogs.WCInfo;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.*;
import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
import org.tmatesoft.svn.core.internal.wc.admin.SVNEntry;
import org.tmatesoft.svn.core.internal.wc.admin.SVNWCAccess;
@@ -634,4 +633,18 @@ public class SvnUtil {
}
}
}
public static boolean remoteFolderIsEmpty(final SvnVcs vcs, final String url) throws SVNException {
final SVNRepository repository;
repository = vcs.createRepository(url);
final Ref<Boolean> result = new Ref<Boolean>(true);
repository.getDir("", -1, null, new ISVNDirEntryHandler() {
public void handleDirEntry(final SVNDirEntry dirEntry) throws SVNException {
if (dirEntry != null) {
result.set(false);
}
}
});
return result.get();
}
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
@@ -31,10 +32,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.idea.svn.SvnBundle;
import org.jetbrains.idea.svn.SvnStatusUtil;
import org.jetbrains.idea.svn.SvnVcs;
import org.jetbrains.idea.svn.SvnWorkingCopyFormatHolder;
import org.jetbrains.idea.svn.*;
import org.jetbrains.idea.svn.checkout.SvnCheckoutProvider;
import org.jetbrains.idea.svn.dialogs.ShareDialog;
import org.tmatesoft.svn.core.SVNCommitInfo;
@@ -106,9 +104,23 @@ public class ShareProjectAction extends BasicAction {
final Ref<Boolean> actionStarted = new Ref<Boolean>(Boolean.TRUE);
final SVNException[] error = new SVNException[1];
final ShareDialog.ShareTarget shareTarget = shareDialog.getShareTarget();
final ProgressManager progressManager = ProgressManager.getInstance();
if (ShareDialog.ShareTarget.useSelected.equals(shareTarget)) {
final boolean folderEmpty = checkRemoteFolder(project, activeVcs, parent, progressManager);
if (! folderEmpty) {
final int promptAnswer =
Messages.showYesNoDialog(project, "Remote folder \"" + parent + "\" is not empty.\nDo you want to continue sharing?",
"Share directory", Messages.getWarningIcon());
if (DialogWrapper.OK_EXIT_CODE != promptAnswer) return false;
}
}
ExclusiveBackgroundVcsAction.run(project, new Runnable() {
public void run() {
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
progressManager.runProcessWithProgressSynchronously(new Runnable() {
public void run() {
try {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
@@ -123,7 +135,6 @@ public class ShareProjectAction extends BasicAction {
final SVNURL checkoutUrl;
final SVNRevision revision;
final ShareDialog.ShareTarget shareTarget = shareDialog.getShareTarget();
if (ShareDialog.ShareTarget.useSelected.equals(shareTarget)) {
checkoutUrl = parenUrl;
revision = SVNRevision.HEAD;
@@ -174,6 +185,30 @@ public class ShareProjectAction extends BasicAction {
return false;
}
private static boolean checkRemoteFolder(Project project,
final SvnVcs activeVcs,
final String parent,
ProgressManager progressManager) throws VcsException {
final SVNException[] exc = new SVNException[1];
final boolean[] folderEmpty = new boolean[1];
progressManager.runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
try {
folderEmpty[0] = SvnUtil.remoteFolderIsEmpty(activeVcs, parent);
}
catch (SVNException e) {
exc[0] = e;
}
}
}, "Check remote folder contents", false, project);
if (exc[0] != null) {
throw new VcsException(exc[0]);
}
return folderEmpty[0];
}
private static Pair<SVNRevision, SVNURL> createRemoteFolder(final SvnVcs vcs, final SVNURL parent, final String folderName) throws SVNException {
SVNURL url = parent.appendPath(folderName, false);
final String urlText = url.toString();