You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitCloneTaskTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2011, Ketan Padegaonkar <KetanPadegaonkar@gmail.com> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.ant.tasks;
  11. import static org.junit.Assert.assertTrue;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import org.apache.tools.ant.BuildException;
  15. import org.apache.tools.ant.DefaultLogger;
  16. import org.apache.tools.ant.Project;
  17. import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
  18. import org.eclipse.jgit.lib.Repository;
  19. import org.eclipse.jgit.lib.RepositoryCache;
  20. import org.eclipse.jgit.util.FS;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. public class GitCloneTaskTest extends LocalDiskRepositoryTestCase {
  24. private GitCloneTask task;
  25. private Project project;
  26. private File dest;
  27. @Before
  28. public void before() throws IOException {
  29. dest = createTempFile();
  30. FS.getFileStoreAttributes(dest.toPath().getParent());
  31. project = new Project();
  32. project.init();
  33. enableLogging();
  34. project.addTaskDefinition("git-clone", GitCloneTask.class);
  35. task = (GitCloneTask) project.createTask("git-clone");
  36. task.setDest(dest);
  37. }
  38. @Test(expected = BuildException.class)
  39. public void shouldRaiseErrorOnNoUrl() throws Exception {
  40. task.execute();
  41. }
  42. @Test(expected = BuildException.class)
  43. public void shouldRaiseErrorOnEmptyUrl() throws Exception {
  44. task.setUri("");
  45. task.execute();
  46. }
  47. @Test(expected = BuildException.class)
  48. public void shouldRaiseErrorOnBadUrl() throws Exception {
  49. task.setUri("foo://bar");
  50. task.execute();
  51. }
  52. @Test(expected = BuildException.class)
  53. public void shouldRaiseErrorOnBadSourceURL() throws Exception {
  54. task.setUri("http://localhost:9090/does-not-exist.git");
  55. task.execute();
  56. }
  57. @Test
  58. public void shouldCloneAValidGitRepository() throws Exception {
  59. Repository repo = createBareRepository();
  60. File directory = repo.getDirectory();
  61. task.setUri("file://" + directory.getAbsolutePath());
  62. task.execute();
  63. assertTrue(RepositoryCache.FileKey.isGitRepository(new File(dest, ".git"), FS.DETECTED));
  64. }
  65. @Test
  66. public void shouldCreateABareCloneOfAValidGitRepository() throws Exception {
  67. Repository repo = createBareRepository();
  68. File directory = repo.getDirectory();
  69. task.setUri("file://" + directory.getAbsolutePath());
  70. task.setBare(true);
  71. task.execute();
  72. assertTrue(RepositoryCache.FileKey.isGitRepository(dest, FS.DETECTED));
  73. }
  74. private void enableLogging() {
  75. DefaultLogger logger = new DefaultLogger();
  76. logger.setOutputPrintStream(System.out);
  77. logger.setErrorPrintStream(System.err);
  78. logger.setMessageOutputLevel(Project.MSG_INFO);
  79. project.addBuildListener(logger);
  80. }
  81. }