|
|
@@ -44,7 +44,6 @@ package org.eclipse.jgit.api; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
@@ -93,139 +92,111 @@ public class CloneCommandTest extends RepositoryTestCase { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCloneRepository() { |
|
|
|
try { |
|
|
|
File directory = createTempDirectory("testCloneRepository"); |
|
|
|
CloneCommand command = Git.cloneRepository(); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" |
|
|
|
+ git.getRepository().getWorkTree().getPath()); |
|
|
|
Git git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
assertNotNull(git2); |
|
|
|
ObjectId id = git2.getRepository().resolve("tag-for-blob"); |
|
|
|
assertNotNull(id); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), |
|
|
|
"refs/heads/test"); |
|
|
|
assertEquals( |
|
|
|
"origin", |
|
|
|
git2.getRepository() |
|
|
|
.getConfig() |
|
|
|
.getString(ConfigConstants.CONFIG_BRANCH_SECTION, |
|
|
|
"test", ConfigConstants.CONFIG_KEY_REMOTE)); |
|
|
|
assertEquals( |
|
|
|
"refs/heads/test", |
|
|
|
git2.getRepository() |
|
|
|
.getConfig() |
|
|
|
.getString(ConfigConstants.CONFIG_BRANCH_SECTION, |
|
|
|
"test", ConfigConstants.CONFIG_KEY_MERGE)); |
|
|
|
assertEquals(2, git2.branchList().setListMode(ListMode.REMOTE) |
|
|
|
.call().size()); |
|
|
|
} catch (Exception e) { |
|
|
|
fail(e.getMessage()); |
|
|
|
} |
|
|
|
public void testCloneRepository() throws IOException { |
|
|
|
File directory = createTempDirectory("testCloneRepository"); |
|
|
|
CloneCommand command = Git.cloneRepository(); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath()); |
|
|
|
Git git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
assertNotNull(git2); |
|
|
|
ObjectId id = git2.getRepository().resolve("tag-for-blob"); |
|
|
|
assertNotNull(id); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test"); |
|
|
|
assertEquals( |
|
|
|
"origin", |
|
|
|
git2.getRepository() |
|
|
|
.getConfig() |
|
|
|
.getString(ConfigConstants.CONFIG_BRANCH_SECTION, |
|
|
|
"test", ConfigConstants.CONFIG_KEY_REMOTE)); |
|
|
|
assertEquals( |
|
|
|
"refs/heads/test", |
|
|
|
git2.getRepository() |
|
|
|
.getConfig() |
|
|
|
.getString(ConfigConstants.CONFIG_BRANCH_SECTION, |
|
|
|
"test", ConfigConstants.CONFIG_KEY_MERGE)); |
|
|
|
assertEquals(2, git2.branchList().setListMode(ListMode.REMOTE).call() |
|
|
|
.size()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCloneRepositoryWithBranch() { |
|
|
|
try { |
|
|
|
File directory = createTempDirectory("testCloneRepositoryWithBranch"); |
|
|
|
CloneCommand command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" |
|
|
|
+ git.getRepository().getWorkTree().getPath()); |
|
|
|
Git git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
|
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), |
|
|
|
"refs/heads/master"); |
|
|
|
assertEquals( |
|
|
|
"refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test", |
|
|
|
allRefNames(git2.branchList().setListMode(ListMode.ALL) |
|
|
|
.call())); |
|
|
|
|
|
|
|
// Same thing, but now without checkout |
|
|
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); |
|
|
|
command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" |
|
|
|
+ git.getRepository().getWorkTree().getPath()); |
|
|
|
command.setNoCheckout(true); |
|
|
|
git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
|
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), |
|
|
|
"refs/heads/master"); |
|
|
|
assertEquals( |
|
|
|
"refs/remotes/origin/master, refs/remotes/origin/test", |
|
|
|
allRefNames(git2.branchList().setListMode(ListMode.ALL) |
|
|
|
.call())); |
|
|
|
|
|
|
|
// Same thing, but now test with bare repo |
|
|
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); |
|
|
|
command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" |
|
|
|
+ git.getRepository().getWorkTree().getPath()); |
|
|
|
command.setBare(true); |
|
|
|
git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
|
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), |
|
|
|
"refs/heads/master"); |
|
|
|
assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2 |
|
|
|
.branchList().setListMode(ListMode.ALL).call())); |
|
|
|
} catch (Exception e) { |
|
|
|
fail(e.getMessage()); |
|
|
|
} |
|
|
|
public void testCloneRepositoryWithBranch() throws IOException { |
|
|
|
File directory = createTempDirectory("testCloneRepositoryWithBranch"); |
|
|
|
CloneCommand command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath()); |
|
|
|
Git git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
|
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); |
|
|
|
assertEquals( |
|
|
|
"refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test", |
|
|
|
allRefNames(git2.branchList().setListMode(ListMode.ALL).call())); |
|
|
|
|
|
|
|
// Same thing, but now without checkout |
|
|
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); |
|
|
|
command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath()); |
|
|
|
command.setNoCheckout(true); |
|
|
|
git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
|
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); |
|
|
|
assertEquals("refs/remotes/origin/master, refs/remotes/origin/test", |
|
|
|
allRefNames(git2.branchList().setListMode(ListMode.ALL).call())); |
|
|
|
|
|
|
|
// Same thing, but now test with bare repo |
|
|
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); |
|
|
|
command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath()); |
|
|
|
command.setBare(true); |
|
|
|
git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
|
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); |
|
|
|
assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2 |
|
|
|
.branchList().setListMode(ListMode.ALL).call())); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCloneRepositoryOnlyOneBranch() { |
|
|
|
try { |
|
|
|
File directory = createTempDirectory("testCloneRepositoryWithBranch"); |
|
|
|
CloneCommand command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setBranchesToClone(Collections |
|
|
|
.singletonList("refs/heads/master")); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" |
|
|
|
+ git.getRepository().getWorkTree().getPath()); |
|
|
|
Git git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), |
|
|
|
"refs/heads/master"); |
|
|
|
assertEquals("refs/remotes/origin/master", |
|
|
|
allRefNames(git2.branchList() |
|
|
|
.setListMode(ListMode.REMOTE).call())); |
|
|
|
|
|
|
|
// Same thing, but now test with bare repo |
|
|
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); |
|
|
|
command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setBranchesToClone(Collections |
|
|
|
.singletonList("refs/heads/master")); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" |
|
|
|
+ git.getRepository().getWorkTree().getPath()); |
|
|
|
command.setBare(true); |
|
|
|
git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), |
|
|
|
"refs/heads/master"); |
|
|
|
assertEquals("refs/heads/master", allRefNames(git2 |
|
|
|
.branchList().setListMode(ListMode.ALL).call())); |
|
|
|
} catch (Exception e) { |
|
|
|
fail(e.getMessage()); |
|
|
|
} |
|
|
|
public void testCloneRepositoryOnlyOneBranch() throws IOException { |
|
|
|
File directory = createTempDirectory("testCloneRepositoryWithBranch"); |
|
|
|
CloneCommand command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setBranchesToClone(Collections |
|
|
|
.singletonList("refs/heads/master")); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath()); |
|
|
|
Git git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); |
|
|
|
assertEquals("refs/remotes/origin/master", allRefNames(git2 |
|
|
|
.branchList().setListMode(ListMode.REMOTE).call())); |
|
|
|
|
|
|
|
// Same thing, but now test with bare repo |
|
|
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); |
|
|
|
command = Git.cloneRepository(); |
|
|
|
command.setBranch("refs/heads/master"); |
|
|
|
command.setBranchesToClone(Collections |
|
|
|
.singletonList("refs/heads/master")); |
|
|
|
command.setDirectory(directory); |
|
|
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath()); |
|
|
|
command.setBare(true); |
|
|
|
git2 = command.call(); |
|
|
|
addRepoToClose(git2.getRepository()); |
|
|
|
assertNotNull(git2); |
|
|
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); |
|
|
|
assertEquals("refs/heads/master", allRefNames(git2.branchList() |
|
|
|
.setListMode(ListMode.ALL).call())); |
|
|
|
} |
|
|
|
|
|
|
|
public static String allRefNames(List<Ref> refs) { |