Search in sources :

Example 1 with MergeConflictHandler

use of org.archicontribs.modelrepository.grafico.MergeConflictHandler in project archi-modelrepository-plugin by archi-contribs.

the class RevertCommitAction method run.

@Override
public void run() {
    // Offer to save the model if open and dirty
    // We need to do this to keep grafico and temp files in sync
    IArchimateModel model = getRepository().locateModel();
    if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
        if (!offerToSaveModel(model)) {
            return;
        }
    }
    // Do the Grafico Export first
    try {
        getRepository().exportModelToGraficoFiles();
    } catch (IOException ex) {
        displayErrorDialog(Messages.RevertCommitAction_0, ex);
        return;
    }
    // Then offer to Commit
    try {
        if (getRepository().hasChangesToCommit()) {
            if (!offerToCommitChanges()) {
                return;
            }
        }
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.RevertCommitAction_3, ex);
        return;
    }
    // Revert
    try (Git git = Git.open(getRepository().getLocalRepositoryFolder())) {
        RevertCommand revertCommand = doRevertCommand(git);
        MergeResult failingResult = revertCommand.getFailingResult();
        if (failingResult != null) {
            MergeConflictHandler handler = new MergeConflictHandler(failingResult, getRepository(), fWindow.getShell());
            boolean result = handler.checkForMergeConflicts();
            if (result) {
                handler.mergeAndCommit(Messages.RevertCommitAction_4, false);
            } else {
                // User cancelled - we assume user has committed all changes so we can reset
                handler.resetToLocalState();
            }
        } else {
            new GraficoModelLoader(getRepository()).loadModel();
        }
        // Save the checksum
        getRepository().saveChecksum();
        notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.RevertCommitAction_1, ex);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) RevertCommand(org.eclipse.jgit.api.RevertCommand) MergeResult(org.eclipse.jgit.api.MergeResult) IOException(java.io.IOException) MergeConflictHandler(org.archicontribs.modelrepository.grafico.MergeConflictHandler) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IArchimateModel (com.archimatetool.model.IArchimateModel)1 IOException (java.io.IOException)1 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)1 MergeConflictHandler (org.archicontribs.modelrepository.grafico.MergeConflictHandler)1 Git (org.eclipse.jgit.api.Git)1 MergeResult (org.eclipse.jgit.api.MergeResult)1 RevertCommand (org.eclipse.jgit.api.RevertCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1