use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.
the class MergeBranchAction method doOnlineMerge.
private void doOnlineMerge(BranchInfo branchToMerge) throws IOException, GitAPIException, GeneralSecurityException {
// Store currentBranch first
BranchInfo currentBranch = getRepository().getBranchStatus().getCurrentLocalBranch();
PushModelAction pushAction = new PushModelAction(fWindow, getRepository().locateModel());
// Init
int status = pushAction.init();
if (status == RefreshModelAction.USER_CANCEL) {
return;
}
// Check primary key set
if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
return;
}
// Get for this before opening the progress dialog
// UsernamePassword is will be null if using SSH
UsernamePassword npw = getUsernamePassword();
// User cancelled on HTTP
if (npw == null && GraficoUtils.isHTTP(getRepository().getOnlineRepositoryURL())) {
return;
}
// Do main action with PM dialog
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
try {
pmDialog.run(false, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
// Update Proxy
ProxyAuthenticator.update();
monitor.beginTask(Messages.MergeBranchAction_11, -1);
// Pull
int pullStatus = pushAction.pull(npw, pmDialog);
// Push
if (pullStatus == RefreshModelAction.PULL_STATUS_OK || pullStatus == RefreshModelAction.PULL_STATUS_UP_TO_DATE) {
pushAction.push(npw, pmDialog);
} else {
return;
}
// Switch to other branch
pmDialog.getProgressMonitor().subTask(Messages.MergeBranchAction_14);
SwitchBranchAction switchBranchAction = new SwitchBranchAction(fWindow);
switchBranchAction.setRepository(getRepository());
switchBranchAction.switchBranch(branchToMerge, true);
// Pull again
pullStatus = pushAction.pull(npw, pmDialog);
// Push
if (pullStatus == RefreshModelAction.PULL_STATUS_OK || pullStatus == RefreshModelAction.PULL_STATUS_UP_TO_DATE) {
pushAction.push(npw, pmDialog);
} else {
return;
}
// Switch back
pmDialog.getProgressMonitor().subTask(Messages.MergeBranchAction_14);
switchBranchAction.switchBranch(currentBranch, true);
// Merge
merge(currentBranch, branchToMerge, pmDialog);
// Final Push on this branch
pushAction.push(npw, pmDialog);
// Ask user to delete branch (if not master)
DeleteBranchAction deleteBranchAction = new DeleteBranchAction(fWindow);
deleteBranchAction.setRepository(getRepository());
deleteBranchAction.setBranch(branchToMerge);
if (deleteBranchAction.shouldBeEnabled()) {
pmDialog.getShell().setVisible(false);
boolean doDeleteBranch = MessageDialog.openQuestion(fWindow.getShell(), Messages.MergeBranchAction_1, NLS.bind(Messages.MergeBranchAction_9, branchToMerge.getShortName()));
if (doDeleteBranch) {
pmDialog.getShell().setVisible(true);
pmDialog.getProgressMonitor().subTask(Messages.MergeBranchAction_12);
// Branch will have been pushed at this point so BranchInfo is no longer valid to determine if it's just a local branch
deleteBranchAction.deleteBranchAndPush(branchToMerge, npw);
}
}
} catch (Exception ex) {
pmDialog.getShell().setVisible(false);
displayErrorDialog(Messages.MergeBranchAction_1, ex);
} finally {
try {
saveChecksumAndNotifyListeners();
} catch (IOException ex) {
ex.printStackTrace();
}
// Clear Proxy
ProxyAuthenticator.clear();
}
}
});
} catch (InvocationTargetException | InterruptedException ex) {
ex.printStackTrace();
}
}
});
}
use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.
the class ResetToRemoteCommitAction 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 (Exception ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
return;
}
try {
// If there are changes to commit then they'll have to be committed first or abandoned
if (getRepository().hasChangesToCommit()) {
if (!MessageDialog.openConfirm(fWindow.getShell(), Messages.ResetToRemoteCommitAction_0, Messages.ResetToRemoteCommitAction_2)) {
return;
}
} else // Else, confirm
{
boolean response = MessageDialog.openConfirm(fWindow.getShell(), Messages.ResetToRemoteCommitAction_0, Messages.ResetToRemoteCommitAction_3);
if (!response) {
return;
}
}
} catch (Exception ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_4, ex);
return;
}
// Do it!
try {
BranchInfo currentRemoteBranch = getCurrentRemoteBranchInfo();
if (currentRemoteBranch != null) {
getRepository().resetToRef(currentRemoteBranch.getFullName());
}
} catch (Exception ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
}
// Reload the model from the Grafico XML files
try {
new GraficoModelLoader(getRepository()).loadModel();
// Save the checksum
getRepository().saveChecksum();
} catch (IOException ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
}
notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
}
use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.
the class BranchesView method updateActions.
/**
* Update the Local Actions depending on the local selection
* @param selection
*/
private void updateActions() {
BranchInfo branchInfo = (BranchInfo) getBranchesViewer().getStructuredSelection().getFirstElement();
fActionSwitchBranch.setBranch(branchInfo);
fActionAddBranch.setBranch(branchInfo);
fActionMergeBranch.setBranch(branchInfo);
fActionDeleteBranch.setBranch(branchInfo);
fActionDeleteStaleBranches.setSelection(getBranchesViewer().getStructuredSelection());
}
use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.
the class BranchesViewer method doSetInput.
void doSetInput(IArchiRepository archiRepo) {
// Get BranchStatus
BranchStatus branchStatus = null;
try {
branchStatus = archiRepo.getBranchStatus();
} catch (IOException | GitAPIException ex) {
ex.printStackTrace();
}
setInput(branchStatus);
// Set selection to current branch
if (branchStatus != null) {
BranchInfo branchInfo = branchStatus.getCurrentLocalBranch();
if (branchInfo != null) {
setSelection(new StructuredSelection(branchInfo));
}
}
// And relayout
getControl().getParent().layout();
}
use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.
the class HistoryView method updateActions.
/**
* Update the Local Actions depending on the local selection
* @param selection
*/
private void updateActions() {
RevCommit commit = (RevCommit) getHistoryViewer().getStructuredSelection().getFirstElement();
// Set commit in these actions
fActionExtractCommit.setCommit(commit);
fActionRestoreCommit.setCommit(commit);
// Also set the commit in the Comment Viewer
fCommentViewer.setCommit(commit);
// Update these actions
fActionUndoLastCommit.update();
fActionResetToRemoteCommit.update();
// Disable actions if our selected branch is not actually the current branch
BranchInfo selectedBranch = (BranchInfo) getBranchesViewer().getStructuredSelection().getFirstElement();
boolean isCurrentBranch = selectedBranch != null && selectedBranch.isCurrentBranch();
fActionRestoreCommit.setEnabled(isCurrentBranch && fActionRestoreCommit.isEnabled());
fActionUndoLastCommit.setEnabled(isCurrentBranch && fActionUndoLastCommit.isEnabled());
fActionResetToRemoteCommit.setEnabled(isCurrentBranch && fActionResetToRemoteCommit.isEnabled());
}
Aggregations