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.

RemoteAddCommandTest.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.api;
  11. import static org.junit.Assert.assertArrayEquals;
  12. import static org.junit.Assert.assertEquals;
  13. import org.eclipse.jgit.lib.Repository;
  14. import org.eclipse.jgit.transport.RemoteConfig;
  15. import org.eclipse.jgit.transport.URIish;
  16. import org.junit.Test;
  17. public class RemoteAddCommandTest extends AbstractRemoteCommandTest {
  18. @Test
  19. public void testAdd() throws Exception {
  20. // create another repository
  21. Repository remoteRepository = createWorkRepository();
  22. URIish uri = new URIish(
  23. remoteRepository.getDirectory().toURI().toURL());
  24. // execute the command to add a new remote
  25. RemoteAddCommand cmd = Git.wrap(db).remoteAdd();
  26. cmd.setName(REMOTE_NAME);
  27. cmd.setUri(uri);
  28. RemoteConfig remote = cmd.call();
  29. // assert that the added remote represents the remote repository
  30. assertEquals(REMOTE_NAME, remote.getName());
  31. assertArrayEquals(new URIish[] { uri }, remote.getURIs().toArray());
  32. assertEquals(1, remote.getFetchRefSpecs().size());
  33. assertEquals(
  34. String.format("+refs/heads/*:refs/remotes/%s/*", REMOTE_NAME),
  35. remote.getFetchRefSpecs().get(0).toString());
  36. // assert that the added remote is available in the git configuration
  37. assertRemoteConfigEquals(remote,
  38. new RemoteConfig(db.getConfig(), REMOTE_NAME));
  39. }
  40. }