Search in sources :

Example 6 with GitCommandResult

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

the class GitConflictResolver method unmergedFiles.

/**
   * Parse changes from lines
   *
   *
   * @param root    the git root
   * @return a set of unmerged files
   * @throws com.intellij.openapi.vcs.VcsException if the input format does not matches expected format
   */
private List<VirtualFile> unmergedFiles(final VirtualFile root) throws VcsException {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository not found for root " + root);
        return Collections.emptyList();
    }
    GitCommandResult result = myGit.getUnmergedFiles(repository);
    if (!result.success()) {
        throw new VcsException(result.getErrorOutputAsJoinedString());
    }
    String output = StringUtil.join(result.getOutput(), "\n");
    HashSet<String> unmergedPaths = ContainerUtil.newHashSet();
    for (StringScanner s = new StringScanner(output); s.hasMoreData(); ) {
        if (s.isEol()) {
            s.nextLine();
            continue;
        }
        s.boundedToken('\t');
        String relative = s.line();
        unmergedPaths.add(GitUtil.unescapePath(relative));
    }
    if (unmergedPaths.size() == 0) {
        return Collections.emptyList();
    } else {
        List<File> files = ContainerUtil.map(unmergedPaths, new Function<String, File>() {

            @Override
            public File fun(String path) {
                return new File(root.getPath(), path);
            }
        });
        return sortVirtualFilesByPresentation(findVirtualFilesWithRefresh(files));
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) VcsException(com.intellij.openapi.vcs.VcsException) GitCommandResult(git4idea.commands.GitCommandResult) StringScanner(git4idea.util.StringScanner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 7 with GitCommandResult

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

the class GitResetOperation method proposeSmartReset.

private GitCommandResult proposeSmartReset(@NotNull GitLocalChangesWouldBeOverwrittenDetector detector, @NotNull final GitRepository repository, @NotNull final String target) {
    Collection<String> absolutePaths = GitUtil.toAbsolute(repository.getRoot(), detector.getRelativeFilePaths());
    List<Change> affectedChanges = GitUtil.findLocalChangesForPaths(myProject, repository.getRoot(), absolutePaths, false);
    int choice = myUiHandler.showSmartOperationDialog(myProject, affectedChanges, absolutePaths, "reset", "&Hard Reset");
    if (choice == GitSmartOperationDialog.SMART_EXIT_CODE) {
        final Ref<GitCommandResult> result = Ref.create();
        new GitPreservingProcess(myProject, myGit, Collections.singleton(repository.getRoot()), "reset", target, GitVcsSettings.UpdateChangesPolicy.STASH, myIndicator, new Runnable() {

            @Override
            public void run() {
                result.set(myGit.reset(repository, myMode, target));
            }
        }).execute();
        return result.get();
    }
    if (choice == GitSmartOperationDialog.FORCE_EXIT_CODE) {
        return myGit.reset(repository, GitResetMode.HARD, target);
    }
    return null;
}
Also used : Change(com.intellij.openapi.vcs.changes.Change) GitCommandResult(git4idea.commands.GitCommandResult) GitPreservingProcess(git4idea.util.GitPreservingProcess)

Example 8 with GitCommandResult

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

the class GitResetOperation method execute.

public void execute() {
    saveAllDocuments();
    AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
    Map<GitRepository, GitCommandResult> results = ContainerUtil.newHashMap();
    try {
        for (Map.Entry<GitRepository, Hash> entry : myCommits.entrySet()) {
            GitRepository repository = entry.getKey();
            VirtualFile root = repository.getRoot();
            String target = entry.getValue().asString();
            GitLocalChangesWouldBeOverwrittenDetector detector = new GitLocalChangesWouldBeOverwrittenDetector(root, RESET);
            GitCommandResult result = myGit.reset(repository, myMode, target, detector);
            if (!result.success() && detector.wasMessageDetected()) {
                GitCommandResult smartResult = proposeSmartReset(detector, repository, target);
                if (smartResult != null) {
                    result = smartResult;
                }
            }
            results.put(repository, result);
            repository.update();
            VfsUtil.markDirtyAndRefresh(false, true, false, root);
            VcsDirtyScopeManager.getInstance(myProject).dirDirtyRecursively(root);
        }
    } finally {
        token.finish();
    }
    notifyResult(results);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitLocalChangesWouldBeOverwrittenDetector(git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector) AccessToken(com.intellij.openapi.application.AccessToken) GitCommandResult(git4idea.commands.GitCommandResult) Hash(com.intellij.vcs.log.Hash) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap)

Example 9 with GitCommandResult

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

the class GitResetOperation method notifyResult.

private void notifyResult(@NotNull Map<GitRepository, GitCommandResult> results) {
    Map<GitRepository, GitCommandResult> successes = ContainerUtil.newHashMap();
    Map<GitRepository, GitCommandResult> errors = ContainerUtil.newHashMap();
    for (Map.Entry<GitRepository, GitCommandResult> entry : results.entrySet()) {
        GitCommandResult result = entry.getValue();
        GitRepository repository = entry.getKey();
        if (result.success()) {
            successes.put(repository, result);
        } else {
            errors.put(repository, result);
        }
    }
    if (errors.isEmpty()) {
        myNotifier.notifySuccess("", "Reset successful");
    } else if (!successes.isEmpty()) {
        myNotifier.notifyImportantWarning("Reset partially failed", "Reset was successful for " + joinRepos(successes.keySet()) + "<br/>but failed for " + joinRepos(errors.keySet()) + ": <br/>" + formErrorReport(errors));
    } else {
        myNotifier.notifyError("Reset Failed", formErrorReport(errors));
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitCommandResult(git4idea.commands.GitCommandResult) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap)

Example 10 with GitCommandResult

use of git4idea.commands.GitCommandResult 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)

Aggregations

GitCommandResult (git4idea.commands.GitCommandResult)20 GitRepository (git4idea.repo.GitRepository)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)4 VcsException (com.intellij.openapi.vcs.VcsException)3 GitSimpleEventDetector (git4idea.commands.GitSimpleEventDetector)3 AccessToken (com.intellij.openapi.application.AccessToken)2 MultiMap (com.intellij.util.containers.MultiMap)2 GitCompoundResult (git4idea.commands.GitCompoundResult)2 GitLineHandlerListener (git4idea.commands.GitLineHandlerListener)2 GitUntrackedFilesOverwrittenByOperationDetector (git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector)2 File (java.io.File)2 Map (java.util.Map)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VcsNotifier (com.intellij.openapi.vcs.VcsNotifier)1 Change (com.intellij.openapi.vcs.changes.Change)1 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)1 Hash (com.intellij.vcs.log.Hash)1 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)1