Search in sources :

Example 1 with GitCompoundResult

use of git4idea.commands.GitCompoundResult 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 2 with GitCompoundResult

use of git4idea.commands.GitCompoundResult 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 3 with GitCompoundResult

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

the class GitRenameBranchOperation method rollback.

@Override
protected void rollback() {
    GitCompoundResult result = new GitCompoundResult(myProject);
    Collection<GitRepository> repositories = getSuccessfulRepositories();
    for (GitRepository repository : repositories) {
        result.append(repository, myGit.renameBranch(repository, myNewName, myCurrentName));
        refresh(repository);
    }
    if (result.totalSuccess()) {
        myNotifier.notifySuccess("Rollback Successful", "Renamed back to " + myCurrentName);
    } else {
        myNotifier.notifyError("Rollback Failed", result.getErrorOutputWithReposIndication());
    }
}
Also used : GitCompoundResult(git4idea.commands.GitCompoundResult) GitRepository(git4idea.repo.GitRepository)

Aggregations

GitCompoundResult (git4idea.commands.GitCompoundResult)3 GitRepository (git4idea.repo.GitRepository)3 GitCommandResult (git4idea.commands.GitCommandResult)2 GitRemote (git4idea.repo.GitRemote)1