use of org.eclipse.jgit.api.errors.RefNotAdvertisedException 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