org.eclipse.jgit.api.CherryPickResult Java Examples
The following examples show how to use
org.eclipse.jgit.api.CherryPickResult.
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 |
/** * {@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 |
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 |
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: GitOperations.java From spring-data-dev-tools with Apache License 2.0 | 5 votes |
private void cherryPickCommitToBranch(ObjectId id, Project project, Branch branch) { doWithGit(project, git -> { try { checkout(project, branch); } catch (RuntimeException o_O) { logger.warn(project, "Couldn't check out branch %s. Skipping cherrypick of commit %s.", branch, id.getName()); return; } logger.log(project, "git cp %s", id.getName()); // Required as the CherryPick command has no setter for a CredentialsProvide *sigh* if (gpg.isGpgAvailable()) { CredentialsProvider.setDefault(new GpgPassphraseProvider(gpg)); } CherryPickResult result = git.cherryPick().include(id).call(); if (result.getStatus().equals(CherryPickStatus.OK)) { logger.log(project, "Successfully cherry-picked commit %s to branch %s.", id.getName(), branch); } else { logger.warn(project, "Cherry pick failed. aborting…"); logger.log(project, "git reset --hard"); git.reset().setMode(ResetType.HARD).call(); } }); }
Example #5
Source File: CherryPickCommand.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected void run () throws GitException { Repository repository = getRepository(); ObjectId originalCommit = getOriginalCommit(); ObjectId head = getHead(); List<RebaseTodoLine> steps; try { switch (operation) { case BEGIN: // initialize sequencer and cherry-pick steps if there are // more commits to cherry-pick steps = prepareCommand(head); // apply the selected steps applySteps(steps, false); break; case ABORT: // delete the sequencer and reset to the original head if (repository.getRepositoryState() == RepositoryState.CHERRY_PICKING || repository.getRepositoryState() == RepositoryState.CHERRY_PICKING_RESOLVED) { if (originalCommit == null) { // maybe the sequencer is not created in that case simply reset to HEAD originalCommit = head; } } Utils.deleteRecursively(getSequencerFolder()); if (originalCommit != null) { ResetCommand reset = new ResetCommand(repository, getClassFactory(), originalCommit.name(), GitClient.ResetType.HARD, new DelegatingGitProgressMonitor(monitor), listener); reset.execute(); } result = createCustomResult(GitCherryPickResult.CherryPickStatus.ABORTED); break; case QUIT: // used to reset the sequencer only Utils.deleteRecursively(getSequencerFolder()); switch (repository.getRepositoryState()) { case CHERRY_PICKING: // unresolved conflicts result = createResult(CherryPickResult.CONFLICT); break; case CHERRY_PICKING_RESOLVED: result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED); break; default: result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK); break; } break; case CONTINUE: switch (repository.getRepositoryState()) { case CHERRY_PICKING: // unresolved conflicts, cannot continue result = createResult(CherryPickResult.CONFLICT); break; case CHERRY_PICKING_RESOLVED: // cannot continue without manual commit result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED); break; default: // read steps from sequencer and apply them // if sequencer is empty this will be a noop steps = readTodoFile(repository); applySteps(steps, true); break; } break; default: throw new IllegalStateException("Unexpected operation " + operation.name()); } } catch (GitAPIException | IOException ex) { throw new GitException(ex); } }
Example #6
Source File: CherryPickCommand.java From netbeans with Apache License 2.0 | 4 votes |
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()); } }
Example #7
Source File: CherryPickCommand.java From netbeans with Apache License 2.0 | 4 votes |
private GitCherryPickResult createResult (CherryPickResult res) { return createResult(res, Collections.<Ref>emptyList()); }
Example #8
Source File: GitEnumsStateTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testCherryPickStatus () { for (CherryPickResult.CherryPickStatus status : CherryPickResult.CherryPickStatus.values()) { assertNotNull(GitCherryPickResult.CherryPickStatus.valueOf(status.name())); } }