View Javadoc
1   /*
2    * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@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 org.eclipse.jgit.transport.FetchResult;
13  
14  /**
15   * Encapsulates the result of a {@link org.eclipse.jgit.api.PullCommand}
16   */
17  public class PullResult {
18  	private final FetchResult fetchResult;
19  
20  	private final MergeResult mergeResult;
21  
22  	private final RebaseResult rebaseResult;
23  
24  	private final String fetchedFrom;
25  
26  	PullResult(FetchResult fetchResult, String fetchedFrom,
27  			MergeResult mergeResult) {
28  		this.fetchResult = fetchResult;
29  		this.fetchedFrom = fetchedFrom;
30  		this.mergeResult = mergeResult;
31  		this.rebaseResult = null;
32  	}
33  
34  	PullResult(FetchResult fetchResult, String fetchedFrom,
35  			RebaseResult rebaseResult) {
36  		this.fetchResult = fetchResult;
37  		this.fetchedFrom = fetchedFrom;
38  		this.mergeResult = null;
39  		this.rebaseResult = rebaseResult;
40  	}
41  
42  	/**
43  	 * Get fetch result
44  	 *
45  	 * @return the fetch result, or <code>null</code>
46  	 */
47  	public FetchResult getFetchResult() {
48  		return this.fetchResult;
49  	}
50  
51  	/**
52  	 * Get merge result
53  	 *
54  	 * @return the merge result, or <code>null</code>
55  	 */
56  	public MergeResult getMergeResult() {
57  		return this.mergeResult;
58  	}
59  
60  	/**
61  	 * Get rebase result
62  	 *
63  	 * @return the rebase result, or <code>null</code>
64  	 */
65  	public RebaseResult getRebaseResult() {
66  		return this.rebaseResult;
67  	}
68  
69  	/**
70  	 * Get name of the remote configuration from which fetch was tried
71  	 *
72  	 * @return the name of the remote configuration from which fetch was tried,
73  	 *         or <code>null</code>
74  	 */
75  	public String getFetchedFrom() {
76  		return this.fetchedFrom;
77  	}
78  
79  	/**
80  	 * Whether the pull was successful
81  	 *
82  	 * @return whether the pull was successful
83  	 */
84  	public boolean isSuccessful() {
85  		if (mergeResult != null)
86  			return mergeResult.getMergeStatus().isSuccessful();
87  		else if (rebaseResult != null)
88  			return rebaseResult.getStatus().isSuccessful();
89  		return true;
90  	}
91  
92  	/** {@inheritDoc} */
93  	@SuppressWarnings("nls")
94  	@Override
95  	public String toString() {
96  		StringBuilder sb = new StringBuilder();
97  		if (fetchResult != null)
98  			sb.append(fetchResult.toString());
99  		else
100 			sb.append("No fetch result");
101 		sb.append("\n");
102 		if (mergeResult != null)
103 			sb.append(mergeResult.toString());
104 		else if (rebaseResult != null)
105 			sb.append(rebaseResult.toString());
106 		else
107 			sb.append("No update result");
108 		return sb.toString();
109 	}
110 }