Search in sources :

Example 1 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class FetchBackgroundable method run.

@Override
@UIThreadUnsafe
public void run(ProgressIndicator indicator) {
    if (taskSubtitle != null) {
        // This method set a text under a progress bar (despite of docstring)
        indicator.setText(taskSubtitle);
    }
    val fetchSupport = GitFetchSupport.fetchSupport(project);
    GitRemote remote = remoteName.equals(LOCAL_REPOSITORY_NAME) ? GitRemote.DOT : GitUtil.findRemoteByName(gitRepository, remoteName);
    if (remote == null) {
        // This is generally NOT expected, the task should never be triggered
        // for an invalid remote in the first place.
        LOG.warn("Remote '${remoteName}' does not exist");
        return;
    }
    val fetchResult = fetchSupport.fetch(gitRepository, remote, refspec);
    fetchResult.showNotificationIfFailed(failureNotificationText);
    fetchResult.throwExceptionIfFailed();
}
Also used : lombok.val(lombok.val) GitRemote(git4idea.repo.GitRemote) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 2 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class GitCommandUpdatingCurrentBranchBackgroundable method deriveGitUpdatedRanges.

@UIThreadUnsafe
@Nullable
private GitUpdatedRanges deriveGitUpdatedRanges(String targetBranchName) {
    GitUpdatedRanges updatedRanges = null;
    val currentBranch = gitRepository.getCurrentBranch();
    if (currentBranch != null) {
        GitBranch targetBranch = gitRepository.getBranches().findBranchByName(targetBranchName);
        if (targetBranch != null) {
            GitBranchPair refPair = new GitBranchPair(currentBranch, targetBranch);
            updatedRanges = GitUpdatedRanges.calcInitialPositions(project, java.util.Collections.singletonMap(gitRepository, refPair));
        } else {
            LOG.warn("Couldn't find the branch with name '${targetBranchName}'");
        }
    }
    return updatedRanges;
}
Also used : lombok.val(lombok.val) GitBranchPair(git4idea.branch.GitBranchPair) GitBranch(git4idea.GitBranch) GitUpdatedRanges(git4idea.update.GitUpdatedRanges) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 3 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class GitCommandUpdatingCurrentBranchBackgroundable method run.

@Override
@UIThreadUnsafe
public final void run(ProgressIndicator indicator) {
    val handler = createGitLineHandler();
    if (handler == null) {
        return;
    }
    val localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(gitRepository.getRoot(), MERGE);
    val untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(gitRepository.getRoot());
    handler.addLineListener(localChangesDetector);
    handler.addLineListener(untrackedFilesDetector);
    Label beforeLabel = LocalHistory.getInstance().putSystemLabel(project, /* name */
    "Before update");
    GitUpdatedRanges updatedRanges = deriveGitUpdatedRanges(getTargetBranchName());
    String beforeRevision = gitRepository.getCurrentRevision();
    try (AccessToken ignore = DvcsUtil.workingTreeChangeStarted(project, getOperationName())) {
        GitCommandResult result = Git.getInstance().runCommand(handler);
        if (beforeRevision != null) {
            GitRevisionNumber currentRev = new GitRevisionNumber(beforeRevision);
            handleResult(result, localChangesDetector, untrackedFilesDetector, currentRev, beforeLabel, updatedRanges);
        }
    }
}
Also used : lombok.val(lombok.val) GitRevisionNumber(git4idea.GitRevisionNumber) GitLocalChangesWouldBeOverwrittenDetector(git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector) AccessToken(com.intellij.openapi.application.AccessToken) Label(com.intellij.history.Label) GitUpdatedRanges(git4idea.update.GitUpdatedRanges) GitMacheteBundle.getString(com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString) GitUntrackedFilesOverwrittenByOperationDetector(git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector) GitCommandResult(git4idea.commands.GitCommandResult) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 4 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class GitCommandUpdatingCurrentBranchBackgroundable method showUpdates.

@UIThreadUnsafe
private void showUpdates(GitRevisionNumber currentRev, Label beforeLabel) {
    try {
        UpdatedFiles files = UpdatedFiles.create();
        val collector = createMergeChangeCollector(project, gitRepository, currentRev);
        collector.collect(files);
        UiThreadExecutionCompat.invokeLaterIfNeeded(ModalityState.defaultModalityState(), () -> {
            val manager = ProjectLevelVcsManagerEx.getInstanceEx(project);
            UpdateInfoTree tree = manager.showUpdateProjectInfo(files, getOperationName(), ActionInfo.UPDATE, /* canceled */
            false);
            if (tree != null) {
                tree.setBefore(beforeLabel);
                tree.setAfter(LocalHistory.getInstance().putSystemLabel(project, /* name */
                "After update"));
                ViewUpdateInfoNotification.focusUpdateInfoTree(project, tree);
            }
        });
    } catch (VcsException e) {
        GitVcs.getInstance(project).showErrors(java.util.Collections.singletonList(e), getOperationName());
    }
}
Also used : lombok.val(lombok.val) VcsException(com.intellij.openapi.vcs.VcsException) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles) UpdateInfoTree(com.intellij.openapi.vcs.update.UpdateInfoTree) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 5 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class PullCurrentBranchFastForwardOnlyBackgroundable method createGitLineHandler.

@Override
@UIThreadUnsafe
@Nullable
protected GitLineHandler createGitLineHandler() {
    val handler = new GitLineHandler(project, gitRepository.getRoot(), GitCommand.PULL);
    String remoteName = remoteBranch.getRemoteName();
    GitRemote remote = GitUtil.findRemoteByName(gitRepository, remoteName);
    if (remote == null) {
        // This is generally NOT expected, the task should never be triggered
        // for an invalid remote in the first place.
        LOG.warn("Remote '${remoteName}' does not exist");
        return null;
    }
    handler.setUrls(remote.getUrls());
    handler.addParameters("--ff-only");
    handler.addParameters(remote.getName());
    val remoteBranchFullNameAsLocalBranchOnRemote = remoteBranch.getFullNameAsLocalBranchOnRemote();
    val remoteBranchFullName = remoteBranch.getFullName();
    // This strategy is used to fetch branch from remote repository to remote branch in our repository.
    String refspec = createRefspec(remoteBranchFullNameAsLocalBranchOnRemote, remoteBranchFullName, /* allowNonFastForward */
    true);
    handler.addParameters(refspec);
    return handler;
}
Also used : lombok.val(lombok.val) GitRemote(git4idea.repo.GitRemote) GitLineHandler(git4idea.commands.GitLineHandler) GitMacheteBundle.getString(com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

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