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.

InMemoryRepositoryTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2019, Google LLC. 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.internal.storage.dfs;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertTrue;
  13. import java.util.Set;
  14. import org.eclipse.jgit.junit.TestRepository;
  15. import org.eclipse.jgit.lib.ObjectIdRef;
  16. import org.eclipse.jgit.lib.Ref;
  17. import org.eclipse.jgit.lib.Ref.Storage;
  18. import org.eclipse.jgit.revwalk.RevCommit;
  19. import org.eclipse.jgit.revwalk.RevTag;
  20. import org.junit.Test;
  21. public class InMemoryRepositoryTest {
  22. @Test
  23. public void keepUpdateIndexPeelingTag() throws Exception {
  24. InMemoryRepository repo = new InMemoryRepository(
  25. new DfsRepositoryDescription());
  26. try (TestRepository<InMemoryRepository> git = new TestRepository<>(
  27. repo)) {
  28. RevCommit commit = git.branch("master").commit()
  29. .message("first commit").create();
  30. RevTag tag = git.tag("v0.1", commit);
  31. git.update("refs/tags/v0.1", tag);
  32. Ref unpeeledTag = new ObjectIdRef.Unpeeled(Storage.LOOSE,
  33. "refs/tags/v0.1", tag.getId(), 1000);
  34. Ref peeledTag = repo.getRefDatabase().peel(unpeeledTag);
  35. assertTrue(peeledTag instanceof ObjectIdRef.PeeledTag);
  36. assertEquals(1000, peeledTag.getUpdateIndex());
  37. }
  38. }
  39. @Test
  40. public void keepUpdateIndexPeelingNonTag() throws Exception {
  41. InMemoryRepository repo = new InMemoryRepository(
  42. new DfsRepositoryDescription());
  43. try (TestRepository<InMemoryRepository> git = new TestRepository<>(
  44. repo)) {
  45. RevCommit commit = git.branch("master").commit()
  46. .message("first commit").create();
  47. Ref unpeeledRef = new ObjectIdRef.Unpeeled(Storage.LOOSE,
  48. "refs/heads/master", commit.getId(), 1000);
  49. Ref peeledRef = repo.getRefDatabase().peel(unpeeledRef);
  50. assertTrue(peeledRef instanceof ObjectIdRef.PeeledNonTag);
  51. assertEquals(1000, peeledRef.getUpdateIndex());
  52. }
  53. }
  54. @Test
  55. public void sha1ToTip_ref() throws Exception {
  56. InMemoryRepository repo = new InMemoryRepository(
  57. new DfsRepositoryDescription());
  58. try (TestRepository<InMemoryRepository> git = new TestRepository<>(
  59. repo)) {
  60. RevCommit commit = git.branch("master").commit()
  61. .message("first commit").create();
  62. Set<Ref> tipsWithSha1 = repo.getRefDatabase()
  63. .getTipsWithSha1(commit.getId());
  64. assertEquals(1, tipsWithSha1.size());
  65. Ref ref = tipsWithSha1.iterator().next();
  66. assertEquals(ref.getName(), "refs/heads/master");
  67. assertEquals(commit.getId(), ref.getObjectId());
  68. }
  69. }
  70. @Test
  71. public void sha1ToTip_annotatedTag() throws Exception {
  72. InMemoryRepository repo = new InMemoryRepository(
  73. new DfsRepositoryDescription());
  74. try (TestRepository<InMemoryRepository> git = new TestRepository<>(
  75. repo)) {
  76. RevCommit commit = git.commit()
  77. .message("first commit").create();
  78. RevTag tagObj = git.tag("v0.1", commit);
  79. git.update("refs/tags/v0.1", tagObj);
  80. Set<Ref> tipsWithSha1 = repo.getRefDatabase()
  81. .getTipsWithSha1(commit.getId());
  82. assertEquals(1, tipsWithSha1.size());
  83. Ref ref = tipsWithSha1.iterator().next();
  84. assertEquals(ref.getName(), "refs/tags/v0.1");
  85. assertEquals(commit.getId(), ref.getPeeledObjectId());
  86. }
  87. }
  88. @Test
  89. public void sha1ToTip_tag() throws Exception {
  90. InMemoryRepository repo = new InMemoryRepository(
  91. new DfsRepositoryDescription());
  92. try (TestRepository<InMemoryRepository> git = new TestRepository<>(
  93. repo)) {
  94. RevCommit commit = git.commit().message("first commit").create();
  95. git.update("refs/tags/v0.2", commit);
  96. Set<Ref> tipsWithSha1 = repo.getRefDatabase()
  97. .getTipsWithSha1(commit.getId());
  98. assertEquals(1, tipsWithSha1.size());
  99. Ref ref = tipsWithSha1.iterator().next();
  100. assertEquals(ref.getName(), "refs/tags/v0.2");
  101. assertEquals(commit.getId(), ref.getObjectId());
  102. }
  103. }
  104. }