Java Code Examples for org.eclipse.jgit.api.CherryPickResult#getStatus()

The following examples show how to use org.eclipse.jgit.api.CherryPickResult#getStatus() . 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: GitMergeUtil.java    From MergeProcessor with Apache License 2.0 7 votes vote down vote up
/**
 * {@code git cherryPick}
 * 
 * @throws MergeCancelException
 */
private void cherryPick() {
	final ObjectId id = ObjectId.fromString(mergeUnit.getRevisionInfo());
	try {
		final CherryPickResult result = repo.cherryPick().include(id).setNoCommit(true).call();
		switch (result.getStatus()) {
		case CONFLICTING:
			final Collection<String> conflicts = repo.status().call().getConflicting();
			resolveConflicts(conflicts);
			break;
		case FAILED:
			exception = new MergeUnitException(String.format("Could not cherry pick the given commit '%s'", //$NON-NLS-1$
					mergeUnit.getRevisionInfo()));
			break;
		default:
			break;
		}
	} catch (GitAPIException e) {
		exception = new MergeUnitException(String.format("Could not cherry pick from the given id %s.", id), e); //$NON-NLS-1$
	}
}
 
Example 2
Source File: CherryPickCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private GitCherryPickResult createResult (CherryPickResult res, List<Ref> cherryPickedRefs) {
    GitRevisionInfo currHead = getCurrentHead();

    GitCherryPickResult.CherryPickStatus status = GitCherryPickResult.CherryPickStatus.valueOf(res.getStatus().name());
    List<File> conflicts;
    if (res.getStatus() == CherryPickResult.CherryPickStatus.CONFLICTING) {
        conflicts = getConflicts(currHead);
    } else {
        conflicts = Collections.<File>emptyList();
    }
    List<GitRevisionInfo> commits = toCommits(cherryPickedRefs);
    return getClassFactory().createCherryPickResult(status, conflicts, getFailures(res), currHead, commits);
}
 
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: CherryPickCommand.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void applySteps (List<RebaseTodoLine> steps, boolean skipFirstStep) throws GitAPIException, IOException {
    Repository repository = getRepository();
    ObjectReader or = repository.newObjectReader();
    CherryPickResult res = null;
    boolean skipped = false;
    List<Ref> cherryPickedRefs = new ArrayList<>();
    for (Iterator<RebaseTodoLine> it = steps.iterator(); it.hasNext();) {
        RebaseTodoLine step = it.next();
        if (step.getAction() == RebaseTodoLine.Action.PICK) {
            if (skipFirstStep && !skipped) {
                it.remove();
                writeTodoFile(repository, steps);
                skipped = true;
                continue;
            }
            Collection<ObjectId> ids = or.resolve(step.getCommit());
            if (ids.size() != 1) {
                throw new JGitInternalException("Could not resolve uniquely the abbreviated object ID");
            }
            org.eclipse.jgit.api.CherryPickCommand command = new Git(repository).cherryPick();
            command.include(ids.iterator().next());
            if (workAroundStrategyIssue) {
                command.setStrategy(new FailuresDetectRecurciveStrategy());
            }
            res = command.call();
            if (res.getStatus() == CherryPickResult.CherryPickStatus.OK) {
                it.remove();
                writeTodoFile(repository, steps);
                cherryPickedRefs.addAll(res.getCherryPickedRefs());
            } else {
                break;
            }
        } else {
            it.remove();
        }
    }
    if (res == null) {
        result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK, cherryPickedRefs);
    } else {
        result = createResult(res, cherryPickedRefs);
    }
    if (steps.isEmpty()) {
        // sequencer no longer needed
        Utils.deleteRecursively(getSequencerFolder());
    }
}