hudson.plugins.git.Revision Java Examples
The following examples show how to use
hudson.plugins.git.Revision.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommitStatusUpdater.java From gitlab-plugin with GNU General Public License v2.0 | 8 votes |
private static String getBuildRevision(Run<?, ?> build) { GitLabWebHookCause cause = build.getCause(GitLabWebHookCause.class); if (cause != null) { return cause.getData().getLastCommit(); } BuildData action = build.getAction(BuildData.class); if (action == null) { throw new IllegalStateException("No (git-plugin) BuildData associated to current build"); } Revision lastBuiltRevision = action.getLastBuiltRevision(); if (lastBuiltRevision == null) { throw new IllegalStateException("Last build has no associated commit"); } return action.getLastBuild(lastBuiltRevision.getSha1()).getMarked().getSha1String(); }
Example #2
Source File: GitLabSCMMergeRequestHead.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 6 votes |
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException { listener.getLogger().println("Merging " + targetBranch.getName() + " commit " + targetBranch.getRevision().getHash() + " into merge-request head commit " + rev.getSha1String()); checkout(scm, build, git, listener, rev); try { git.setAuthor("Jenkins", /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */"nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(ObjectId.fromString(targetBranch.getRevision().getHash())); for (GitSCMExtension ext : scm.getExtensions()) { // By default we do a regular merge, allowing it to fast-forward. ext.decorateMergeCommand(scm, build, git, listener, cmd); } cmd.execute(); } catch (GitException e) { // Try to revert merge conflict markers. checkout(scm, build, git, listener, rev); throw e; } build.addAction(new MergeRecord(targetBranch.getRefSpec().destinationRef(targetBranch.getName()), targetBranch.getRevision().getHash())); // does not seem to be used, but just in case ObjectId mergeRev = git.revParse(Constants.HEAD); listener.getLogger().println("Merge succeeded, producing " + mergeRev.name()); return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked }
Example #3
Source File: BuildUtilTest.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
private BuildData createBuildData(String sha) { BuildData buildData = mock(BuildData.class); Revision revision = mock(Revision.class); when(revision.getSha1String()).thenReturn(sha); when(buildData.getLastBuiltRevision()).thenReturn(revision); Build gitBuild = mock(Build.class); when(gitBuild.getMarked()).thenReturn(revision); when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild); when(gitBuild.getRevision()).thenReturn(revision); when(gitBuild.isFor(sha)).thenReturn(true); buildData.lastBuild = gitBuild; return buildData; }
Example #4
Source File: HistoryAggregatedFlakyTestResultAction.java From flaky-test-handler-plugin with Apache License 2.0 | 6 votes |
/** * Construct a SingleTestFlakyStatsWithRevision object with {@link SingleTestFlakyStats} and * build information. * * @param stats Embedded {@link SingleTestFlakyStats} object * @param build The {@link hudson.model.Run} object to get SCM information from. */ public SingleTestFlakyStatsWithRevision(SingleTestFlakyStats stats, Run build) { this.stats = stats; revision = Integer.toString(build.getNumber()); Job job = build.getParent(); SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job); if (s != null) { ArrayList<SCM> scms = new ArrayList<>(s.getSCMs()); SCM scm = scms.size() > 0 ? scms.get(0) : null; if (scm != null && "hudson.plugins.git.GitSCM".equalsIgnoreCase(scm.getType())) { GitSCM gitSCM = (GitSCM) scm; BuildData buildData = gitSCM.getBuildData(build); if (buildData != null) { Revision gitRevision = buildData.getLastBuiltRevision(); if (gitRevision != null) { revision = gitRevision.getSha1String(); } } } } }
Example #5
Source File: DeflakeGitBuildChooser.java From flaky-test-handler-plugin with Apache License 2.0 | 6 votes |
/** * Get failing build revision if this is a deflake build, otherwise use the default build chooser */ @Override public Collection<Revision> getCandidateRevisions(boolean isPollCall, String singleBranch, GitClient git, TaskListener listener, BuildData buildData, BuildChooserContext context) throws GitException, IOException, InterruptedException { // Not sure why it cannot be inferred and we have to put cast here DeflakeCause cause = (DeflakeCause) context.getBuild().getCause(DeflakeCause.class); if (cause != null) { BuildData gitBuildData = gitSCM.getBuildData(cause.getUpstreamRun(), true); Revision revision = gitBuildData.getLastBuiltRevision(); if (revision != null) { return Collections.singletonList(revision); } } // If it is not a deflake run, then use the default git checkout strategy defaultBuildChooser.gitSCM = this.gitSCM; return defaultBuildChooser.getCandidateRevisions(isPollCall, singleBranch, git, listener, buildData, context); }
Example #6
Source File: GitLabSCMMergeRequestHead.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
private void checkout(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision rev) throws InterruptedException, IOException, GitException { CheckoutCommand checkoutCommand = git.checkout().ref(rev.getSha1String()); for (GitSCMExtension ext : scm.getExtensions()) { ext.decorateCheckoutCommand(scm, build, git, listener, checkoutCommand); } checkoutCommand.execute(); }
Example #7
Source File: LegacyCompatibleGitAPIImplTest.java From git-client-plugin with MIT License | 5 votes |
@Test @Deprecated public void testShowRevisionTrackedFile() throws Exception { File trackedFile = commitTrackedFile(); ObjectId head = git.getHeadRev(repo.getPath(), "master"); List<String> revisions = git.showRevision(new Revision(head)); assertEquals("commit " + head.name(), revisions.get(0)); }
Example #8
Source File: LegacyCompatibleGitAPIImplTest.java From git-client-plugin with MIT License | 5 votes |
@Test @Deprecated public void testShowRevisionThrowsGitException() throws Exception { File trackedFile = commitTrackedFile(); assertThrows(GitException.class, () -> { git.showRevision(new Revision(gitClientCommit)); }); }
Example #9
Source File: GitClientTest.java From git-client-plugin with MIT License | 5 votes |
public void testSetupSubmoduleUrls() throws Exception { System.out.println("setupSubmoduleUrls"); Revision rev = null; TaskListener listener = null; GitClient instance = gitClient; instance.setupSubmoduleUrls(rev, listener); fail("The test case is a prototype."); }
Example #10
Source File: GitLabCommitStatusPublisherTest.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private AbstractBuild mockBuild(String gitLabConnection, Result result, String... remoteUrls) { AbstractBuild build = mock(AbstractBuild.class); List<BuildData> buildDatas = new ArrayList<>(); BuildData buildData = mock(BuildData.class); Revision revision = mock(Revision.class); when(revision.getSha1String()).thenReturn(SHA1); when(buildData.getLastBuiltRevision()).thenReturn(revision); when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls))); Build gitBuild = mock(Build.class); when(gitBuild.getMarked()).thenReturn(revision); when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild); buildDatas.add(buildData); when(build.getActions(BuildData.class)).thenReturn(buildDatas); when(build.getAction(BuildData.class)).thenReturn(buildData); when(build.getResult()).thenReturn(result); when(build.getUrl()).thenReturn(BUILD_URL); AbstractProject<?, ?> project = mock(AbstractProject.class); when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection)); when(build.getProject()).thenReturn(project); EnvVars environment = mock(EnvVars.class); when(environment.expand(anyString())).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return (String) invocation.getArguments()[0]; } }); try { when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment); } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } return build; }
Example #11
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__server_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git"); PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1, new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe" ); source.setCredentialsId("user-key"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.test/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 " + "+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-key")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(2)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(MergeWithGitSCMExtension.class), instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser, notNullValue()); assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class)); AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser = (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener( Logger.getAnonymousLogger(), Level.FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class); assertThat(merge, notNullValue()); assertThat(merge.getBaseName(), is("remotes/origin/test-branch")); assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef")); }
Example #12
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId(null); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git")); assertThat(config.getCredentialsId(), is(nullValue())); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #13
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userpass__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId("user-pass"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-pass")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-pass")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #14
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId("user-key"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-key")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #15
Source File: RemoteGitImpl.java From git-client-plugin with MIT License | 4 votes |
/** {@inheritDoc} */ public void setupSubmoduleUrls(Revision rev, TaskListener listener) throws GitException, InterruptedException { proxy.setupSubmoduleUrls(rev, listener); }
Example #16
Source File: RemoteGitImpl.java From git-client-plugin with MIT License | 4 votes |
/** {@inheritDoc} */ public List<String> showRevision(Revision r) throws GitException, InterruptedException { return getGitAPI().showRevision(r); }
Example #17
Source File: LegacyCompatibleGitAPIImpl.java From git-client-plugin with MIT License | 4 votes |
/** {@inheritDoc} */ @Deprecated public List<String> showRevision(Revision r) throws GitException, InterruptedException { return showRevision(null, r.getSha1()); }
Example #18
Source File: CliGitAPIImpl.java From git-client-plugin with MIT License | 4 votes |
/** * {@inheritDoc} * * Set up submodule URLs so that they correspond to the remote pertaining to * the revision that has been checked out. */ @Override public void setupSubmoduleUrls( Revision rev, TaskListener listener ) throws GitException, InterruptedException { String remote = null; // try to locate the remote repository from where this commit came from // (by using the heuristics that the branch name, if available, contains the remote name) // if we can figure out the remote, the other setupSubmoduleUrls method // look at its URL, and if it's a non-bare repository, we attempt to retrieve modules // from this checked out copy. // // the idea is that you have something like tree-structured repositories: at the root you have corporate central repositories that you // ultimately push to, which all .gitmodules point to, then you have intermediate team local repository, // which is assumed to be a non-bare repository (say, a checked out copy on a shared server accessed via SSH) // // the abovementioned behaviour of the Git plugin makes it pick up submodules from this team local repository, // not the corporate central. // // (Kohsuke: I have a bit of hesitation/doubt about such a behaviour change triggered by seemingly indirect // evidence of whether the upstream is bare or not (not to mention the fact that you can't reliably // figure out if the repository is bare or not just from the URL), but that's what apparently has been implemented // and we care about the backward compatibility.) // // note that "figuring out which remote repository the commit came from" isn't a well-defined // question, and this is really a heuristics. The user might be telling us to build a specific SHA1. // or maybe someone pushed directly to the workspace and so it may not correspond to any remote branch. // so if we fail to figure this out, we back out and avoid being too clever. See JENKINS-10060 as an example // of where our trying to be too clever here is breaking stuff for people. for (Branch br : rev.getBranches()) { String b = br.getName(); if (b != null) { int slash = b.indexOf('/'); if ( slash != -1 ) remote = getDefaultRemote( b.substring(0,slash) ); } if (remote!=null) break; } if (remote==null) remote = getDefaultRemote(); if (remote!=null) setupSubmoduleUrls( remote, listener ); }
Example #19
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_anon_sshtrait_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId(null); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait(null); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is(nullValue())); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #20
Source File: GitLabCommitStatusPublisherTest.java From gitlab-plugin with GNU General Public License v2.0 | 4 votes |
private AbstractBuild mockBuildWithLibrary(String gitLabConnection, Result result, String... remoteUrls) { AbstractBuild build = mock(AbstractBuild.class); List<BuildData> buildDatas = new ArrayList<>(); BuildData buildData = mock(BuildData.class); SCMRevisionAction scmRevisionAction = mock(SCMRevisionAction.class); AbstractGitSCMSource.SCMRevisionImpl revisionImpl = mock(AbstractGitSCMSource.SCMRevisionImpl.class); when(build.getAction(SCMRevisionAction.class)).thenReturn(scmRevisionAction); when(scmRevisionAction.getRevision()).thenReturn(revisionImpl); when(revisionImpl.getHash()).thenReturn(SHA1); Revision revision = mock(Revision.class); when(revision.getSha1String()).thenReturn(SHA1); when(buildData.getLastBuiltRevision()).thenReturn(revision); when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls))); Build gitBuild = mock(Build.class); when(gitBuild.getMarked()).thenReturn(revision); when(gitBuild.getSHA1()).thenReturn(ObjectId.fromString(SHA1)); when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild); Map<String, Build> buildsByBranchName = new HashMap<>(); buildsByBranchName.put("develop", gitBuild); when(buildData.getBuildsByBranchName()).thenReturn(buildsByBranchName); buildDatas.add(buildData); //Second build data (@librabry) BuildData buildDataLib = mock(BuildData.class); Revision revisionLib = mock(Revision.class); when(revisionLib.getSha1String()).thenReturn("SHALIB"); when(buildDataLib.getLastBuiltRevision()).thenReturn(revisionLib); Build gitBuildLib = mock(Build.class); when(gitBuildLib.getMarked()).thenReturn(revisionLib); when(buildDataLib.getLastBuild(any(ObjectId.class))).thenReturn(gitBuildLib); buildDatas.add(buildDataLib); when(build.getActions(BuildData.class)).thenReturn(buildDatas); when(build.getResult()).thenReturn(result); when(build.getUrl()).thenReturn(BUILD_URL); AbstractProject<?, ?> project = mock(AbstractProject.class); when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection)); when(build.getProject()).thenReturn(project); EnvVars environment = mock(EnvVars.class); when(environment.expand(anyString())).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return (String) invocation.getArguments()[0]; } }); try { when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment); } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } return build; }
Example #21
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userpass_sshtrait_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId("user-pass"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-pass")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait(null); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is(nullValue())); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #22
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userkey_sshtrait_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId("user-key"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait(null); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is(nullValue())); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #23
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_anon_sshtrait_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId(null); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait("user-key"); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-key")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #24
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userpass_sshtrait_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId("user-pass"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-pass")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait("user-key"); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-key")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #25
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userkey_sshtrait_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"); source.setCredentialsId("user-key"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait("user-key"); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/tester/test-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-key")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(1)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example #26
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__server_pullMerge_rev_userpass__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git"); PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1, new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe" ); source.setCredentialsId("user-pass"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-pass")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.test/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.test/tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 " + "+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-pass")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(2)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(MergeWithGitSCMExtension.class), instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser, notNullValue()); assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class)); AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser = (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener( Logger.getAnonymousLogger(), Level.FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class); assertThat(merge, notNullValue()); assertThat(merge.getBaseName(), is("remotes/origin/test-branch")); assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef")); }
Example #27
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__server_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git"); PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1, new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe" ); source.setCredentialsId(null); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.test/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.test/tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 " + "+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git")); assertThat(config.getCredentialsId(), is(nullValue())); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(2)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(MergeWithGitSCMExtension.class), instanceOf(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser, notNullValue()); assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class)); AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser = (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener( Logger.getAnonymousLogger(), Level.FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class); assertThat(merge, notNullValue()); assertThat(merge.getBaseName(), is("remotes/origin/test-branch")); assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef")); }
Example #28
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1, new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe" ); source.setCredentialsId("user-key"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 " + "+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-key")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(2)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(GitSCMSourceDefaults.class), instanceOf(BuildChooserSetting.class), instanceOf(MergeWithGitSCMExtension.class) )); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser, notNullValue()); assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class)); AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser = (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener( Logger.getAnonymousLogger(), Level.FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class); assertThat(merge, notNullValue()); assertThat(merge.getBaseName(), is("remotes/origin/test-branch")); assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef")); }
Example #29
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_pullMerge_rev_userpass__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1, new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe" ); source.setCredentialsId("user-pass"); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is("user-pass")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 " + "+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git")); assertThat(config.getCredentialsId(), is("user-pass")); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(2)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(GitSCMSourceDefaults.class), instanceOf(BuildChooserSetting.class), instanceOf(MergeWithGitSCMExtension.class) )); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser, notNullValue()); assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class)); AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser = (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener( Logger.getAnonymousLogger(), Level.FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class); assertThat(merge, notNullValue()); assertThat(merge.getBaseName(), is("remotes/origin/test-branch")); assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef")); }
Example #30
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1, new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe" ); source.setCredentialsId(null); GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1")); assertThat("expecting guess value until withGitHubRemote called", instance.remote(), is("https://github.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); GitSCM actual = instance.build(); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo")); assertThat(actual.getGitTool(), nullValue()); assertThat(actual.getUserRemoteConfigs(), hasSize(1)); UserRemoteConfig config = actual.getUserRemoteConfigs().get(0); assertThat(config.getName(), is("origin")); assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 " + "+refs/heads/test-branch:refs/remotes/origin/test-branch")); assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git")); assertThat(config.getCredentialsId(), is(nullValue())); RemoteConfig origin = actual.getRepositoryByName("origin"); assertThat(origin, notNullValue()); assertThat(origin.getURIs(), hasSize(1)); assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git")); assertThat(origin.getFetchRefSpecs(), hasSize(2)); assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head")); assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1")); assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false)); assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch")); assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true)); assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false)); assertThat(actual.getExtensions(), containsInAnyOrder( instanceOf(GitSCMSourceDefaults.class), instanceOf(BuildChooserSetting.class), instanceOf(MergeWithGitSCMExtension.class) )); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser, notNullValue()); assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class)); AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser = (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener( Logger.getAnonymousLogger(), Level.FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class); assertThat(merge, notNullValue()); assertThat(merge.getBaseName(), is("remotes/origin/test-branch")); assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef")); }