diff options
author | Adrian Goerler <adrian.goerler@sap.com> | 2011-07-06 23:10:44 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2011-07-06 23:10:53 +0200 |
commit | 172a9f05216394f243805844b446cc357dd6b943 (patch) | |
tree | 9976ca1edd329cbb9903c8bbbad02e6d8d149e7a /org.eclipse.jgit/src/org/eclipse | |
parent | 7e1b2466e3928f3b2863912ef83b316ed39082db (diff) | |
download | jgit-172a9f05216394f243805844b446cc357dd6b943.tar.gz jgit-172a9f05216394f243805844b446cc357dd6b943.zip |
Cloning should fail when destination directory exists and is not empty
When trying to clone into a folder that already contains a cloned
repository native git will fail with a message "fatal: destination path
'folder' already exists and is not an empty directory.". Now JGit will
also fail in this situation throwing a JGitInternalException.
The test case was provided by Tomasz Zarna.
Bug: 347852
Change-Id: If9e9919a5f92d13cf038dc470c21ee5967322dac
Also-by: Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
Signed-off-by: Adrian Goerler <adrian.goerler@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java | 1 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java index 7054cf800f..af20477a65 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java @@ -146,6 +146,7 @@ public class JGitText extends TranslationBundle { /***/ public String checkoutConflictWithFile; /***/ public String checkoutConflictWithFiles; /***/ public String classCastNotA; + /***/ public String cloneNonEmptyDirectory; /***/ public String collisionOn; /***/ public String commandWasCalledInTheWrongState; /***/ public String commitAlreadyExists; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index aa8cf6e30a..cfbcbf1b6d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -45,11 +45,13 @@ package org.eclipse.jgit.api; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.Callable; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.dircache.DirCache; @@ -131,6 +133,9 @@ public class CloneCommand implements Callable<Git> { command.setBare(bare); if (directory == null) directory = new File(u.getHumanishName(), Constants.DOT_GIT); + if (directory.exists() && directory.listFiles().length != 0) + throw new JGitInternalException(MessageFormat.format( + JGitText.get().cloneNonEmptyDirectory, directory.getName())); command.setDirectory(directory); return command.call().getRepository(); } |