Previous behavior was to not allow selecting empty directory. While it seems to be sensible to use empty dir as destination and it's just a little bit more complex, this feature is added. Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx> --- .../src/org/spearce/egit/ui/UIText.java | 2 +- .../ui/internal/clone/CloneDestinationPage.java | 20 ++++++++++++++------ .../egit/ui/internal/clone/GitCloneWizard.java | 3 ++- .../src/org/spearce/egit/ui/uitext.properties | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java index 9150832..189b769 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java @@ -170,7 +170,7 @@ public class UIText extends NLS { public static String CloneDestinationPage_browseButton; /** */ - public static String CloneDestinationPage_errorExists; + public static String CloneDestinationPage_errorNotEmptyDir; /** */ public static String Decorator_failedLazyLoading; diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java index a445cf5..97f166a 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java @@ -221,17 +221,17 @@ class CloneDestinationPage extends WizardPage { setPageComplete(false); return; } - final File dstFile = new File(dstpath); - if (dstFile.exists()) { - setErrorMessage(NLS.bind(UIText.CloneDestinationPage_errorExists, - dstFile.getName())); + final File absoluteFile = new File(dstpath).getAbsoluteFile(); + if (!isEmptyDir(absoluteFile)) { + setErrorMessage(NLS.bind(UIText.CloneDestinationPage_errorNotEmptyDir, + absoluteFile.getPath())); setPageComplete(false); return; } - final File absoluteFile = dstFile.getAbsoluteFile(); + if (!canCreateSubdir(absoluteFile.getParentFile())) { setErrorMessage(NLS.bind(UIText.GitCloneWizard_errorCannotCreate, - dstFile.getPath())); + absoluteFile.getPath())); setPageComplete(false); return; } @@ -252,6 +252,14 @@ class CloneDestinationPage extends WizardPage { setPageComplete(true); } + private static boolean isEmptyDir(final File dir) { + if (!dir.exists()) + return true; + if (!dir.isDirectory()) + return false; + return dir.listFiles().length == 0; + } + // this is actually just an optimistic heuristic - should be named // isThereHopeThatCanCreateSubdir() as probably there is no 100% reliable // way to check that in Java for Windows diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/GitCloneWizard.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/GitCloneWizard.java index efcf57f..10b2cd4 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/GitCloneWizard.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/GitCloneWizard.java @@ -66,7 +66,8 @@ public class GitCloneWizard extends Wizard implements IImportWizard { final String branch = cloneDestination.getInitialBranch(); final String remoteName = cloneDestination.getRemote(); - if (!workdir.mkdirs()) { + workdir.mkdirs(); + if (!workdir.isDirectory()) { final String errorMessage = NLS.bind( UIText.GitCloneWizard_errorCannotCreate, workdir.getPath()); ErrorDialog.openError(getShell(), getWindowTitle(), diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties index 420b610..f46e183 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties @@ -73,7 +73,7 @@ CloneDestinationPage_promptInitialBranch=Initial branch CloneDestinationPage_promptRemoteName=Remote name CloneDestinationPage_fieldRequired={0} is required. CloneDestinationPage_browseButton=Browse -CloneDestinationPage_errorExists={0} already exists. +CloneDestinationPage_errorNotEmptyDir={0} is not an empty directory. Decorator_failedLazyLoading=Resource decorator failed to load tree contents on demand. QuickDiff_failedLoading=Quick diff failed to obtain file data. -- 1.5.6.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html