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.

AbstractRemoteCommandTest.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.assertEquals;
  12. import java.io.IOException;
  13. import java.net.URISyntaxException;
  14. import org.eclipse.jgit.junit.RepositoryTestCase;
  15. import org.eclipse.jgit.lib.Constants;
  16. import org.eclipse.jgit.lib.Repository;
  17. import org.eclipse.jgit.lib.StoredConfig;
  18. import org.eclipse.jgit.transport.RefSpec;
  19. import org.eclipse.jgit.transport.RemoteConfig;
  20. import org.eclipse.jgit.transport.URIish;
  21. public class AbstractRemoteCommandTest extends RepositoryTestCase {
  22. protected static final String REMOTE_NAME = "test";
  23. protected RemoteConfig setupRemote()
  24. throws IOException, URISyntaxException {
  25. // create another repository
  26. Repository remoteRepository = createWorkRepository();
  27. // set it up as a remote to this repository
  28. final StoredConfig config = db.getConfig();
  29. RemoteConfig remoteConfig = new RemoteConfig(config, REMOTE_NAME);
  30. RefSpec refSpec = new RefSpec();
  31. refSpec = refSpec.setForceUpdate(true);
  32. refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*",
  33. Constants.R_REMOTES + REMOTE_NAME + "/*");
  34. remoteConfig.addFetchRefSpec(refSpec);
  35. URIish uri = new URIish(
  36. remoteRepository.getDirectory().toURI().toURL());
  37. remoteConfig.addURI(uri);
  38. remoteConfig.update(config);
  39. config.save();
  40. return remoteConfig;
  41. }
  42. protected void assertRemoteConfigEquals(RemoteConfig expected,
  43. RemoteConfig actual) {
  44. assertEquals(expected.getName(), actual.getName());
  45. assertEquals(expected.getURIs(), actual.getURIs());
  46. assertEquals(expected.getPushURIs(), actual.getPushURIs());
  47. assertEquals(expected.getFetchRefSpecs(), actual.getFetchRefSpecs());
  48. assertEquals(expected.getPushRefSpecs(), actual.getPushRefSpecs());
  49. }
  50. }