Java Code Examples for hudson.plugins.git.GitSCM#getExtensions()

The following examples show how to use hudson.plugins.git.GitSCM#getExtensions() . 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: GitLabSCMMergeRequestHead.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 6 votes vote down vote up
@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 2
Source File: GitLabSCMMergeRequestHead.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
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 3
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
private static <T extends GitSCMExtension> T getExtension(GitSCM scm, Class<T> type) {
    for (GitSCMExtension e : scm.getExtensions()) {
        if (type.isInstance(e)) {
            return type.cast(e);
        }
    }
    return null;
}