|
25 | 25 | import jenkins.plugins.git.AbstractGitSCMSource;
|
26 | 26 | import jenkins.plugins.git.GitSCMSourceDefaults;
|
27 | 27 | import jenkins.plugins.git.MergeWithGitSCMExtension;
|
| 28 | +import jenkins.plugins.git.traits.RefSpecsSCMSourceTrait; |
28 | 29 | import jenkins.scm.api.SCMHead;
|
29 | 30 | import jenkins.scm.api.SCMHeadOrigin;
|
30 | 31 | import jenkins.scm.api.SCMRevision;
|
@@ -454,6 +455,76 @@ public void given__server_branch_rev_anon__when__build__then__scmBuilt() throws
|
454 | 455 | assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
|
455 | 456 | }
|
456 | 457 |
|
| 458 | + @Test |
| 459 | + public void given__server_branch_rev_anon_with_extra_refSpec_when__build__then__scmBuilt() throws Exception { |
| 460 | + source.setServerUrl("https://bitbucket.test"); |
| 461 | + BranchSCMHead head = new BranchSCMHead("test-branch"); |
| 462 | + AbstractGitSCMSource.SCMRevisionImpl revision = |
| 463 | + new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); |
| 464 | + BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source, |
| 465 | + head, revision, null); |
| 466 | + instance.withTrait(new RefSpecsSCMSourceTrait("+refs/heads/*:refs/remotes/@{remote}/*")); |
| 467 | + assertThat(instance.credentialsId(), is(nullValue())); |
| 468 | + assertThat(instance.head(), is((SCMHead) head)); |
| 469 | + assertThat(instance.revision(), is((SCMRevision) revision)); |
| 470 | + assertThat(instance.scmSource(), is(source)); |
| 471 | + assertThat("expecting dummy value until clone links provided or withBitbucketRemote called", |
| 472 | + instance.remote(), is("https://bitbucket.test")); |
| 473 | + assertThat(instance.browser(), instanceOf(BitbucketWeb.class)); |
| 474 | + assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo")); |
| 475 | + |
| 476 | + instance.withCloneLinks( |
| 477 | + List.of( |
| 478 | + new BitbucketHref("http", "https://bitbucket.test/scm/tester/test-repo.git"), |
| 479 | + new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git") |
| 480 | + ), |
| 481 | + List.of() |
| 482 | + ); |
| 483 | + assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git")); |
| 484 | + assertThat(instance.refSpecs(), hasSize(2)); |
| 485 | + assertThat(instance.refSpecs(), contains( |
| 486 | + "+refs/heads/*:refs/remotes/@{remote}/*", |
| 487 | + "+refs/heads/test-branch:refs/remotes/@{remote}/test-branch" |
| 488 | + )); |
| 489 | + |
| 490 | + GitSCM actual = instance.build(); |
| 491 | + assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class)); |
| 492 | + assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo")); |
| 493 | + assertThat(actual.getGitTool(), nullValue()); |
| 494 | + assertThat(actual.getUserRemoteConfigs(), hasSize(1)); |
| 495 | + UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); |
| 496 | + assertThat(config.getName(), is("origin")); |
| 497 | + assertThat(config.getRefspec(), is("+refs/heads/*:refs/remotes/origin/* +refs/heads/test-branch:refs/remotes/origin/test-branch")); |
| 498 | + assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git")); |
| 499 | + assertThat(config.getCredentialsId(), is(nullValue())); |
| 500 | + RemoteConfig origin = actual.getRepositoryByName("origin"); |
| 501 | + assertThat(origin, notNullValue()); |
| 502 | + assertThat(origin.getURIs(), hasSize(1)); |
| 503 | + assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git")); |
| 504 | + assertThat(origin.getFetchRefSpecs(), hasSize(2)); |
| 505 | + assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/*")); |
| 506 | + assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/*")); |
| 507 | + assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); |
| 508 | + assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(true)); |
| 509 | + assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch")); |
| 510 | + assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch")); |
| 511 | + assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true)); |
| 512 | + assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false)); |
| 513 | + assertThat(actual.getExtensions(), containsInAnyOrder( |
| 514 | + instanceOf(GitSCMSourceDefaults.class), |
| 515 | + instanceOf(BuildChooserSetting.class) |
| 516 | + )); |
| 517 | + BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); |
| 518 | + assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class)); |
| 519 | + AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser = |
| 520 | + (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser(); |
| 521 | + Collection<Revision> revisions = revChooser |
| 522 | + .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener( |
| 523 | + Logger.getAnonymousLogger(), Level.FINEST), null, null); |
| 524 | + assertThat(revisions, hasSize(1)); |
| 525 | + assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); |
| 526 | + } |
| 527 | + |
457 | 528 | @Test
|
458 | 529 | public void given__server_withMirror_branch_rev_anon__when__build__then__scmBuilt() throws Exception {
|
459 | 530 | source.setServerUrl("https://bitbucket.test");
|
|
0 commit comments