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
12 import java.util.List;
13 import java.util.Map;
14
15 import org.eclipse.jgit.lib.Ref;
16 import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
17 import org.eclipse.jgit.revwalk.RevCommit;
18
19 /**
20 * Encapsulates the result of a {@link org.eclipse.jgit.api.CherryPickCommand}.
21 */
22 public class CherryPickResult {
23
24 /**
25 * The cherry-pick status
26 */
27 public enum CherryPickStatus {
28 /** */
29 OK {
30 @Override
31 public String toString() {
32 return "Ok"; //$NON-NLS-1$
33 }
34 },
35 /** */
36 FAILED {
37 @Override
38 public String toString() {
39 return "Failed"; //$NON-NLS-1$
40 }
41 },
42 /** */
43 CONFLICTING {
44 @Override
45 public String toString() {
46 return "Conflicting"; //$NON-NLS-1$
47 }
48 }
49 }
50
51 private final CherryPickStatus status;
52
53 private final RevCommit newHead;
54
55 private final List<Ref> cherryPickedRefs;
56
57 private final Map<String, MergeFailureReason> failingPaths;
58
59 /**
60 * Constructor for CherryPickResult
61 *
62 * @param newHead
63 * commit the head points at after this cherry-pick
64 * @param cherryPickedRefs
65 * list of successfully cherry-picked <code>Ref</code>'s
66 */
67 public CherryPickResult(RevCommit newHead, List<Ref> cherryPickedRefs) {
68 this.status = CherryPickStatus.OK;
69 this.newHead = newHead;
70 this.cherryPickedRefs = cherryPickedRefs;
71 this.failingPaths = null;
72 }
73
74 /**
75 * Constructor for CherryPickResult
76 *
77 * @param failingPaths
78 * list of paths causing this cherry-pick to fail (see
79 * {@link org.eclipse.jgit.merge.ResolveMerger#getFailingPaths()}
80 * for details)
81 */
82 public CherryPickResult(Map<String, MergeFailureReason> failingPaths) {
83 this.status = CherryPickStatus.FAILED;
84 this.newHead = null;
85 this.cherryPickedRefs = null;
86 this.failingPaths = failingPaths;
87 }
88
89 private CherryPickResult(CherryPickStatus status) {
90 this.status = status;
91 this.newHead = null;
92 this.cherryPickedRefs = null;
93 this.failingPaths = null;
94 }
95
96 /**
97 * A <code>CherryPickResult</code> with status
98 * {@link CherryPickStatus#CONFLICTING}
99 */
100 public static final CherryPickResultml#CherryPickResult">CherryPickResult CONFLICT = new CherryPickResult(
101 CherryPickStatus.CONFLICTING);
102
103 /**
104 * Get status
105 *
106 * @return the status this cherry-pick resulted in
107 */
108 public CherryPickStatus getStatus() {
109 return status;
110 }
111
112 /**
113 * Get the new head after this cherry-pick
114 *
115 * @return the commit the head points at after this cherry-pick,
116 * <code>null</code> if {@link #getStatus} is not
117 * {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#OK}
118 */
119 public RevCommit getNewHead() {
120 return newHead;
121 }
122
123 /**
124 * Get the cherry-picked {@code Ref}s
125 *
126 * @return the list of successfully cherry-picked <code>Ref</code>'s,
127 * <code>null</code> if {@link #getStatus} is not
128 * {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#OK}
129 */
130 public List<Ref> getCherryPickedRefs() {
131 return cherryPickedRefs;
132 }
133
134 /**
135 * Get the list of paths causing this cherry-pick to fail
136 *
137 * @return the list of paths causing this cherry-pick to fail (see
138 * {@link org.eclipse.jgit.merge.ResolveMerger#getFailingPaths()}
139 * for details), <code>null</code> if {@link #getStatus} is not
140 * {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#FAILED}
141 */
142 public Map<String, MergeFailureReason> getFailingPaths() {
143 return failingPaths;
144 }
145 }