Search in sources :

Example 16 with GitCommandResult

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

the class GitStashChangesSaver method loadRoot.

/**
   * Returns true if the root was loaded with conflict.
   * False is returned in all other cases: in the case of success and in case of some other error.
   */
private boolean loadRoot(final VirtualFile root) {
    LOG.info("loadRoot " + root);
    myProgressIndicator.setText(GitHandlerUtil.formatOperationName("Unstashing changes to", root));
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository is null for root " + root);
        return false;
    }
    GitSimpleEventDetector conflictDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT_ON_UNSTASH);
    GitCommandResult result = myGit.stashPop(repository, conflictDetector);
    VfsUtil.markDirtyAndRefresh(false, true, false, root);
    if (result.success()) {
        return false;
    } else if (conflictDetector.hasHappened()) {
        return true;
    } else {
        LOG.info("unstash failed " + result.getErrorOutputAsJoinedString());
        GitUIUtil.notifyImportantError(myProject, "Couldn't unstash", "<br/>" + result.getErrorOutputAsHtmlString());
        return false;
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitSimpleEventDetector(git4idea.commands.GitSimpleEventDetector) GitCommandResult(git4idea.commands.GitCommandResult)

Example 17 with GitCommandResult

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

the class GitStashChangesSaver method save.

@Override
protected void save(@NotNull Collection<VirtualFile> rootsToSave) throws VcsException {
    LOG.info("saving " + rootsToSave);
    for (VirtualFile root : rootsToSave) {
        final String message = GitHandlerUtil.formatOperationName("Stashing changes from", root);
        LOG.info(message);
        final String oldProgressTitle = myProgressIndicator.getText();
        myProgressIndicator.setText(message);
        GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
        if (repository == null) {
            LOG.error("Repository is null for root " + root);
        } else {
            GitCommandResult result = myGit.stashSave(repository, myStashMessage);
            if (result.success() && somethingWasStashed(result)) {
                myStashedRoots.add(root);
            } else {
                String error = "stash " + repository.getRoot() + ": " + result.getErrorOutputAsJoinedString();
                if (!result.success()) {
                    throw new VcsException(error);
                } else {
                    LOG.warn(error);
                }
            }
        }
        myProgressIndicator.setText(oldProgressTitle);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) VcsException(com.intellij.openapi.vcs.VcsException) GitCommandResult(git4idea.commands.GitCommandResult)

Example 18 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 19 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 20 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)

Aggregations

GitCommandResult (git4idea.commands.GitCommandResult)20 GitRepository (git4idea.repo.GitRepository)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)4 VcsException (com.intellij.openapi.vcs.VcsException)3 GitSimpleEventDetector (git4idea.commands.GitSimpleEventDetector)3 AccessToken (com.intellij.openapi.application.AccessToken)2 MultiMap (com.intellij.util.containers.MultiMap)2 GitCompoundResult (git4idea.commands.GitCompoundResult)2 GitLineHandlerListener (git4idea.commands.GitLineHandlerListener)2 GitUntrackedFilesOverwrittenByOperationDetector (git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector)2 File (java.io.File)2 Map (java.util.Map)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VcsNotifier (com.intellij.openapi.vcs.VcsNotifier)1 Change (com.intellij.openapi.vcs.changes.Change)1 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)1 Hash (com.intellij.vcs.log.Hash)1 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)1