Search in sources :

Example 1 with GitCommandResult

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

the class GitCheckoutNewBranchOperation method execute.

@Override
protected void execute() {
    boolean fatalErrorHappened = false;
    while (hasMoreRepositories() && !fatalErrorHappened) {
        final GitRepository repository = next();
        GitSimpleEventDetector unmergedDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.UNMERGED_PREVENTING_CHECKOUT);
        GitCommandResult result = myGit.checkoutNewBranch(repository, myNewBranchName, unmergedDetector);
        if (result.success()) {
            refresh(repository);
            markSuccessful(repository);
        } else if (unmergedDetector.hasHappened()) {
            fatalUnmergedFilesError();
            fatalErrorHappened = true;
        } else {
            fatalError("Couldn't create new branch " + myNewBranchName, result.getErrorOutputAsJoinedString());
            fatalErrorHappened = true;
        }
    }
    if (!fatalErrorHappened) {
        notifySuccess();
        updateRecentBranch();
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitSimpleEventDetector(git4idea.commands.GitSimpleEventDetector) GitCommandResult(git4idea.commands.GitCommandResult)

Example 2 with GitCommandResult

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

the class GitCheckoutNewBranchOperation method rollback.

@Override
protected void rollback() {
    GitCompoundResult checkoutResult = new GitCompoundResult(myProject);
    GitCompoundResult deleteResult = new GitCompoundResult(myProject);
    Collection<GitRepository> repositories = getSuccessfulRepositories();
    for (GitRepository repository : repositories) {
        GitCommandResult result = myGit.checkout(repository, myCurrentHeads.get(repository), null, true, false);
        checkoutResult.append(repository, result);
        if (result.success()) {
            deleteResult.append(repository, myGit.branchDelete(repository, myNewBranchName, false));
        }
        refresh(repository);
    }
    if (checkoutResult.totalSuccess() && deleteResult.totalSuccess()) {
        VcsNotifier.getInstance(myProject).notifySuccess("Rollback successful", String.format("Checked out %s and deleted %s on %s %s", stringifyBranchesByRepos(myCurrentHeads), code(myNewBranchName), StringUtil.pluralize("root", repositories.size()), successfulRepositoriesJoined()));
    } else {
        StringBuilder message = new StringBuilder();
        if (!checkoutResult.totalSuccess()) {
            message.append("Errors during checkout: ");
            message.append(checkoutResult.getErrorOutputWithReposIndication());
        }
        if (!deleteResult.totalSuccess()) {
            message.append("Errors during deleting ").append(code(myNewBranchName));
            message.append(deleteResult.getErrorOutputWithReposIndication());
        }
        VcsNotifier.getInstance(myProject).notifyError("Error during rollback", message.toString());
    }
}
Also used : GitCompoundResult(git4idea.commands.GitCompoundResult) GitRepository(git4idea.repo.GitRepository) GitCommandResult(git4idea.commands.GitCommandResult)

Example 3 with GitCommandResult

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

the class GitDeleteRemoteBranchOperation method doDeleteRemote.

private boolean doDeleteRemote(@NotNull String branchName, @NotNull Collection<GitRepository> repositories) {
    Couple<String> pair = splitNameOfRemoteBranch(branchName);
    String remoteName = pair.getFirst();
    String branch = pair.getSecond();
    GitCompoundResult result = new GitCompoundResult(myProject);
    for (GitRepository repository : repositories) {
        GitCommandResult res;
        GitRemote remote = getRemoteByName(repository, remoteName);
        if (remote == null) {
            String error = "Couldn't find remote by name: " + remoteName;
            LOG.error(error);
            res = GitCommandResult.error(error);
        } else {
            res = pushDeletion(repository, remote, branch);
            if (!res.success() && isAlreadyDeletedError(res.getErrorOutputAsJoinedString())) {
                res = myGit.remotePrune(repository, remote);
            }
        }
        result.append(repository, res);
        repository.update();
    }
    if (!result.totalSuccess()) {
        VcsNotifier.getInstance(myProject).notifyError("Failed to delete remote branch " + branchName, result.getErrorOutputWithReposIndication());
    }
    return result.totalSuccess();
}
Also used : GitRemote(git4idea.repo.GitRemote) GitCompoundResult(git4idea.commands.GitCompoundResult) GitRepository(git4idea.repo.GitRepository) GitCommandResult(git4idea.commands.GitCommandResult)

Example 4 with GitCommandResult

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

the class GitCrlfProblemsDetector method findFilesWithoutAttrs.

@NotNull
private Collection<VirtualFile> findFilesWithoutAttrs(@NotNull VirtualFile root, @NotNull Collection<VirtualFile> files) {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.warn("Repository is null for " + root);
        return Collections.emptyList();
    }
    Collection<String> interestingAttributes = Arrays.asList(GitAttribute.TEXT.getName(), GitAttribute.CRLF.getName());
    GitCommandResult result = myGit.checkAttr(repository, interestingAttributes, files);
    if (!result.success()) {
        LOG.warn(String.format("Couldn't git check-attr. Attributes: %s, files: %s", interestingAttributes, files));
        return Collections.emptyList();
    }
    GitCheckAttrParser parser = GitCheckAttrParser.parse(result.getOutput());
    Map<String, Collection<GitAttribute>> attributes = parser.getAttributes();
    Collection<VirtualFile> filesWithoutAttrs = new ArrayList<>();
    for (VirtualFile file : files) {
        ProgressIndicatorProvider.checkCanceled();
        String relativePath = FileUtil.getRelativePath(root.getPath(), file.getPath(), '/');
        Collection<GitAttribute> attrs = attributes.get(relativePath);
        if (attrs == null || !attrs.contains(GitAttribute.TEXT) && !attrs.contains(GitAttribute.CRLF)) {
            filesWithoutAttrs.add(file);
        }
    }
    return filesWithoutAttrs;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitCheckAttrParser(git4idea.attributes.GitCheckAttrParser) GitAttribute(git4idea.attributes.GitAttribute) GitCommandResult(git4idea.commands.GitCommandResult) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GitCommandResult

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

the class GitCrlfProblemsDetector method isAutoCrlfSetRight.

private boolean isAutoCrlfSetRight(@NotNull VirtualFile root) {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.warn("Repository is null for " + root);
        return true;
    }
    GitCommandResult result = myGit.config(repository, GitConfigUtil.CORE_AUTOCRLF);
    String value = result.getOutputAsJoinedString();
    return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("input");
}
Also used : GitRepository(git4idea.repo.GitRepository) GitCommandResult(git4idea.commands.GitCommandResult)

Aggregations

GitCommandResult (git4idea.commands.GitCommandResult)23 GitRepository (git4idea.repo.GitRepository)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 VcsException (com.intellij.openapi.vcs.VcsException)4 NotNull (org.jetbrains.annotations.NotNull)4 AccessToken (com.intellij.openapi.application.AccessToken)3 Git (git4idea.commands.Git)3 GitLineHandlerListener (git4idea.commands.GitLineHandlerListener)3 GitSimpleEventDetector (git4idea.commands.GitSimpleEventDetector)3 GitUntrackedFilesOverwrittenByOperationDetector (git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector)3 File (java.io.File)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 MultiMap (com.intellij.util.containers.MultiMap)2 GitLocalBranch (git4idea.GitLocalBranch)2 GitCompoundResult (git4idea.commands.GitCompoundResult)2 GitLocalChangesWouldBeOverwrittenDetector (git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector)2 Map (java.util.Map)2 Notification (com.intellij.notification.Notification)1 UrlOpeningListener (com.intellij.notification.NotificationListener.UrlOpeningListener)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1