Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RemoteTest.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2015, Kaloyan Raev <kaloyan.r@zend.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.pgm;
  11. import static org.junit.Assert.assertArrayEquals;
  12. import static org.junit.Assert.assertEquals;
  13. import static org.junit.Assert.assertTrue;
  14. import java.util.List;
  15. import org.eclipse.jgit.api.Git;
  16. import org.eclipse.jgit.lib.CLIRepositoryTestCase;
  17. import org.eclipse.jgit.lib.Repository;
  18. import org.eclipse.jgit.lib.StoredConfig;
  19. import org.eclipse.jgit.transport.RefSpec;
  20. import org.eclipse.jgit.transport.RemoteConfig;
  21. import org.eclipse.jgit.transport.URIish;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. public class RemoteTest extends CLIRepositoryTestCase {
  25. private StoredConfig config;
  26. private RemoteConfig remote;
  27. @Before
  28. @Override
  29. public void setUp() throws Exception {
  30. super.setUp();
  31. // create another repository
  32. Repository remoteRepository = createWorkRepository();
  33. // set it up as a remote to this repository
  34. config = db.getConfig();
  35. remote = new RemoteConfig(config, "test");
  36. remote.addFetchRefSpec(
  37. new RefSpec("+refs/heads/*:refs/remotes/test/*"));
  38. URIish uri = new URIish(
  39. remoteRepository.getDirectory().toURI().toURL());
  40. remote.addURI(uri);
  41. remote.update(config);
  42. config.save();
  43. Git.wrap(remoteRepository).commit().setMessage("initial commit").call();
  44. }
  45. @Test
  46. public void testList() throws Exception {
  47. assertArrayEquals(new String[] { remote.getName(), "" },
  48. execute("git remote"));
  49. }
  50. @Test
  51. public void testVerboseList() throws Exception {
  52. assertArrayEquals(
  53. new String[] {
  54. String.format("%s\t%s (fetch)", remote.getName(),
  55. remote.getURIs().get(0)),
  56. String.format("%s\t%s (push)", remote.getName(),
  57. remote.getURIs().get(0)),
  58. "" },
  59. execute("git remote -v"));
  60. }
  61. @Test
  62. public void testAdd() throws Exception {
  63. assertArrayEquals(new String[] { "" },
  64. execute("git remote add second git://test.com/second"));
  65. List<RemoteConfig> remotes = RemoteConfig.getAllRemoteConfigs(config);
  66. assertEquals(2, remotes.size());
  67. assertEquals("second", remotes.get(0).getName());
  68. assertEquals("test", remotes.get(1).getName());
  69. }
  70. @Test
  71. public void testRemove() throws Exception {
  72. assertArrayEquals(new String[] { "" },
  73. execute("git remote remove test"));
  74. assertTrue(RemoteConfig.getAllRemoteConfigs(config).isEmpty());
  75. }
  76. @Test
  77. public void testSetUrl() throws Exception {
  78. assertArrayEquals(new String[] { "" },
  79. execute("git remote set-url test git://test.com/test"));
  80. RemoteConfig result = new RemoteConfig(config, "test");
  81. assertEquals("test", result.getName());
  82. assertArrayEquals(new URIish[] { new URIish("git://test.com/test") },
  83. result.getURIs().toArray());
  84. assertTrue(result.getPushURIs().isEmpty());
  85. }
  86. @Test
  87. public void testSetUrlPush() throws Exception {
  88. assertArrayEquals(new String[] { "" },
  89. execute("git remote set-url --push test git://test.com/test"));
  90. RemoteConfig result = new RemoteConfig(config, "test");
  91. assertEquals("test", result.getName());
  92. assertEquals(remote.getURIs(), result.getURIs());
  93. assertArrayEquals(new URIish[] { new URIish("git://test.com/test") },
  94. result.getPushURIs().toArray());
  95. }
  96. @Test
  97. public void testUpdate() throws Exception {
  98. assertArrayEquals(new String[] {
  99. "From " + remote.getURIs().get(0).toString(),
  100. " * [new branch] master -> test/master", "", "" },
  101. execute("git remote update test"));
  102. }
  103. }