use of com.virtuslab.branchlayout.api.EntryDoesNotExistException in project git-machete-intellij-plugin by VirtusLab.
the class SlideInBackgroundable method run.
@Override
@UIThreadUnsafe
public void run(ProgressIndicator indicator) {
preSlideInRunnable.run();
// `preSlideInRunnable` may perform some sneakily-asynchronous operations (e.g. checkoutRemoteBranch).
// The high-level method used within the runnable do not allow us to schedule the tasks after them.
// (Stepping deeper is not an option since we would lose some important logic or become very dependent on the internals of git4idea).
// Hence we wait for the creation of the branch (with exponential backoff).
waitForCreationOfLocalBranch();
Path macheteFilePath = getMacheteFilePath(gitRepository);
IBranchLayoutEntry childEntryByName = branchLayout.findEntryByName(slideInOptions.getName()).getOrNull();
IBranchLayoutEntry entryToSlideIn;
IBranchLayout targetBranchLayout;
if (childEntryByName != null) {
if (slideInOptions.shouldReattach()) {
entryToSlideIn = childEntryByName;
targetBranchLayout = branchLayout;
} else {
entryToSlideIn = childEntryByName.withChildren(List.empty());
targetBranchLayout = branchLayout.slideOut(slideInOptions.getName());
}
} else {
entryToSlideIn = new BranchLayoutEntry(slideInOptions.getName(), /* customAnnotation */
null, /* children */
List.empty());
targetBranchLayout = branchLayout;
}
IBranchLayout newBranchLayout;
try {
newBranchLayout = targetBranchLayout.slideIn(parentName, entryToSlideIn);
} catch (EntryDoesNotExistException e) {
notifyError(format(getString("action.GitMachete.BaseSlideInBranchBelowAction.notification.message.entry-does-not-exist"), parentName), e);
return;
} catch (EntryIsDescendantOfException e) {
notifyError(format(getString("action.GitMachete.BaseSlideInBranchBelowAction.notification.message.entry-is-descendant-of"), entryToSlideIn.getName(), parentName), e);
return;
}
final IBranchLayout finalNewBranchLayout = newBranchLayout;
Try.run(() -> branchLayoutWriter.write(macheteFilePath, finalNewBranchLayout, /* backupOldLayout */
true)).onFailure(t -> IntelliJNotificationCompat.notifyError(project, /* title */
getString("action.GitMachete.BaseSlideInBranchBelowAction.notification.title.branch-layout-write-fail"), getMessageOrEmpty(t)));
}
Aggregations