Search in sources :

Example 6 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchUtil method findRemoteByNameOrLogError.

@Nullable
@Deprecated
public static GitRemote findRemoteByNameOrLogError(@NotNull Project project, @NotNull VirtualFile root, @NotNull String remoteName) {
    GitRepository repository = GitUtil.getRepositoryForRootOrLogError(project, root);
    if (repository == null) {
        return null;
    }
    GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
    if (remote == null) {
        LOG.warn("Couldn't find remote with name " + remoteName);
        return null;
    }
    return remote;
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchUtil method getCommonBranches.

@NotNull
public static Collection<String> getCommonBranches(Collection<GitRepository> repositories, boolean local) {
    Collection<String> commonBranches = null;
    for (GitRepository repository : repositories) {
        GitBranchesCollection branchesCollection = repository.getBranches();
        Collection<String> names = local ? convertBranchesToNames(branchesCollection.getLocalBranches()) : getBranchNamesWithoutRemoteHead(branchesCollection.getRemoteBranches());
        if (commonBranches == null) {
            commonBranches = names;
        } else {
            commonBranches = ContainerUtil.intersection(commonBranches, names);
        }
    }
    if (commonBranches != null) {
        ArrayList<String> common = new ArrayList<>(commonBranches);
        Collections.sort(common);
        return common;
    } else {
        return Collections.emptyList();
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) ArrayList(java.util.ArrayList) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchWorker method loadCommitsToCompare.

private GitCommitCompareInfo loadCommitsToCompare(List<GitRepository> repositories, String branchName) {
    GitCommitCompareInfo compareInfo = new GitCommitCompareInfo();
    for (GitRepository repository : repositories) {
        compareInfo.put(repository, loadCommitsToCompare(repository, branchName));
        compareInfo.put(repository, loadTotalDiff(repository, branchName));
    }
    return compareInfo;
}
Also used : GitCommitCompareInfo(git4idea.util.GitCommitCompareInfo) GitRepository(git4idea.repo.GitRepository)

Example 9 with GitRepository

use of git4idea.repo.GitRepository 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 10 with GitRepository

use of git4idea.repo.GitRepository 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)

Aggregations

GitRepository (git4idea.repo.GitRepository)123 VirtualFile (com.intellij.openapi.vfs.VirtualFile)46 NotNull (org.jetbrains.annotations.NotNull)33 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)18 GitCommandResult (git4idea.commands.GitCommandResult)14 GitRepositoryManager (git4idea.repo.GitRepositoryManager)12 VcsException (com.intellij.openapi.vcs.VcsException)11 AccessToken (com.intellij.openapi.application.AccessToken)9 File (java.io.File)8 Map (java.util.Map)8 GitRemote (git4idea.repo.GitRemote)7 FilePath (com.intellij.openapi.vcs.FilePath)6 Change (com.intellij.openapi.vcs.changes.Change)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Task (com.intellij.openapi.progress.Task)5 ArrayList (java.util.ArrayList)5 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)4 MultiMap (com.intellij.util.containers.MultiMap)4 GitBranch (git4idea.GitBranch)4