org.eclipse.jgit.api.Git.merge()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(322)

本文整理了Java中org.eclipse.jgit.api.Git.merge()方法的一些代码示例,展示了Git.merge()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.merge()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:merge

Git.merge介绍

[英]Return a command object to execute a Merge command
[中]返回命令对象以执行合并命令

代码示例

代码示例来源:origin: gocd/gocd

String getMergedConfig(String branchName, RevCommit newCommit) throws GitAPIException, IOException {
  MergeResult result = null;
  try {
    checkout(branchName);
    result = git.merge().include(newCommit).call();
  } catch (GitAPIException e) {
    LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName());
    throw e;
  }
  if (!result.getMergeStatus().isSuccessful()) {
    LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed as config file has changed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName,
        getCurrentRevCommit().getId().getName());
    throw new ConfigFileHasChangedException();
  }
  LOGGER.info("[CONFIG_MERGE] Successfully merged commit {} by user {} to branch {}. Merge commit revision is {}", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName());
  return FileUtils.readFileToString(new File(workingDir, CRUISE_CONFIG_XML), UTF_8);
}

代码示例来源:origin: spring-cloud/spring-cloud-config

private MergeResult merge(Git git, String label) {
  try {
    MergeCommand merge = git.merge();
    merge.include(git.getRepository().findRef("origin/" + label));
    MergeResult result = merge.call();
    if (!result.getMergeStatus().isSuccessful()) {
      this.logger.warn("Merged from remote " + label + " with result "
          + result.getMergeStatus());
    }
    return result;
  }
  catch (Exception ex) {
    String message = "Could not merge remote for " + label + " remote: " + git
        .getRepository().getConfig().getString("remote", "origin", "url");
    warn(message, ex);
    return null;
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory merge(String[] refs, ArrayMemory settings) throws IOException, GitAPIException {
  MergeCommand command = getWrappedObject().merge();
  for (String ref : refs) {
    Repository repository = getWrappedObject().getRepository();
    ObjectId objectId = repository.resolve(ref);
    command.include(objectId);
  }
  if (settings != null) {
    command.setCommit(settings.valueOfIndex("commit").toBoolean());
    command.setMessage(settings.valueOfIndex("message").toString());
    command.setSquash(settings.valueOfIndex("squash").toBoolean());
    Memory fastForward = settings.valueOfIndex("fastForward");
    
    if (fastForward.isNumber()) {
      command.setFastForward(MergeCommand.FastForwardMode.valueOf(fastForward.toString()));
    }
    Memory strategy = settings.valueOfIndex("strategy");
    if (strategy.isNotNull()) {
      command.setStrategy(MergeStrategy.get(strategy.toString()));
    }
  }
  MergeResult call = command.call();
  return GitUtils.valueOf(call);
}

代码示例来源:origin: centic9/jgit-cookbook

MergeResult merge = git.merge().
    include(mergeBase).
    setCommit(true).

代码示例来源:origin: centic9/jgit-cookbook

MergeResult merge = git.merge().
    include(mergeBase).
    setCommit(true).

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

MergeCommand merge = git.merge()
    .setFastForward(MergeCommand.FastForwardMode.NO_FF)
    .setProgressMonitor(monitor)

代码示例来源:origin: org.openmrs.maven.plugins/openmrs-sdk-maven-plugin

/**
 * Merge with temporary branch
 * @param git
 * @param newBranchFull
 * @throws IOException
 * @throws GitAPIException
 */
private void mergeWithNewBranch(Git git, String newBranchFull) throws Exception {
  MergeCommand mergeCommand = git.merge();
  try {
    mergeCommand.include(git.getRepository().getRef(newBranchFull));
    mergeCommand.setFastForward(MergeCommand.FastForwardMode.FF_ONLY);
    mergeCommand.call();
  } catch (GitAPIException e) {
    throw new Exception(MERGING_PROBLEM_REASON, e);
  } catch (IOException e) {
    throw new Exception(GIT_COMMAND_REASON, e);
  }
}

代码示例来源:origin: stackoverflow.com

Git git = ... // you get it through a CloneCommand, InitCommand 
       // or through the file system

CheckoutCommand coCmd = git.checkout(); 
// Commands are part of the api module, which include git-like calls
coCmd.setName("master");
coCmd.setCreateBranch(false); // probably not needed, just to make sure
coCmd.call(); // switch to "master" branch

MergeCommand mgCmd = git.merge();
mgCmd.include("foo"); // "foo" is considered as a Ref to a branch
MergeResult res = mgCmd.call(); // actually do the merge

if (res.getMergeStatus().equals(MergeResult.MergeStatus.CONFLICTING)){
  System.out.println(res.getConflicts().toString());
  // inform the user he has to handle the conflicts
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

/**
 * Merges the branch represented by the passed branchId in the current branch.
 *
 * @param branchId - String representation of an ObjectId
 * @throws GitAPIException - failed.
 */
public void merge(final String branchId) throws GitAPIException {
  git.merge()
    .setCommit(true)
    .include(ObjectId.fromString(branchId))
    .call();
}

代码示例来源:origin: Verigreen/verigreen

public Pair<Boolean, String> merge(String branchToUpdate, String branchHead, boolean commit) {
  
  Pair<Boolean, String> ret = new Pair<>(false, "");
  MergeCommand command = _git.merge();
  try {
    String refName =
        !branchHead.contains(REFS_HEADS) ? REFS_REMOTES + branchHead : branchHead;
    command.include(_repo.getRef(refName));
    command.setCommit(commit);
    MergeResult mergeResult = command.call();
    ret = checkResult(branchToUpdate, branchHead, ret, mergeResult);
  } catch (Throwable e) {
    VerigreenLogger.get().log(
        getClass().getName(),
        RuntimeUtils.getCurrentMethodName(),
        String.format(
            "Failed to update branch [%s] with parent branch [%s]",
            branchToUpdate,
            branchHead));
  }
  
  return ret;
}

代码示例来源:origin: org.apache.camel/camel-git

protected void doMerge(Exchange exchange, String operation) throws Exception {
  MergeResult result = null;
  ObjectId mergeBase;
  try {
    if (ObjectHelper.isEmpty(endpoint.getBranchName())) {
      throw new IllegalArgumentException("Branch name must be specified to execute " + operation);
    }
    mergeBase = git.getRepository().resolve(endpoint.getBranchName());
    git.checkout().setName("master").call();
    result = git.merge().include(mergeBase).setFastForward(FastForwardMode.FF).setCommit(true).call();
  } catch (Exception e) {
    LOG.error("There was an error in Git {} operation", operation);
    throw e;
  }
  updateExchange(exchange, result);
}

代码示例来源:origin: matburt/mobileorg-android

git.merge()
    .setStrategy(MergeStrategy.OURS)
    .include(ref)

代码示例来源:origin: org.springframework.cloud.stream.app/python-app-starters-common

private MergeResult merge(Git git, String branch) {
  try {
    MergeCommand merge = git.merge();
    merge.include(git.getRepository().findRef("origin/" + branch));
    MergeResult result = merge.call();
    if (!result.getMergeStatus().isSuccessful()) {
      this.logger.warn("Merged from remote " + branch + " with result " + result.getMergeStatus());
    }
    return result;
  }
  catch (Exception ex) {
    String message = "Could not merge remote for " + branch + " remote: " + git.getRepository().getConfig()
      .getString("remote", "origin", "url");
    warn(message, ex);
    return null;
  }
}

代码示例来源:origin: maks/MGit

mRepo.getGit().merge().include(mCommit).setFastForward(ffMode)
      .call();
} catch (GitAPIException e) {

代码示例来源:origin: jenkinsci/git-client-plugin

@Override
  public void execute() throws GitException, InterruptedException {
    try (Repository repo = getRepository()) {
      Git git = git(repo);
      MergeResult mergeResult;
      if (strategy != null)
        mergeResult = git.merge().setMessage(comment).setStrategy(strategy).setFastForward(fastForwardMode).setSquash(squash).setCommit(commit).include(rev).call();
      else
        mergeResult = git.merge().setMessage(comment).setFastForward(fastForwardMode).setSquash(squash).setCommit(commit).include(rev).call();
      if (!mergeResult.getMergeStatus().isSuccessful()) {
        git.reset().setMode(HARD).call();
        throw new GitException("Failed to merge " + rev);
      }
    } catch (GitAPIException e) {
      throw new GitException("Failed to merge " + rev, e);
    }
  }
};

代码示例来源:origin: line/centraldogma

final MergeResult mergeResult = git.merge()
                  .include(commit1.getId())
                  .setFastForward(FastForwardMode.NO_FF)

代码示例来源:origin: Spirals-Team/repairnator

MergeResult result = git.merge().include(revCommitBase).setFastForward(MergeCommand.FastForwardMode.NO_FF).call();
  this.nbCommits++;
} catch (Exception e) {

代码示例来源:origin: jboss-fuse/fabric8

.call();
MergeResult result = git.merge()
    .setFastForward(MergeCommand.FastForwardMode.NO_FF)
    .include(git.getRepository().resolve(patchBranch))

代码示例来源:origin: io.fabric8.patch/patch-management

.call();
MergeResult result = git.merge()
    .setFastForward(MergeCommand.FastForwardMode.NO_FF)
    .include(git.getRepository().resolve(patchBranch))

代码示例来源:origin: external.atlassian.jgitflow/jgit-flow-core

mergeResult = git.merge().setSquash(true).include(localBranchRef).call();
if (mergeResult.getMergeStatus().isSuccessful())
MergeCommand mergeCommand = git.merge().setFastForward(ffMode).include(localBranchRef);

相关文章