Lines 58-63
Link Here
|
58 |
import org.netbeans.modules.git.client.GitClient; |
58 |
import org.netbeans.modules.git.client.GitClient; |
59 |
import org.netbeans.libs.git.GitException; |
59 |
import org.netbeans.libs.git.GitException; |
60 |
import org.netbeans.libs.git.GitMergeResult; |
60 |
import org.netbeans.libs.git.GitMergeResult; |
|
|
61 |
import org.netbeans.libs.git.GitRepository.FastForwardOption; |
61 |
import org.netbeans.libs.git.GitRevisionInfo; |
62 |
import org.netbeans.libs.git.GitRevisionInfo; |
62 |
import org.netbeans.libs.git.progress.ProgressMonitor; |
63 |
import org.netbeans.libs.git.progress.ProgressMonitor; |
63 |
import org.netbeans.modules.git.Git; |
64 |
import org.netbeans.modules.git.Git; |
Lines 94-100
Link Here
|
94 |
} |
95 |
} |
95 |
|
96 |
|
96 |
public void mergeRevision (final File repository, String preselectedRevision) { |
97 |
public void mergeRevision (final File repository, String preselectedRevision) { |
97 |
final MergeRevision mergeRevision = new MergeRevision(repository, new File[0], preselectedRevision); |
98 |
FastForwardOption defaultFFOption = FastForwardOption.FAST_FORWARD; |
|
|
99 |
try { |
100 |
defaultFFOption = Git.getInstance().getRepository(repository).getDefaultFastForwardOption(); |
101 |
} catch (GitException ex) { |
102 |
LOG.log(Level.INFO, null, ex); |
103 |
} |
104 |
final MergeRevision mergeRevision = new MergeRevision(repository, new File[0], preselectedRevision, defaultFFOption); |
98 |
if (mergeRevision.show()) { |
105 |
if (mergeRevision.show()) { |
99 |
GitProgressSupport supp = new GitProgressSupport() { |
106 |
GitProgressSupport supp = new GitProgressSupport() { |
100 |
private String revision; |
107 |
private String revision; |
Lines 109-128
Link Here
|
109 |
client.addNotificationListener(new DefaultFileListener(new File[] { repository })); |
116 |
client.addNotificationListener(new DefaultFileListener(new File[] { repository })); |
110 |
revision = mergeRevision.getRevision(); |
117 |
revision = mergeRevision.getRevision(); |
111 |
LOG.log(Level.FINE, "Merging revision {0} into HEAD", revision); //NOI18N |
118 |
LOG.log(Level.FINE, "Merging revision {0} into HEAD", revision); //NOI18N |
112 |
boolean cont; |
119 |
MergeContext ctx = new MergeContext(revision, mergeRevision.getFFOption()); |
113 |
MergeResultProcessor mrp = new MergeResultProcessor(client, repository, revision, getLogger(), getProgressMonitor()); |
120 |
MergeResultProcessor mrp = new MergeResultProcessor(client, repository, ctx, getLogger(), getProgressMonitor()); |
114 |
do { |
121 |
do { |
115 |
cont = false; |
122 |
ctx.setContinue(false); |
116 |
try { |
123 |
try { |
117 |
GitMergeResult result = client.merge(revision, getProgressMonitor()); |
124 |
GitMergeResult result = client.merge(revision, ctx.getFFOption(), getProgressMonitor()); |
118 |
mrp.processResult(result); |
125 |
mrp.processResult(result); |
119 |
} catch (GitException.CheckoutConflictException ex) { |
126 |
} catch (GitException.CheckoutConflictException ex) { |
120 |
if (LOG.isLoggable(Level.FINE)) { |
127 |
if (LOG.isLoggable(Level.FINE)) { |
121 |
LOG.log(Level.FINE, "Local modifications in WT during merge: {0} - {1}", new Object[] { repository, Arrays.asList(ex.getConflicts()) }); //NOI18N |
128 |
LOG.log(Level.FINE, "Local modifications in WT during merge: {0} - {1}", new Object[] { repository, Arrays.asList(ex.getConflicts()) }); //NOI18N |
122 |
} |
129 |
} |
123 |
cont = mrp.resolveLocalChanges(ex.getConflicts()); |
130 |
ctx.setContinue(mrp.resolveLocalChanges(ex.getConflicts())); |
124 |
} |
131 |
} |
125 |
} while (cont); |
132 |
} while (ctx.isContinue() && !isCanceled()); |
126 |
return null; |
133 |
return null; |
127 |
} |
134 |
} |
128 |
}, repository); |
135 |
}, repository); |
Lines 139-158
Link Here
|
139 |
} |
146 |
} |
140 |
} |
147 |
} |
141 |
|
148 |
|
|
|
149 |
@NbBundle.Messages({ |
150 |
"LBL_Merge.failed.title=Cannot Merge", |
151 |
"MSG_Merge.failed.aborted.text=Merge requires a merge commit and cannot be a fast-forward merge.\n\n" |
152 |
+ "Do you want to restart the merge and allow merge commits (--ff option)." |
153 |
}) |
142 |
public static class MergeResultProcessor extends ResultProcessor { |
154 |
public static class MergeResultProcessor extends ResultProcessor { |
143 |
|
155 |
|
144 |
private final OutputLogger logger; |
156 |
private final OutputLogger logger; |
145 |
private final String revision; |
|
|
146 |
private final GitBranch current; |
157 |
private final GitBranch current; |
|
|
158 |
private final MergeContext context; |
147 |
|
159 |
|
148 |
public MergeResultProcessor (GitClient client, File repository, String revision, OutputLogger logger, ProgressMonitor pm) { |
160 |
public MergeResultProcessor (GitClient client, File repository, MergeContext context, OutputLogger logger, ProgressMonitor pm) { |
149 |
super(client, repository, revision, pm); |
161 |
super(client, repository, context.getRevision(), pm); |
|
|
162 |
this.context = context; |
150 |
this.current = RepositoryInfo.getInstance(repository).getActiveBranch(); |
163 |
this.current = RepositoryInfo.getInstance(repository).getActiveBranch(); |
151 |
this.revision = revision; |
|
|
152 |
this.logger = logger; |
164 |
this.logger = logger; |
153 |
} |
165 |
} |
154 |
|
166 |
|
155 |
public void processResult (GitMergeResult result) { |
167 |
public void processResult (GitMergeResult result) { |
|
|
168 |
String revision = context.getRevision(); |
156 |
StringBuilder sb = new StringBuilder(NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result", result.getMergeStatus().toString())); //NOI18N |
169 |
StringBuilder sb = new StringBuilder(NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result", result.getMergeStatus().toString())); //NOI18N |
157 |
GitRevisionInfo info = null; |
170 |
GitRevisionInfo info = null; |
158 |
if (result.getNewHead() != null) { |
171 |
if (result.getNewHead() != null) { |
Lines 163-168
Link Here
|
163 |
} |
176 |
} |
164 |
} |
177 |
} |
165 |
boolean logActions = false; |
178 |
boolean logActions = false; |
|
|
179 |
final Action openAction = logger.getOpenOutputAction(); |
166 |
switch (result.getMergeStatus()) { |
180 |
switch (result.getMergeStatus()) { |
167 |
case ALREADY_UP_TO_DATE: |
181 |
case ALREADY_UP_TO_DATE: |
168 |
sb.append(NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result.alreadyUpToDate", revision)); //NOI18N |
182 |
sb.append(NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result.alreadyUpToDate", revision)); //NOI18N |
Lines 183-189
Link Here
|
183 |
resolveConflicts(result.getConflicts()); |
197 |
resolveConflicts(result.getConflicts()); |
184 |
break; |
198 |
break; |
185 |
case FAILED: |
199 |
case FAILED: |
186 |
final Action openAction = logger.getOpenOutputAction(); |
|
|
187 |
if (openAction != null) { |
200 |
if (openAction != null) { |
188 |
try { |
201 |
try { |
189 |
EventQueue.invokeAndWait(new Runnable() { |
202 |
EventQueue.invokeAndWait(new Runnable() { |
Lines 201-206
Link Here
|
201 |
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message( |
214 |
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message( |
202 |
NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result.failed", revision), NotifyDescriptor.ERROR_MESSAGE)); //NOI18N |
215 |
NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result.failed", revision), NotifyDescriptor.ERROR_MESSAGE)); //NOI18N |
203 |
break; |
216 |
break; |
|
|
217 |
case ABORTED: |
218 |
Object o = DialogDisplayer.getDefault().notify(new NotifyDescriptor(Bundle.MSG_Merge_failed_aborted_text(), |
219 |
Bundle.LBL_Merge_failed_title(), NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, |
220 |
new Object[] { NotifyDescriptor.YES_OPTION, NotifyDescriptor.NO_OPTION }, |
221 |
NotifyDescriptor.NO_OPTION)); |
222 |
if (o == NotifyDescriptor.YES_OPTION) { |
223 |
context.setFFOption(FastForwardOption.FAST_FORWARD); |
224 |
context.setContinue(true); |
225 |
} else { |
226 |
if (openAction != null) { |
227 |
try { |
228 |
EventQueue.invokeAndWait(new Runnable() { |
229 |
@Override |
230 |
public void run () { |
231 |
openAction.actionPerformed(new ActionEvent(MergeResultProcessor.this, ActionEvent.ACTION_PERFORMED, null)); |
232 |
} |
233 |
}); |
234 |
} catch (InterruptedException | InvocationTargetException ex) { |
235 |
} |
236 |
} |
237 |
} |
238 |
sb.append(NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result.aborted", revision)); //NOI18N |
239 |
break; |
204 |
case NOT_SUPPORTED: |
240 |
case NOT_SUPPORTED: |
205 |
sb.append(NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result.unsupported")); //NOI18N |
241 |
sb.append(NbBundle.getMessage(MergeRevisionAction.class, "MSG_MergeRevisionAction.result.unsupported")); //NOI18N |
206 |
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message( |
242 |
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message( |
Lines 216-219
Link Here
|
216 |
} |
252 |
} |
217 |
} |
253 |
} |
218 |
} |
254 |
} |
|
|
255 |
|
256 |
public static class MergeContext { |
257 |
private FastForwardOption ffOption; |
258 |
private final String revision; |
259 |
private boolean cont; |
260 |
|
261 |
public MergeContext (String revision, FastForwardOption ffOption) { |
262 |
this.revision = revision; |
263 |
this.ffOption = ffOption; |
264 |
} |
265 |
|
266 |
public String getRevision () { |
267 |
return revision; |
268 |
} |
269 |
|
270 |
public FastForwardOption getFFOption () { |
271 |
return ffOption; |
272 |
} |
273 |
|
274 |
private void setFFOption (FastForwardOption ffOption) { |
275 |
this.ffOption = ffOption; |
276 |
} |
277 |
|
278 |
public void setContinue (boolean cont) { |
279 |
this.cont = cont; |
280 |
} |
281 |
|
282 |
public boolean isContinue () { |
283 |
return cont; |
284 |
} |
285 |
|
286 |
} |
219 |
} |
287 |
} |