Search in sources :

Example 46 with GitRepository

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

the class GitAbortRebaseProcess method doAbort.

private void doAbort(final boolean rollback) {
    new GitFreezingProcess(myProject, "rebase", new Runnable() {

        public void run() {
            AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
            List<GitRepository> repositoriesToRefresh = ContainerUtil.newArrayList();
            try {
                if (myRepositoryToAbort != null) {
                    myIndicator.setText2("git rebase --abort" + GitUtil.mention(myRepositoryToAbort));
                    GitCommandResult result = myGit.rebaseAbort(myRepositoryToAbort);
                    repositoriesToRefresh.add(myRepositoryToAbort);
                    if (!result.success()) {
                        myNotifier.notifyError("Rebase Abort Failed", result.getErrorOutputAsHtmlString() + mentionLocalChangesRemainingInStash(mySaver));
                        return;
                    }
                }
                if (rollback) {
                    for (GitRepository repo : myRepositoriesToRollback.keySet()) {
                        myIndicator.setText2("git reset --keep" + GitUtil.mention(repo));
                        GitCommandResult res = myGit.reset(repo, GitResetMode.KEEP, myRepositoriesToRollback.get(repo));
                        repositoriesToRefresh.add(repo);
                        if (res.success()) {
                            String initialBranchPosition = myInitialCurrentBranches.get(repo);
                            if (initialBranchPosition != null && !initialBranchPosition.equals(repo.getCurrentBranchName())) {
                                myIndicator.setText2("git checkout " + initialBranchPosition + GitUtil.mention(repo));
                                res = myGit.checkout(repo, initialBranchPosition, null, true, false);
                            }
                        }
                        if (!res.success()) {
                            String description = myRepositoryToAbort != null ? "Rebase abort was successful" + GitUtil.mention(myRepositoryToAbort) + ", but rollback failed" : "Rollback failed";
                            description += GitUtil.mention(repo) + ":" + res.getErrorOutputAsHtmlString() + mentionLocalChangesRemainingInStash(mySaver);
                            myNotifier.notifyImportantWarning("Rebase Rollback Failed", description);
                            return;
                        }
                    }
                }
                if (mySaver != null) {
                    mySaver.load();
                }
                myNotifier.notifySuccess("Rebase abort succeeded");
            } finally {
                refresh(repositoriesToRefresh);
                token.finish();
            }
        }
    }).execute();
}
Also used : GitFreezingProcess(git4idea.util.GitFreezingProcess) GitRepository(git4idea.repo.GitRepository) AccessToken(com.intellij.openapi.application.AccessToken) GitCommandResult(git4idea.commands.GitCommandResult)

Example 47 with GitRepository

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

the class GitRebaseDialog method loadRefs.

/**
   * Load tags and branches
   */
protected void loadRefs() {
    try {
        myLocalBranches.clear();
        myRemoteBranches.clear();
        myTags.clear();
        final VirtualFile root = gitRoot();
        GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
        if (repository != null) {
            myLocalBranches.addAll(repository.getBranches().getLocalBranches());
            myRemoteBranches.addAll(repository.getBranches().getRemoteBranches());
            myCurrentBranch = repository.getCurrentBranch();
        } else {
            LOG.error("Repository is null for root " + root);
        }
        GitTag.list(myProject, root, myTags);
    } catch (VcsException e) {
        GitUIUtil.showOperationError(myProject, e, "git branch -a");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) VcsException(com.intellij.openapi.vcs.VcsException)

Example 48 with GitRepository

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

the class GitRebaseProcess method doRebase.

/**
   * Given a GitRebaseSpec this method either starts, or continues the ongoing rebase in multiple repositories.
   * <ul>
   * <li>It does nothing with "already successfully rebased repositories" (the ones which have {@link GitRebaseStatus} == SUCCESSFUL,
   * and just remembers them to use in the resulting notification.</li>
   * <li>If there is a repository with rebase in progress, it calls `git rebase --continue` (or `--skip`).
   * It is assumed that there is only one such repository.</li>
   * <li>For all remaining repositories rebase on which didn't start yet, it calls {@code git rebase <original parameters>}</li>
   * </ul>
   */
private void doRebase() {
    LOG.info("Started rebase");
    LOG.debug("Started rebase with the following spec: " + myRebaseSpec);
    Map<GitRepository, GitRebaseStatus> statuses = newLinkedHashMap(myRebaseSpec.getStatuses());
    Collection<GitRepository> toRefresh = newLinkedHashSet();
    List<GitRepository> repositoriesToRebase = myRebaseSpec.getIncompleteRepositories();
    AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
    try {
        if (!saveDirtyRootsInitially(repositoriesToRebase))
            return;
        GitRepository failed = null;
        for (GitRepository repository : repositoriesToRebase) {
            GitRebaseResumeMode customMode = null;
            if (repository == myRebaseSpec.getOngoingRebase()) {
                customMode = myCustomMode == null ? GitRebaseResumeMode.CONTINUE : myCustomMode;
            }
            GitRebaseStatus rebaseStatus = rebaseSingleRoot(repository, customMode, getSuccessfulRepositories(statuses));
            // make the repo state info actual ASAP
            repository.update();
            statuses.put(repository, rebaseStatus);
            if (shouldBeRefreshed(rebaseStatus)) {
                toRefresh.add(repository);
            }
            if (rebaseStatus.getType() != GitRebaseStatus.Type.SUCCESS) {
                failed = repository;
                break;
            }
        }
        if (failed == null) {
            LOG.debug("Rebase completed successfully.");
            mySaver.load();
        }
        refresh(toRefresh);
        if (failed == null) {
            notifySuccess(getSuccessfulRepositories(statuses), getSkippedCommits(statuses));
        }
        saveUpdatedSpec(statuses);
    } catch (ProcessCanceledException pce) {
        throw pce;
    } catch (Throwable e) {
        myRepositoryManager.setOngoingRebaseSpec(null);
        ExceptionUtil.rethrowUnchecked(e);
    } finally {
        token.finish();
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) AccessToken(com.intellij.openapi.application.AccessToken) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 49 with GitRepository

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

the class GitRebaseSpec method forNewRebase.

@NotNull
public static GitRebaseSpec forNewRebase(@NotNull Project project, @NotNull GitRebaseParams params, @NotNull Collection<GitRepository> repositories, @NotNull ProgressIndicator indicator) {
    GitUtil.updateRepositories(repositories);
    Map<GitRepository, String> initialHeadPositions = findInitialHeadPositions(repositories, params.getBranch());
    Map<GitRepository, String> initialBranchNames = findInitialBranchNames(repositories);
    Map<GitRepository, GitRebaseStatus> initialStatusMap = new TreeMap<>(DvcsUtil.REPOSITORY_COMPARATOR);
    for (GitRepository repository : repositories) {
        initialStatusMap.put(repository, GitRebaseStatus.notStarted());
    }
    return new GitRebaseSpec(params, initialStatusMap, initialHeadPositions, initialBranchNames, newSaver(project, indicator), true);
}
Also used : GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with GitRepository

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

the class GitRebaseUtils method getRebaseDir.

/**
   * Get rebase directory
   *
   * @param root the vcs root
   * @return the rebase directory or null if it does not exist.
   */
@Nullable
private static File getRebaseDir(@NotNull Project project, @NotNull VirtualFile root) {
    GitRepository repository = assertNotNull(GitUtil.getRepositoryManager(project).getRepositoryForRoot(root));
    File f = repository.getRepositoryFiles().getRebaseApplyDir();
    if (f.exists()) {
        return f;
    }
    f = repository.getRepositoryFiles().getRebaseMergeDir();
    if (f.exists()) {
        return f;
    }
    return null;
}
Also used : GitRepository(git4idea.repo.GitRepository) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

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