Search in sources :

Example 1 with RefNotAdvertisedException

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;
}
Also used : CanceledException(org.eclipse.jgit.api.errors.CanceledException) FetchResult(org.eclipse.jgit.transport.FetchResult) MergeConflictHandler(org.archicontribs.modelrepository.merge.MergeConflictHandler) IOException(java.io.IOException) PullResult(org.eclipse.jgit.api.PullResult) RefNotAdvertisedException(org.eclipse.jgit.api.errors.RefNotAdvertisedException) GeneralSecurityException(java.security.GeneralSecurityException) CanceledException(org.eclipse.jgit.api.errors.CanceledException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RefNotAdvertisedException(org.eclipse.jgit.api.errors.RefNotAdvertisedException) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) BranchStatus(org.archicontribs.modelrepository.grafico.BranchStatus)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 BranchStatus (org.archicontribs.modelrepository.grafico.BranchStatus)1 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)1 MergeConflictHandler (org.archicontribs.modelrepository.merge.MergeConflictHandler)1 PullResult (org.eclipse.jgit.api.PullResult)1 CanceledException (org.eclipse.jgit.api.errors.CanceledException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 RefNotAdvertisedException (org.eclipse.jgit.api.errors.RefNotAdvertisedException)1 FetchResult (org.eclipse.jgit.transport.FetchResult)1