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.

InitTest.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2016, Rüdiger Herrmann <ruediger.herrmann@gmx.de> 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.pgm;
  11. import static org.junit.Assert.assertArrayEquals;
  12. import static org.junit.Assert.assertEquals;
  13. import java.io.File;
  14. import org.eclipse.jgit.internal.storage.file.FileRepository;
  15. import org.eclipse.jgit.lib.CLIRepositoryTestCase;
  16. import org.eclipse.jgit.lib.Constants;
  17. import org.eclipse.jgit.lib.Repository;
  18. import org.junit.Rule;
  19. import org.junit.Test;
  20. import org.junit.rules.TemporaryFolder;
  21. public class InitTest extends CLIRepositoryTestCase {
  22. @Rule
  23. public final TemporaryFolder tempFolder = new TemporaryFolder();
  24. @Test
  25. public void testInitBare() throws Exception {
  26. File directory = tempFolder.getRoot();
  27. String[] result = execute(
  28. "git init '" + directory.getCanonicalPath() + "' --bare");
  29. String[] expecteds = new String[] {
  30. "Initialized empty Git repository in "
  31. + directory.getCanonicalPath(),
  32. "" };
  33. assertArrayEquals(expecteds, result);
  34. }
  35. @Test
  36. public void testInitDirectory() throws Exception {
  37. File workDirectory = tempFolder.getRoot();
  38. File gitDirectory = new File(workDirectory, Constants.DOT_GIT);
  39. String[] result = execute(
  40. "git init '" + workDirectory.getCanonicalPath() + "'");
  41. String[] expecteds = new String[] {
  42. "Initialized empty Git repository in "
  43. + gitDirectory.getCanonicalPath(),
  44. "" };
  45. assertArrayEquals(expecteds, result);
  46. }
  47. @Test
  48. public void testInitDirectoryInitialBranch() throws Exception {
  49. File workDirectory = tempFolder.getRoot();
  50. File gitDirectory = new File(workDirectory, Constants.DOT_GIT);
  51. String[] result = execute(
  52. "git init -b main '" + workDirectory.getCanonicalPath() + "'");
  53. String[] expecteds = new String[] {
  54. "Initialized empty Git repository in "
  55. + gitDirectory.getCanonicalPath(),
  56. "" };
  57. assertArrayEquals(expecteds, result);
  58. try (Repository repo = new FileRepository(gitDirectory)) {
  59. assertEquals("refs/heads/main", repo.getFullBranch());
  60. }
  61. }
  62. }