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.

FetchTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2013, Chris Aniszczyk <zx@twitter.com> and others. 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.assertEquals;
  12. import org.eclipse.jgit.api.Git;
  13. import org.eclipse.jgit.lib.CLIRepositoryTestCase;
  14. import org.eclipse.jgit.lib.Repository;
  15. import org.eclipse.jgit.lib.StoredConfig;
  16. import org.eclipse.jgit.transport.RemoteConfig;
  17. import org.eclipse.jgit.transport.URIish;
  18. import org.junit.Before;
  19. import org.junit.Test;
  20. public class FetchTest extends CLIRepositoryTestCase {
  21. private Git git;
  22. private Git remoteGit;
  23. @Override
  24. @Before
  25. public void setUp() throws Exception {
  26. super.setUp();
  27. git = new Git(db);
  28. git.commit().setMessage("initial commit").call();
  29. Repository remoteRepository = createWorkRepository();
  30. remoteGit = new Git(remoteRepository);
  31. // setup the first repository to fetch from the second repository
  32. final StoredConfig config = db.getConfig();
  33. RemoteConfig remoteConfig = new RemoteConfig(config, "test");
  34. URIish uri = new URIish(remoteRepository.getDirectory().toURI().toURL());
  35. remoteConfig.addURI(uri);
  36. remoteConfig.update(config);
  37. config.save();
  38. remoteGit.commit().setMessage("initial commit").call();
  39. remoteGit.tag().setName("tag").call();
  40. remoteGit.checkout().setName("other").setCreateBranch(true).call();
  41. remoteGit.commit().setMessage("commit2").call();
  42. remoteGit.tag().setName("foo").call();
  43. }
  44. @Test
  45. public void testFetchDefault() throws Exception {
  46. String[] result = execute("git fetch test refs/heads/master:refs/remotes/origin/master");
  47. assertEquals(" * [new branch] master -> origin/master",
  48. result[1]);
  49. assertEquals(" * [new tag] tag -> tag", result[2]);
  50. }
  51. @Test
  52. public void testFetchForceUpdate() throws Exception {
  53. String[] result = execute(
  54. "git fetch test refs/heads/master:refs/remotes/origin/master");
  55. assertEquals(" * [new branch] master -> origin/master",
  56. result[1]);
  57. assertEquals(" * [new tag] tag -> tag", result[2]);
  58. remoteGit.commit().setAmend(true).setMessage("amended").call();
  59. result = execute(
  60. "git fetch -f test refs/heads/master:refs/remotes/origin/master");
  61. assertEquals("", result[0]);
  62. }
  63. @Test
  64. public void testFetchNoTags() throws Exception {
  65. String[] result = execute("git fetch --no-tags test refs/heads/master:refs/remotes/origin/master");
  66. assertEquals(" * [new branch] master -> origin/master",
  67. result[1]);
  68. assertEquals("", result[2]);
  69. }
  70. @Test
  71. public void testFetchAllTags() throws Exception {
  72. String[] result = execute("git fetch --tags test refs/heads/master:refs/remotes/origin/master");
  73. assertEquals(" * [new branch] master -> origin/master",
  74. result[1]);
  75. assertEquals(" * [new tag] foo -> foo", result[2]);
  76. assertEquals(" * [new tag] tag -> tag", result[3]);
  77. }
  78. }