Source:
<code>public RevCommit call() throws GitAPIException { RevCommit newHead = null; checkCallable(); RevWalk revWalk = new RevWalk(repo); try { Ref headRef = repo.getRef(Constants.HEAD); if (headRef == null) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); <START> RevCommit headCommit = revWalk.lookupCommit(headRef.getObjectId()); <END> for (Ref src : commits) { ObjectId srcObjectId = src.getPeeledObjectId(); if (srcObjectId == null) srcObjectId = src.getObjectId(); RevCommit srcCommit = revWalk.parseCommit(srcObjectId); if (srcCommit.getParentCount() != 1) { throw new InvalidCherryPickCommit( JGitText.get().canOnlyCherryPickCommitsWithOneParent); } RevCommit srcParent = revWalk.parseCommit(srcCommit .getParent(0)); 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(); newHead = new Git(getRepository()).commit() .setMessage(srcCommit.getFullMessage()) .setAuthor(srcCommit.getAuthorIdent()).call(); cherryPickedRefs.add(src); } else { return null; } } } catch (IOException e) { throw new JGitInternalException( MessageFormat.format( JGitText.get().exceptionCaughtDuringExecutionOfCherryPickCommand, e), e); } finally { revWalk.release(); } return newHead; }</code><technical_language>lookupCommit assumes is a commit. true, manually done in repository HEAD a non-commit. parseCommit parsing hit in order ensure new parent is a commit. create a corrupt object a parent points a commit if HEAD mangled externally</technical_language>

Target:
public RevCommit call() throws GitAPIException { RevCommit newHead = null; checkCallable(); RevWalk revWalk = new RevWalk(repo); try { Ref headRef = repo.getRef(Constants.HEAD); if (headRef == null) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId()); for (Ref src : commits) { ObjectId srcObjectId = src.getPeeledObjectId(); if (srcObjectId == null) srcObjectId = src.getObjectId(); RevCommit srcCommit = revWalk.parseCommit(srcObjectId); if (srcCommit.getParentCount() != 1) { throw new MultipleParentsNotAllowedException( JGitText.get().canOnlyCherryPickCommitsWithOneParent); } 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(); newHead = new Git(getRepository()).commit() .setMessage(srcCommit.getFullMessage()) .setAuthor(srcCommit.getAuthorIdent()).call(); cherryPickedRefs.add(src); } else { return null; } } } catch (IOException e) { throw new JGitInternalException( MessageFormat.format( JGitText.get().exceptionCaughtDuringExecutionOfCherryPickCommand, e), e); } finally { revWalk.release(); } return newHead; }