aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorAdrian Goerler <adrian.goerler@sap.com>2011-07-06 23:10:44 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2011-07-06 23:10:53 +0200
commit172a9f05216394f243805844b446cc357dd6b943 (patch)
tree9976ca1edd329cbb9903c8bbbad02e6d8d149e7a /org.eclipse.jgit.test/tst/org/eclipse/jgit
parent7e1b2466e3928f3b2863912ef83b316ed39082db (diff)
downloadjgit-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.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java27
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java14
2 files changed, 41 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
index ca52607669..e43ce3431f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
@@ -44,6 +44,8 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -51,6 +53,7 @@ import java.util.Collections;
import java.util.List;
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
+import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
@@ -209,6 +212,30 @@ public class CloneCommandTest extends RepositoryTestCase {
return sb.toString();
}
+ @Test
+ public void testCloneRepositoryWhenDestinationDirectoryExistsAndIsNotEmpty()
+ throws IOException {
+ String dirName = "testCloneTargetDirectoryNotEmpty";
+ File directory = createTempDirectory(dirName);
+ CloneCommand command = Git.cloneRepository();
+ command.setDirectory(directory);
+ command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+ Git git2 = command.call();
+ assertNotNull(git2);
+ // clone again
+ command = Git.cloneRepository();
+ command.setDirectory(directory);
+ command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+ try {
+ git2 = command.call();
+ // we shouldn't get here
+ fail("destination directory already exists and is not an empty folder, cloning should fail");
+ } catch (JGitInternalException e) {
+ assertTrue(e.getMessage().contains("not an empty directory"));
+ assertTrue(e.getMessage().contains(dirName));
+ }
+ }
+
public static File createTempDirectory(String name) throws IOException {
final File temp;
temp = File.createTempFile(name, Long.toString(System.nanoTime()));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
index 7f47295c3f..797aad4efb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
@@ -73,6 +73,20 @@ public class InitCommandTest extends RepositoryTestCase {
}
@Test
+ public void testInitNonEmptyRepository() throws IOException {
+ File directory = createTempDirectory("testInitRepository2");
+ File someFile = new File(directory, "someFile");
+ someFile.createNewFile();
+ assertTrue(someFile.exists());
+ assertTrue(directory.listFiles().length > 0);
+ InitCommand command = new InitCommand();
+ command.setDirectory(directory);
+ Repository repository = command.call().getRepository();
+ addRepoToClose(repository);
+ assertNotNull(repository);
+ }
+
+ @Test
public void testInitBareRepository() throws IOException {
File directory = createTempDirectory("testInitBareRepository");
InitCommand command = new InitCommand();