Search in sources :

Example 21 with UIThreadUnsafe

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;
}
Also used : lombok.val(lombok.val) GitLineHandler(git4idea.commands.GitLineHandler) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 22 with UIThreadUnsafe

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)));
}
Also used : GitVfsUtils.getMacheteFilePath(com.virtuslab.gitmachete.frontend.vfsutils.GitVfsUtils.getMacheteFilePath) Path(java.nio.file.Path) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) BranchLayoutEntry(com.virtuslab.branchlayout.api.BranchLayoutEntry) IBranchLayoutEntry(com.virtuslab.branchlayout.api.IBranchLayoutEntry) EntryDoesNotExistException(com.virtuslab.branchlayout.api.EntryDoesNotExistException) IBranchLayout(com.virtuslab.branchlayout.api.IBranchLayout) EntryIsDescendantOfException(com.virtuslab.branchlayout.api.EntryIsDescendantOfException) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 23 with UIThreadUnsafe

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());
    }
}
Also used : lombok.val(lombok.val) VcsException(com.intellij.openapi.vcs.VcsException) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 24 with UIThreadUnsafe

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();
}
Also used : lombok.val(lombok.val) Task(com.intellij.openapi.progress.Task) GitLineHandler(git4idea.commands.GitLineHandler) GitLocalChangesWouldBeOverwrittenDetector(git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AccessToken(com.intellij.openapi.application.AccessToken) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe) GitCommandResult(git4idea.commands.GitCommandResult)

Example 25 with UIThreadUnsafe

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();
}
Also used : lombok.val(lombok.val) Task(com.intellij.openapi.progress.Task) UIEffect(org.checkerframework.checker.guieffect.qual.UIEffect) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) GitFetchResult(git4idea.fetch.GitFetchResult) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GitMacheteBundle.getString(com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe) UIEffect(org.checkerframework.checker.guieffect.qual.UIEffect)

Aggregations

UIThreadUnsafe (com.virtuslab.qual.guieffect.UIThreadUnsafe)27 lombok.val (lombok.val)25 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 Task (com.intellij.openapi.progress.Task)8 GitMacheteBundle.getString (com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString)8 UIEffect (org.checkerframework.checker.guieffect.qual.UIEffect)6 VcsException (com.intellij.openapi.vcs.VcsException)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 GitCoreException (com.virtuslab.gitcore.api.GitCoreException)3 GitMacheteException (com.virtuslab.gitmachete.backend.api.GitMacheteException)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 AccessToken (com.intellij.openapi.application.AccessToken)2 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 IManagedBranchSnapshot (com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot)2 DeleteBranchOnSlideOutSuggestionDialog (com.virtuslab.gitmachete.frontend.actions.dialogs.DeleteBranchOnSlideOutSuggestionDialog)2 IExpectsKeyGitMacheteRepository (com.virtuslab.gitmachete.frontend.actions.expectedkeys.IExpectsKeyGitMacheteRepository)2 IEnhancedLambdaLogger (com.virtuslab.logger.IEnhancedLambdaLogger)2 GitRebaseParams (git4idea.branch.GitRebaseParams)2