CherryPickResult.java

  1. /*
  2.  * Copyright (C) 2011, Philipp Thun <philipp.thun@sap.com> and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */
  10. package org.eclipse.jgit.api;

  11. import java.util.List;
  12. import java.util.Map;

  13. import org.eclipse.jgit.lib.Ref;
  14. import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
  15. import org.eclipse.jgit.revwalk.RevCommit;

  16. /**
  17.  * Encapsulates the result of a {@link org.eclipse.jgit.api.CherryPickCommand}.
  18.  */
  19. public class CherryPickResult {

  20.     /**
  21.      * The cherry-pick status
  22.      */
  23.     public enum CherryPickStatus {
  24.         /** */
  25.         OK {
  26.             @Override
  27.             public String toString() {
  28.                 return "Ok"; //$NON-NLS-1$
  29.             }
  30.         },
  31.         /** */
  32.         FAILED {
  33.             @Override
  34.             public String toString() {
  35.                 return "Failed"; //$NON-NLS-1$
  36.             }
  37.         },
  38.         /** */
  39.         CONFLICTING {
  40.             @Override
  41.             public String toString() {
  42.                 return "Conflicting"; //$NON-NLS-1$
  43.             }
  44.         }
  45.     }

  46.     private final CherryPickStatus status;

  47.     private final RevCommit newHead;

  48.     private final List<Ref> cherryPickedRefs;

  49.     private final Map<String, MergeFailureReason> failingPaths;

  50.     /**
  51.      * Constructor for CherryPickResult
  52.      *
  53.      * @param newHead
  54.      *            commit the head points at after this cherry-pick
  55.      * @param cherryPickedRefs
  56.      *            list of successfully cherry-picked <code>Ref</code>'s
  57.      */
  58.     public CherryPickResult(RevCommit newHead, List<Ref> cherryPickedRefs) {
  59.         this.status = CherryPickStatus.OK;
  60.         this.newHead = newHead;
  61.         this.cherryPickedRefs = cherryPickedRefs;
  62.         this.failingPaths = null;
  63.     }

  64.     /**
  65.      * Constructor for CherryPickResult
  66.      *
  67.      * @param failingPaths
  68.      *            list of paths causing this cherry-pick to fail (see
  69.      *            {@link org.eclipse.jgit.merge.ResolveMerger#getFailingPaths()}
  70.      *            for details)
  71.      */
  72.     public CherryPickResult(Map<String, MergeFailureReason> failingPaths) {
  73.         this.status = CherryPickStatus.FAILED;
  74.         this.newHead = null;
  75.         this.cherryPickedRefs = null;
  76.         this.failingPaths = failingPaths;
  77.     }

  78.     private CherryPickResult(CherryPickStatus status) {
  79.         this.status = status;
  80.         this.newHead = null;
  81.         this.cherryPickedRefs = null;
  82.         this.failingPaths = null;
  83.     }

  84.     /**
  85.      * A <code>CherryPickResult</code> with status
  86.      * {@link CherryPickStatus#CONFLICTING}
  87.      */
  88.     public static final CherryPickResult CONFLICT = new CherryPickResult(
  89.             CherryPickStatus.CONFLICTING);

  90.     /**
  91.      * Get status
  92.      *
  93.      * @return the status this cherry-pick resulted in
  94.      */
  95.     public CherryPickStatus getStatus() {
  96.         return status;
  97.     }

  98.     /**
  99.      * Get the new head after this cherry-pick
  100.      *
  101.      * @return the commit the head points at after this cherry-pick,
  102.      *         <code>null</code> if {@link #getStatus} is not
  103.      *         {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#OK}
  104.      */
  105.     public RevCommit getNewHead() {
  106.         return newHead;
  107.     }

  108.     /**
  109.      * Get the cherry-picked {@code Ref}s
  110.      *
  111.      * @return the list of successfully cherry-picked <code>Ref</code>'s,
  112.      *         <code>null</code> if {@link #getStatus} is not
  113.      *         {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#OK}
  114.      */
  115.     public List<Ref> getCherryPickedRefs() {
  116.         return cherryPickedRefs;
  117.     }

  118.     /**
  119.      * Get the list of paths causing this cherry-pick to fail
  120.      *
  121.      * @return the list of paths causing this cherry-pick to fail (see
  122.      *         {@link org.eclipse.jgit.merge.ResolveMerger#getFailingPaths()}
  123.      *         for details), <code>null</code> if {@link #getStatus} is not
  124.      *         {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#FAILED}
  125.      */
  126.     public Map<String, MergeFailureReason> getFailingPaths() {
  127.         return failingPaths;
  128.     }
  129. }