use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class MergeCurrentBranchFastForwardOnlyBackgroundable method createGitLineHandler.
@Override
@UIThreadUnsafe
@Nullable
protected GitLineHandler createGitLineHandler() {
val handler = new GitLineHandler(project, gitRepository.getRoot(), GitCommand.MERGE);
handler.addParameters("--ff-only");
handler.addParameters(targetBranch.getFullName());
return handler;
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe 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)));
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class BaseOverrideForkPointAction method setOverrideForkPointConfigValues.
@UIThreadUnsafe
private void setOverrideForkPointConfigValues(Project project, VirtualFile root, String branchName, ICommitOfManagedBranch forkPoint, ICommitOfManagedBranch ancestorCommit) {
val section = "machete";
val subsectionPrefix = "overrideForkPoint";
val to = "to";
val whileDescendantOf = "whileDescendantOf";
// Section spans the characters before the first dot
// Name spans the characters after the last dot
// Subsection is everything else
val toKey = "${section}.${subsectionPrefix}.${branchName}.${to}";
val whileDescendantOfKey = "${section}.${subsectionPrefix}.${branchName}.${whileDescendantOf}";
try {
GitConfigUtil.setValue(project, root, toKey, forkPoint.getHash());
} catch (VcsException e) {
LOG.info("Attempt to set '${toKey}' git config value failed: " + e.getMessage());
}
try {
GitConfigUtil.setValue(project, root, whileDescendantOfKey, ancestorCommit.getHash());
} catch (VcsException e) {
LOG.info("Attempt to get '${whileDescendantOf}' git config value failed: " + e.getMessage());
}
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class BaseResetBranchToRemoteAction method doResetCurrentBranchToRemoteWithKeep.
protected void doResetCurrentBranchToRemoteWithKeep(Project project, GitRepository gitRepository, ILocalBranchReference localBranch, IRemoteTrackingBranchReference remoteTrackingBranch) {
new Task.Backgroundable(project, getString("action.GitMachete.BaseResetBranchToRemoteAction.task-title"), /* canBeCancelled */
true) {
@Override
@UIThreadUnsafe
public void run(ProgressIndicator indicator) {
val localBranchName = localBranch.getName();
val remoteTrackingBranchName = remoteTrackingBranch.getName();
log().debug(() -> "Resetting '${localBranchName}' to '${remoteTrackingBranchName}'");
try (AccessToken ignored = DvcsUtil.workingTreeChangeStarted(project, getString("action.GitMachete.BaseResetBranchToRemoteAction.task-title"))) {
GitLineHandler resetHandler = new GitLineHandler(project, gitRepository.getRoot(), GitCommand.RESET);
resetHandler.addParameters("--keep");
resetHandler.addParameters(remoteTrackingBranchName);
resetHandler.endOptions();
val localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(gitRepository.getRoot(), RESET);
resetHandler.addLineListener(localChangesDetector);
GitCommandResult result = Git.getInstance().runCommand(resetHandler);
if (result.success()) {
IntelliJNotificationCompat.notifySuccess(project, /* title */
"", format(getString("action.GitMachete.BaseResetBranchToRemoteAction.notification.title.reset-success"), localBranchName));
log().debug(() -> "Branch '${localBranchName}' has been reset to '${remoteTrackingBranchName}");
} else if (localChangesDetector.wasMessageDetected()) {
localChangesWouldBeOverwrittenHelper_showErrorNotification(project, gitRepository.getRoot(), /* operationName */
"Reset", localChangesDetector.getRelativeFilePaths());
} else {
log().error(result.getErrorOutputAsJoinedString());
IntelliJNotificationCompat.notifyError(project, VCS_NOTIFIER_TITLE, result.getErrorOutputAsHtmlString());
}
val repositoryRoot = getMainDirectory(gitRepository);
GitRepositoryManager.getInstance(project).updateRepository(repositoryRoot);
VfsUtil.markDirtyAndRefresh(/* async */
false, /* recursive */
true, /* reloadChildren */
false, repositoryRoot);
}
}
}.queue();
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class FetchAllRemotesAction method actionPerformed.
@Override
@UIEffect
public void actionPerformed(AnActionEvent anActionEvent) {
log().debug("Performing");
val project = getProject(anActionEvent);
val gitRepository = getSelectedGitRepository(anActionEvent);
String title = getString("action.GitMachete.FetchAllRemotesAction.task-title");
new Task.Backgroundable(project, title, /* canBeCancelled */
true) {
@MonotonicNonNull
private GitFetchResult result = null;
@Override
@UIThreadUnsafe
public void run(ProgressIndicator indicator) {
result = GitFetchSupport.fetchSupport(project).fetchAllRemotes(gitRepository.toJavaList());
if (gitRepository.isDefined()) {
val name = gitRepository.get().getRoot().getName();
lastFetchTimeMillisByRepositoryName.put(name, System.currentTimeMillis());
}
}
@Override
@UIEffect
public void onFinished() {
val result = this.result;
if (result != null) {
result.showNotification();
}
}
}.queue();
}
Aggregations