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;
}
@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) {
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;
}
@Test
- public void testInitRepository() {
- try {
- File directory = createTempDirectory("testInitRepository");
- InitCommand command = new InitCommand();
- command.setDirectory(directory);
- Repository repository = command.call().getRepository();
- addRepoToClose(repository);
- assertNotNull(repository);
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ public void testInitRepository() throws IOException {
+ File directory = createTempDirectory("testInitRepository");
+ InitCommand command = new InitCommand();
+ command.setDirectory(directory);
+ Repository repository = command.call().getRepository();
+ addRepoToClose(repository);
+ assertNotNull(repository);
}
@Test
- public void testInitBareRepository() {
- try {
- File directory = createTempDirectory("testInitBareRepository");
- InitCommand command = new InitCommand();
- command.setDirectory(directory);
- command.setBare(true);
- Repository repository = command.call().getRepository();
- addRepoToClose(repository);
- assertNotNull(repository);
- assertTrue(repository.isBare());
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ public void testInitBareRepository() throws IOException {
+ File directory = createTempDirectory("testInitBareRepository");
+ InitCommand command = new InitCommand();
+ command.setDirectory(directory);
+ command.setBare(true);
+ Repository repository = command.call().getRepository();
+ addRepoToClose(repository);
+ assertNotNull(repository);
+ assertTrue(repository.isBare());
}
public static File createTempDirectory(String name) throws IOException {