org.eclipse.jgit.merge.ResolveMerger Java Examples

The following examples show how to use org.eclipse.jgit.merge.ResolveMerger. 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: GitUtils.java    From onedev with MIT License 5 votes vote down vote up
@Nullable
  public static ObjectId rebase(Repository repository, ObjectId source, ObjectId target, PersonIdent committer) {
  	try (	RevWalk revWalk = new RevWalk(repository);
  			ObjectInserter inserter = repository.newObjectInserter();) {
  		RevCommit sourceCommit = revWalk.parseCommit(source);
  		RevCommit targetCommit = revWalk.parseCommit(target);
  		revWalk.setRevFilter(RevFilter.NO_MERGES);
  		List<RevCommit> commits = RevWalkUtils.find(revWalk, sourceCommit, targetCommit);
  		Collections.reverse(commits);
  		RevCommit headCommit = targetCommit;
  		for (RevCommit commit: commits) {
      		ResolveMerger merger = (ResolveMerger) MergeStrategy.RECURSIVE.newMerger(repository, true);
      		merger.setBase(commit.getParent(0));
      		if (merger.merge(headCommit, commit)) {
			if (!headCommit.getTree().getId().equals(merger.getResultTreeId())) {
				if (!commit.getTree().getId().equals(merger.getResultTreeId()) 
						|| !commit.getParent(0).equals(headCommit)) {
			        CommitBuilder commitBuilder = new CommitBuilder();
			        commitBuilder.setAuthor(commit.getAuthorIdent());
			        commitBuilder.setCommitter(committer);
			        commitBuilder.setParentId(headCommit);
			        commitBuilder.setMessage(commit.getFullMessage());
			        commitBuilder.setTreeId(merger.getResultTreeId());
			        headCommit = revWalk.parseCommit(inserter.insert(commitBuilder));
				} else {
					headCommit = commit;
				}
			}
      		} else {
      			return null;
      		}
  		}
  		inserter.flush();
  		return headCommit.copy();
  	} catch (IOException e) {
  		throw new RuntimeException(e);
}
  }
 
Example #2
Source File: GitMergeResult.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<File> getFailures (MergeResult result) {
    List<File> files = new LinkedList<File>();
    Map<String, ResolveMerger.MergeFailureReason> obstructions = result.getFailingPaths();
    if (obstructions != null) {
        for (Map.Entry<String, ResolveMerger.MergeFailureReason> failure : obstructions.entrySet()) {
            files.add(new File(workDir, failure.getKey()));
        }
    }
    return Collections.unmodifiableList(files);
}
 
Example #3
Source File: CherryPickCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<File> getFailures (CherryPickResult result) {
    List<File> files = new ArrayList<>();
    File workDir = getRepository().getWorkTree();
    if (result.getStatus() == CherryPickResult.CherryPickStatus.FAILED) {
        Map<String, ResolveMerger.MergeFailureReason> obstructions = result.getFailingPaths();
        if (obstructions != null) {
            for (Map.Entry<String, ResolveMerger.MergeFailureReason> failure : obstructions.entrySet()) {
                files.add(new File(workDir, failure.getKey()));
            }
        }
    }
    return Collections.unmodifiableList(files);
}
 
Example #4
Source File: MergeConflict.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Map<String, MergeConflict> readConflicts(ResolveMerger merger) {
  Map<String, MergeConflict> ret = new HashMap<>();
  for(Map.Entry<String, MergeResult<? extends Sequence>> conflict : merger.getMergeResults().entrySet())
    ret.put(toAbsolutePath(conflict.getKey()), new MergeConflict(conflict.getValue(), merger.getCommitNames()));
  return unmodifiableMap(ret);
}
 
Example #5
Source File: MergeConflict.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Map<String, MergeConflict> readConflicts(ResolveMerger merger) {
  Map<String, MergeConflict> ret = new HashMap<>();
  for(Map.Entry<String, MergeResult<? extends Sequence>> conflict : merger.getMergeResults().entrySet())
    ret.put(toAbsolutePath(conflict.getKey()), new MergeConflict(conflict.getValue(), merger.getCommitNames()));
  return unmodifiableMap(ret);
}