Example usage for org.eclipse.jgit.errors NoMergeBaseException NoMergeBaseException

List of usage examples for org.eclipse.jgit.errors NoMergeBaseException NoMergeBaseException

Introduction

In this page you can find the example usage for org.eclipse.jgit.errors NoMergeBaseException NoMergeBaseException.

Prototype

public NoMergeBaseException(MergeBaseFailureReason reason, String message) 

Source Link

Document

Construct a NoMergeBase exception

Usage

From source file:com.hpe.application.automation.tools.octane.model.processors.scm.GitSCMProcessor.java

License:Open Source License

@Override
public CommonOriginRevision getCommonOriginRevision(final Run run) {
    //for phase 1 this is hard coded since its not possible to calculate it, and configuration from outside will complicate the feature
    //so for this phase we keep it hardcoded.
    CommonOriginRevision commonOriginRevision = new CommonOriginRevision();

    try {//w  w w . j a va 2s .c om
        final AbstractBuild abstractBuild = (AbstractBuild) run;
        FilePath workspace = ((AbstractBuild) run).getWorkspace();
        if (workspace != null) {
            commonOriginRevision = workspace.act(new FilePath.FileCallable<CommonOriginRevision>() {
                @Override
                public CommonOriginRevision invoke(File file, VirtualChannel channel)
                        throws IOException, InterruptedException {
                    CommonOriginRevision result = new CommonOriginRevision();
                    File repoDir = new File(getRemoteString(abstractBuild) + File.separator + ".git");
                    Git git = Git.open(repoDir);
                    Repository repo = git.getRepository();
                    final RevWalk walk = new RevWalk(repo);

                    ObjectId resolveForCurrentBranch = repo.resolve(Constants.HEAD);
                    RevCommit currentBranchCommit = walk.parseCommit(resolveForCurrentBranch);
                    ObjectId resolveForMaster = repo.resolve(MASTER);
                    RevCommit masterCommit = walk.parseCommit(resolveForMaster);

                    walk.reset();
                    walk.setRevFilter(RevFilter.MERGE_BASE);
                    walk.markStart(currentBranchCommit);
                    walk.markStart(masterCommit);
                    final RevCommit base = walk.next();
                    if (base == null)
                        return result;
                    final RevCommit base2 = walk.next();
                    if (base2 != null) {
                        throw new NoMergeBaseException(
                                NoMergeBaseException.MergeBaseFailureReason.MULTIPLE_MERGE_BASES_NOT_SUPPORTED,
                                MessageFormat.format(JGitText.get().multipleMergeBasesFor,
                                        currentBranchCommit.name(), masterCommit.name(), base.name(),
                                        base2.name()));
                    }
                    result.revision = base.getId().getName();
                    result.branch = getBranchName(run);
                    return result;
                }

                @Override
                public void checkRoles(RoleChecker roleChecker) throws SecurityException {
                    if (roleChecker != null) {
                        logger.info("Note : roleChecker is not empty, but no action was taken");
                    }
                }
            });
        }
        logger.info("most recent common revision resolved to " + commonOriginRevision.revision + " (branch: "
                + commonOriginRevision.branch + ")");
    } catch (Exception e) {
        logger.error("failed to resolve most recent common revision", e);
        return commonOriginRevision;
    }
    return commonOriginRevision;
}

From source file:org.kuali.student.git.importer.ReportBlobSizePerBranch.java

License:Educational Community License

private static RevCommit getMergeBaseCommit(RevWalk walk, RevCommit a, RevCommit b)
        throws IncorrectObjectTypeException, IOException {
    walk.reset();//from   w w w . j  a  v  a 2s .  c om
    walk.setRevFilter(RevFilter.MERGE_BASE);
    walk.markStart(a);
    walk.markStart(b);
    final RevCommit base = walk.next();
    if (base == null)
        return null;
    final RevCommit base2 = walk.next();
    if (base2 != null) {
        throw new NoMergeBaseException(MergeBaseFailureReason.MULTIPLE_MERGE_BASES_NOT_SUPPORTED, MessageFormat
                .format(JGitText.get().multipleMergeBasesFor, a.name(), b.name(), base.name(), base2.name()));
    }
    return base;
}