use of org.archicontribs.modelrepository.merge.MergeConflictHandler in project archi-modelrepository-plugin by archi-contribs.
the class MergeBranchAction method merge.
private int merge(BranchInfo currentBranch, BranchInfo branchToMerge, ProgressMonitorDialog pmDialog) throws GitAPIException, IOException {
pmDialog.getProgressMonitor().subTask(Messages.MergeBranchAction_13);
// update dialog
Display.getCurrent().readAndDispatch();
try (Git git = Git.open(getRepository().getLocalRepositoryFolder())) {
ObjectId mergeBase = git.getRepository().resolve(branchToMerge.getShortName());
String mergeMessage = NLS.bind(Messages.MergeBranchAction_2, branchToMerge.getShortName(), currentBranch.getShortName());
MergeResult mergeResult = git.merge().include(mergeBase).setCommit(true).setFastForward(FastForwardMode.FF).setStrategy(MergeStrategy.RECURSIVE).setSquash(false).setMessage(mergeMessage).call();
MergeStatus status = mergeResult.getMergeStatus();
// Conflict
if (status == MergeStatus.CONFLICTING) {
// Try to handle the merge conflict
MergeConflictHandler handler = new MergeConflictHandler(mergeResult, branchToMerge.getShortName(), getRepository(), fWindow.getShell());
try {
handler.init(pmDialog.getProgressMonitor());
} catch (IOException | GitAPIException ex) {
// Clean up
handler.resetToLocalState();
if (ex instanceof CanceledException) {
return MERGE_STATUS_MERGE_CANCEL;
}
throw ex;
}
String dialogMessage = NLS.bind(Messages.MergeBranchAction_10, branchToMerge.getShortName(), currentBranch.getShortName());
pmDialog.getShell().setVisible(false);
boolean result = handler.openConflictsDialog(dialogMessage);
pmDialog.getShell().setVisible(true);
if (result) {
handler.merge();
} else // User cancelled - so we reset
{
handler.resetToLocalState();
return MERGE_STATUS_MERGE_CANCEL;
}
}
// Reload the model from the Grafico XML files
GraficoModelLoader loader = new GraficoModelLoader(getRepository());
loader.loadModel();
// Do a commit if needed
if (getRepository().hasChangesToCommit()) {
mergeMessage = NLS.bind(Messages.MergeBranchAction_3, branchToMerge.getShortName(), currentBranch.getShortName());
// Did we restore any missing objects?
String restoredObjects = loader.getRestoredObjectsAsString();
// Add to commit message
if (restoredObjects != null) {
// $NON-NLS-1$ //$NON-NLS-2$
mergeMessage += "\n\n" + Messages.RefreshModelAction_3 + "\n" + restoredObjects;
}
// IMPORTANT!!! "amend" has to be false after a merge conflict or else the commit will be orphaned
getRepository().commitChanges(mergeMessage, false);
}
}
return MERGE_STATUS_OK;
}
use of org.archicontribs.modelrepository.merge.MergeConflictHandler in project archi-modelrepository-plugin by archi-contribs.
the class RefreshModelAction method pull.
protected int pull(UsernamePassword npw, ProgressMonitorDialog pmDialog) throws IOException, GitAPIException {
PullResult pullResult = null;
pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_6);
// update dialog
Display.getCurrent().readAndDispatch();
try {
pullResult = getRepository().pullFromRemote(npw, new ProgressMonitorWrapper(pmDialog.getProgressMonitor()));
} catch (Exception ex) {
// So quietly absorb this and return OK
if (ex instanceof RefNotAdvertisedException) {
return PULL_STATUS_OK;
}
throw ex;
}
// Check for tracking updates
FetchResult fetchResult = pullResult.getFetchResult();
boolean newTrackingRefUpdates = fetchResult != null && !fetchResult.getTrackingRefUpdates().isEmpty();
// Merge is already up to date...
if (pullResult.getMergeResult().getMergeStatus() == MergeStatus.ALREADY_UP_TO_DATE) {
// Check if any tracked refs were updated
if (newTrackingRefUpdates) {
return PULL_STATUS_OK;
}
return PULL_STATUS_UP_TO_DATE;
}
pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_7);
BranchStatus branchStatus = getRepository().getBranchStatus();
// Setup the Graphico Model Loader
GraficoModelLoader loader = new GraficoModelLoader(getRepository());
// Merge failure
if (!pullResult.isSuccessful() && pullResult.getMergeResult().getMergeStatus() == MergeStatus.CONFLICTING) {
// Get the remote ref name
String remoteRef = branchStatus.getCurrentRemoteBranch().getFullName();
// Try to handle the merge conflict
MergeConflictHandler handler = new MergeConflictHandler(pullResult.getMergeResult(), remoteRef, getRepository(), fWindow.getShell());
try {
handler.init(pmDialog.getProgressMonitor());
} catch (IOException | GitAPIException ex) {
// Clean up
handler.resetToLocalState();
if (ex instanceof CanceledException) {
return PULL_STATUS_MERGE_CANCEL;
}
throw ex;
}
String dialogMessage = NLS.bind(Messages.RefreshModelAction_4, branchStatus.getCurrentLocalBranch().getShortName());
pmDialog.getShell().setVisible(false);
boolean result = handler.openConflictsDialog(dialogMessage);
pmDialog.getShell().setVisible(true);
if (result) {
handler.merge();
} else // User cancelled - we assume they committed all changes so we can reset
{
handler.resetToLocalState();
return PULL_STATUS_MERGE_CANCEL;
}
// We now have to check if model can be reloaded
pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_8);
// Reload the model from the Grafico XML files
try {
loader.loadModel();
} catch (IOException ex) {
// Clean up
handler.resetToLocalState();
throw ex;
}
} else {
// Reload the model from the Grafico XML files
pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_8);
loader.loadModel();
}
// Do a commit if needed
if (getRepository().hasChangesToCommit()) {
pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_9);
String commitMessage = NLS.bind(Messages.RefreshModelAction_1, branchStatus.getCurrentLocalBranch().getShortName());
// Did we restore any missing objects?
String restoredObjects = loader.getRestoredObjectsAsString();
// Add to commit message
if (restoredObjects != null) {
// $NON-NLS-1$ //$NON-NLS-2$
commitMessage += "\n\n" + Messages.RefreshModelAction_3 + "\n" + restoredObjects;
}
// TODO - not sure if amend should be false or true here?
getRepository().commitChanges(commitMessage, false);
}
return PULL_STATUS_OK;
}
Aggregations