Search in sources :

Example 96 with GitRepository

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

the class GitBranchOperation method groupByBranches.

@NotNull
private static MultiMap<String, VirtualFile> groupByBranches(@NotNull Map<GitRepository, String> heads) {
    MultiMap<String, VirtualFile> result = MultiMap.createLinked();
    List<GitRepository> sortedRepos = DvcsUtil.sortRepositories(heads.keySet());
    for (GitRepository repo : sortedRepos) {
        result.putValue(heads.get(repo), repo.getRoot());
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) ObjectUtils.chooseNotNull(com.intellij.util.ObjectUtils.chooseNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with GitRepository

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

the class GitBranchOperation method updateRecentBranch.

/**
   * Updates the recently visited branch in the settings.
   * This is to be performed after successful checkout operation.
   */
protected void updateRecentBranch() {
    if (getRepositories().size() == 1) {
        GitRepository repository = myRepositories.iterator().next();
        String currentHead = myCurrentHeads.get(repository);
        if (currentHead != null) {
            mySettings.setRecentBranchOfRepository(repository.getRoot().getPath(), currentHead);
        } else {
            LOG.error("Current head is not known for " + repository.getRoot().getPath());
        }
    } else {
        String recentCommonBranch = getRecentCommonBranch();
        if (recentCommonBranch != null) {
            mySettings.setRecentCommonBranch(recentCommonBranch);
        }
    }
}
Also used : GitRepository(git4idea.repo.GitRepository)

Example 98 with GitRepository

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

the class GitBranchOperation method markSuccessful.

/**
   * Marks repositories as successful, i.e. they won't be handled again.
   */
protected void markSuccessful(GitRepository... repositories) {
    for (GitRepository repository : repositories) {
        mySuccessfulRepositories.add(repository);
        myRemainingRepositories.remove(repository);
    }
}
Also used : GitRepository(git4idea.repo.GitRepository)

Example 99 with GitRepository

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

the class GitMergeOperation method doMerge.

/**
   * Performs merge in the given repositories.
   * Handle only merge conflict situation: all other cases should have been handled before and are treated as errors.
   * Conflict is treated as a success: the repository with conflict is remembered and will be handled later along with all other conflicts.
   * If an error happens in one repository, the method doesn't go further in others, and shows a notification.
   *
   * @return true if merge has succeeded without errors (but possibly with conflicts) in all repositories;
   *         false if it failed at least in one of them.
   */
private boolean doMerge(@NotNull Collection<GitRepository> repositories) {
    for (GitRepository repository : repositories) {
        GitSimpleEventDetector mergeConflict = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT);
        GitCommandResult result = myGit.merge(repository, myBranchToMerge, Collections.<String>emptyList(), mergeConflict);
        if (!result.success()) {
            if (mergeConflict.hasHappened()) {
                myConflictedRepositories.put(repository, Boolean.TRUE);
                refresh(repository);
                markSuccessful(repository);
            } else {
                fatalError(getCommonErrorTitle(), result.getErrorOutputAsJoinedString());
                return false;
            }
        } else {
            refresh(repository);
            markSuccessful(repository);
        }
    }
    return true;
}
Also used : GitRepository(git4idea.repo.GitRepository)

Example 100 with GitRepository

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

the class GitMergeOperation method rollback.

@Override
protected void rollback() {
    LOG.info("starting rollback...");
    Collection<GitRepository> repositoriesForSmartRollback = new ArrayList<>();
    Collection<GitRepository> repositoriesForSimpleRollback = new ArrayList<>();
    Collection<GitRepository> repositoriesForMergeRollback = new ArrayList<>();
    for (GitRepository repository : getSuccessfulRepositories()) {
        if (myConflictedRepositories.containsKey(repository)) {
            repositoriesForMergeRollback.add(repository);
        } else if (thereAreLocalChangesIn(repository)) {
            repositoriesForSmartRollback.add(repository);
        } else {
            repositoriesForSimpleRollback.add(repository);
        }
    }
    LOG.info("for smart rollback: " + DvcsUtil.getShortNames(repositoriesForSmartRollback) + "; for simple rollback: " + DvcsUtil.getShortNames(repositoriesForSimpleRollback) + "; for merge rollback: " + DvcsUtil.getShortNames(repositoriesForMergeRollback));
    GitCompoundResult result = smartRollback(repositoriesForSmartRollback);
    for (GitRepository repository : repositoriesForSimpleRollback) {
        result.append(repository, rollback(repository));
    }
    for (GitRepository repository : repositoriesForMergeRollback) {
        result.append(repository, rollbackMerge(repository));
    }
    myConflictedRepositories.clear();
    if (!result.totalSuccess()) {
        VcsNotifier.getInstance(myProject).notifyError("Error during rollback", result.getErrorOutputWithReposIndication());
    }
    LOG.info("rollback finished.");
}
Also used : GitRepository(git4idea.repo.GitRepository)

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