Search in sources :

Example 21 with GitCommandResult

use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.

the class GitFetcher method fetchNatively.

@NotNull
private static GitFetchResult fetchNatively(@NotNull GitRepository repository, @NotNull GitRemote remote, @Nullable String branch) {
    Git git = Git.getInstance();
    String[] additionalParams = branch != null ? new String[] { getFetchSpecForBranch(branch, remote.getName()) } : ArrayUtil.EMPTY_STRING_ARRAY;
    GitFetchPruneDetector pruneDetector = new GitFetchPruneDetector();
    GitCommandResult result = git.fetch(repository, remote, Collections.<GitLineHandlerListener>singletonList(pruneDetector), additionalParams);
    GitFetchResult fetchResult;
    if (result.success()) {
        fetchResult = GitFetchResult.success();
    } else if (result.cancelled()) {
        fetchResult = GitFetchResult.cancel();
    } else {
        fetchResult = GitFetchResult.error(result.getErrorOutputAsJoinedString());
    }
    fetchResult.addPruneInfo(pruneDetector.getPrunedRefs());
    return fetchResult;
}
Also used : Git(git4idea.commands.Git) GitCommandResult(git4idea.commands.GitCommandResult) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with GitCommandResult

use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.

the class GitRenameBranchOperation method execute.

@Override
protected void execute() {
    while (hasMoreRepositories()) {
        GitRepository repository = next();
        GitCommandResult result = myGit.renameBranch(repository, myCurrentName, myNewName);
        if (result.success()) {
            refresh(repository);
            markSuccessful(repository);
        } else {
            fatalError("Couldn't rename " + myCurrentName + " to " + myNewName, result.getErrorOutputAsJoinedString());
            return;
        }
    }
    notifySuccess();
}
Also used : GitRepository(git4idea.repo.GitRepository) GitCommandResult(git4idea.commands.GitCommandResult)

Example 23 with GitCommandResult

use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.

the class GitPushOperation method doPush.

@NotNull
private ResultWithOutput doPush(@NotNull GitRepository repository, @NotNull PushSpec<GitPushSource, GitPushTarget> pushSpec) {
    GitPushTarget target = pushSpec.getTarget();
    GitLocalBranch sourceBranch = pushSpec.getSource().getBranch();
    GitRemoteBranch targetBranch = target.getBranch();
    GitLineHandlerListener progressListener = GitStandardProgressAnalyzer.createListener(myProgressIndicator);
    boolean setUpstream = pushSpec.getTarget().isNewBranchCreated() && !branchTrackingInfoIsSet(repository, sourceBranch);
    String tagMode = myTagMode == null ? null : myTagMode.getArgument();
    String spec = sourceBranch.getFullName() + ":" + targetBranch.getNameForRemoteOperations();
    GitCommandResult res = myGit.push(repository, targetBranch.getRemote(), spec, myForce, setUpstream, tagMode, progressListener);
    return new ResultWithOutput(res);
}
Also used : GitLocalBranch(git4idea.GitLocalBranch) GitLineHandlerListener(git4idea.commands.GitLineHandlerListener) GitCommandResult(git4idea.commands.GitCommandResult) GitRemoteBranch(git4idea.GitRemoteBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with GitCommandResult

use of git4idea.commands.GitCommandResult in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectRepositoryValidator method unstash.

private void unstash(@NotNull final Project project, @NotNull final Ref<StashInfo> targetStash, @NotNull final VirtualFile root) {
    if (repoState.getSourceRepository() == null || repoState.getOriginalBranchName() == null || (!repoState.getOriginalBranchName().equals(repoState.getSourceRepository().getCurrentBranchName()) && !repoState.getOriginalBranchName().equals(repoState.getSourceRepository().getCurrentRevision()))) {
        Messages.showErrorDialog(GctBundle.getString("clouddebug.erroroncheckout", repoState.getOriginalBranchName()), "Error");
        return;
    }
    final GitLineHandler handler = new GitLineHandler(project, root, GitCommand.STASH);
    handler.addParameters("apply");
    handler.addParameters("--index");
    addStashParameter(project, handler, targetStash.get().getStash());
    final AtomicBoolean conflict = new AtomicBoolean();
    handler.addLineListener(new GitLineHandlerAdapter() {

        @Override
        public void onLineAvailable(String line, Key outputType) {
            if (line.contains("Merge conflict")) {
                conflict.set(true);
            }
        }
    });
    GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
    GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, MERGE);
    handler.addLineListener(untrackedFilesDetector);
    handler.addLineListener(localChangesDetector);
    AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
    try {
        final Ref<GitCommandResult> result = Ref.create();
        ProgressManager.getInstance().run(new Task.Modal(handler.project(), GitBundle.getString("unstash.unstashing"), false) {

            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                indicator.setIndeterminate(true);
                handler.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(indicator, handler, "stash", false));
                Git git = ServiceManager.getService(Git.class);
                result.set(git.runCommand(new Computable.PredefinedValueComputable<GitLineHandler>(handler)));
            }
        });
        ServiceManager.getService(project, GitPlatformFacade.class).hardRefresh(root);
        GitCommandResult res = result.get();
        if (conflict.get()) {
            Messages.showDialog(GctBundle.getString("clouddebug.unstashmergeconflicts"), "Merge Conflicts", new String[] { "Ok" }, 0, Messages.getErrorIcon());
        } else if (untrackedFilesDetector.wasMessageDetected()) {
            GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), "unstash", null);
        } else if (localChangesDetector.wasMessageDetected()) {
            LocalChangesWouldBeOverwrittenHelper.showErrorDialog(project, root, "unstash", localChangesDetector.getRelativeFilePaths());
        } else if (!res.success()) {
            GitUIUtil.showOperationErrors(project, handler.errors(), handler.printableCommandLine());
        } else if (res.success()) {
            ProgressManager.getInstance().run(new Task.Modal(project, GctBundle.getString("clouddebug.removestashx", targetStash.get().getStash()), false) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    if (project == null) {
                        return;
                    }
                    final GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH);
                    h.addParameters("drop");
                    addStashParameter(project, h, targetStash.get().getStash());
                    try {
                        h.run();
                        h.unsilence();
                    } catch (final VcsException ex) {
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                GitUIUtil.showOperationError(project, ex, h.printableCommandLine());
                            }
                        });
                    }
                }
            });
        }
    } finally {
        DvcsUtil.workingTreeChangeFinished(project, token);
    }
}
Also used : GitLineHandler(git4idea.commands.GitLineHandler) Task(com.intellij.openapi.progress.Task) GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitLocalChangesWouldBeOverwrittenDetector(git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector) GitPlatformFacade(git4idea.GitPlatformFacade) GitUntrackedFilesOverwrittenByOperationDetector(git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector) GitCommandResult(git4idea.commands.GitCommandResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Git(git4idea.commands.Git) AccessToken(com.intellij.openapi.application.AccessToken) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) GitLineHandlerAdapter(git4idea.commands.GitLineHandlerAdapter) Key(com.intellij.openapi.util.Key) Computable(com.intellij.openapi.util.Computable)

Example 25 with GitCommandResult

use of git4idea.commands.GitCommandResult 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)

Aggregations

GitCommandResult (git4idea.commands.GitCommandResult)26 GitRepository (git4idea.repo.GitRepository)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 AccessToken (com.intellij.openapi.application.AccessToken)5 VcsException (com.intellij.openapi.vcs.VcsException)4 GitLocalChangesWouldBeOverwrittenDetector (git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector)4 GitUntrackedFilesOverwrittenByOperationDetector (git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector)4 NotNull (org.jetbrains.annotations.NotNull)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Git (git4idea.commands.Git)3 GitLineHandler (git4idea.commands.GitLineHandler)3 GitLineHandlerListener (git4idea.commands.GitLineHandlerListener)3 GitSimpleEventDetector (git4idea.commands.GitSimpleEventDetector)3 File (java.io.File)3 Task (com.intellij.openapi.progress.Task)2 MultiMap (com.intellij.util.containers.MultiMap)2 UIThreadUnsafe (com.virtuslab.qual.guieffect.UIThreadUnsafe)2 GitLocalBranch (git4idea.GitLocalBranch)2 GitCompoundResult (git4idea.commands.GitCompoundResult)2 Map (java.util.Map)2