コード例 #1
0
ファイル: MergeUtil.java プロジェクト: web1992/gerrit
 public static String mergeStrategyName(boolean useContentMerge, boolean useRecursiveMerge) {
   if (useContentMerge) {
     // Settings for this project allow us to try and automatically resolve
     // conflicts within files if needed. Use either the old resolve merger or
     // new recursive merger, and instruct to operate in core.
     if (useRecursiveMerge) {
       return MergeStrategy.RECURSIVE.getName();
     } else {
       return MergeStrategy.RESOLVE.getName();
     }
   } else {
     // No auto conflict resolving allowed. If any of the
     // affected files was modified, merge will fail.
     return MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.getName();
   }
 }
コード例 #2
0
 /**
  * Merges current master with the given branch. The strategy used is Resolve since egit does still
  * not support the Recusive stragety.
  *
  * @param branch the branch to merge
  * @param repository the repository the branch is in
  * @param monitor the monitor to report the progress to
  * @return the result of the merge
  * @throws CoreException
  * @see MergeStrategy#RESOLVE
  * @link http://www.eclipse.org/forums/index.php/mv/msg/261278/753913/#msg_753913
  * @link https://bugs.eclipse.org/bugs/show_bug.cgi?id=354099
  * @link https://bugs.eclipse.org/bugs/show_bug.cgi?id=359951
  */
 private static MergeResult merge(String branch, Repository repository, IProgressMonitor monitor)
     throws CoreException {
   MergeOperation merge = new MergeOperation(repository, branch, MergeStrategy.RESOLVE.getName());
   merge.execute(monitor);
   return merge.getResult();
 }
コード例 #3
0
ファイル: GitUtils.java プロジェクト: snjeza/core
  public static CherryPickResult cherryPickNoMerge(final Git git, Ref src)
      throws GitAPIException, CantMergeCommitWithZeroParentsException {
    // Does the same as the original git-cherryPick
    // except commiting after running merger
    Repository repo = git.getRepository();

    RevCommit newHead = null;
    List<Ref> cherryPickedRefs = new LinkedList<Ref>();

    RevWalk revWalk = new RevWalk(repo);
    try {
      // get the head commit
      Ref headRef = repo.getRef(Constants.HEAD);
      if (headRef == null)
        throw new NoHeadException(JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
      RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());

      newHead = headCommit;

      // get the commit to be cherry-picked
      // handle annotated tags
      ObjectId srcObjectId = src.getPeeledObjectId();
      if (srcObjectId == null) srcObjectId = src.getObjectId();
      RevCommit srcCommit = revWalk.parseCommit(srcObjectId);

      // get the parent of the commit to cherry-pick
      if (srcCommit.getParentCount() == 0)
        throw new CantMergeCommitWithZeroParentsException(
            "Commit with zero parents cannot be merged");

      if (srcCommit.getParentCount() > 1)
        throw new MultipleParentsNotAllowedException(
            MessageFormat.format(
                JGitText.get().canOnlyCherryPickCommitsWithOneParent,
                srcCommit.name(),
                Integer.valueOf(srcCommit.getParentCount())));

      RevCommit srcParent = srcCommit.getParent(0);
      revWalk.parseHeaders(srcParent);

      ResolveMerger merger = (ResolveMerger) MergeStrategy.RESOLVE.newMerger(repo);
      merger.setWorkingTreeIterator(new FileTreeIterator(repo));
      merger.setBase(srcParent.getTree());
      if (merger.merge(headCommit, srcCommit)) {
        DirCacheCheckout dco =
            new DirCacheCheckout(
                repo, headCommit.getTree(), repo.lockDirCache(), merger.getResultTreeId());
        dco.setFailOnConflict(true);
        dco.checkout();

        cherryPickedRefs.add(src);
      } else {
        if (merger.failed()) return new CherryPickResult(merger.getFailingPaths());

        // there are merge conflicts
        String message =
            new MergeMessageFormatter()
                .formatWithConflicts(srcCommit.getFullMessage(), merger.getUnmergedPaths());

        repo.writeCherryPickHead(srcCommit.getId());
        repo.writeMergeCommitMsg(message);

        return CherryPickResult.CONFLICT;
      }
    } catch (IOException e) {
      throw new JGitInternalException(
          MessageFormat.format(JGitText.get().exceptionCaughtDuringExecutionOfCherryPickCommand, e),
          e);
    } finally {
      revWalk.release();
    }

    return new CherryPickResult(newHead, cherryPickedRefs);
  }