您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BranchTrackingStatusTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2011, Robin Stocker <robin@nibor.org> 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.lib;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertNull;
  13. import org.eclipse.jgit.junit.RepositoryTestCase;
  14. import org.eclipse.jgit.junit.TestRepository;
  15. import org.eclipse.jgit.revwalk.RevCommit;
  16. import org.eclipse.jgit.revwalk.RevWalk;
  17. import org.junit.Test;
  18. public class BranchTrackingStatusTest extends RepositoryTestCase {
  19. private TestRepository<Repository> util;
  20. protected RevWalk rw;
  21. @Override
  22. public void setUp() throws Exception {
  23. super.setUp();
  24. util = new TestRepository<>(db);
  25. StoredConfig config = util.getRepository().getConfig();
  26. config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master",
  27. ConfigConstants.CONFIG_KEY_REMOTE, "origin");
  28. config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master",
  29. ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master");
  30. config.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin",
  31. "fetch", "+refs/heads/*:refs/remotes/origin/*");
  32. }
  33. @Test
  34. public void shouldWorkInNormalCase() throws Exception {
  35. RevCommit remoteTracking = util.branch("refs/remotes/origin/master")
  36. .commit().create();
  37. util.branch("master").commit().parent(remoteTracking).create();
  38. util.branch("master").commit().create();
  39. BranchTrackingStatus status = BranchTrackingStatus.of(
  40. util.getRepository(), "master");
  41. assertEquals(2, status.getAheadCount());
  42. assertEquals(0, status.getBehindCount());
  43. assertEquals("refs/remotes/origin/master",
  44. status.getRemoteTrackingBranch());
  45. }
  46. @Test
  47. public void shouldWorkWithoutMergeBase() throws Exception {
  48. util.branch("refs/remotes/origin/master").commit().create();
  49. util.branch("master").commit().create();
  50. BranchTrackingStatus status = BranchTrackingStatus.of(util.getRepository(), "master");
  51. assertEquals(1, status.getAheadCount());
  52. assertEquals(1, status.getBehindCount());
  53. }
  54. @Test
  55. public void shouldReturnNullWhenBranchDoesntExist() throws Exception {
  56. BranchTrackingStatus status = BranchTrackingStatus.of(
  57. util.getRepository(), "doesntexist");
  58. assertNull(status);
  59. }
  60. }