Search in sources :

Example 1 with GitRepositoryManager

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

the class GitMergeAction method handleResult.

private void handleResult(GitCommandResult result, Project project, GitSimpleEventDetector mergeConflictDetector, GitLocalChangesWouldBeOverwrittenDetector localChangesDetector, GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector, GitRepository repository, GitRevisionNumber currentRev, Label beforeLabel) {
    GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
    VirtualFile root = repository.getRoot();
    if (result.success() || mergeConflictDetector.hasHappened()) {
        VfsUtil.markDirtyAndRefresh(false, true, false, root);
        List<VcsException> exceptions = new ArrayList<>();
        GitMergeUtil.showUpdates(project, exceptions, root, currentRev, beforeLabel, getActionName(), ActionInfo.UPDATE);
        repositoryManager.updateRepository(root);
        showErrors(project, getActionName(), exceptions);
    } else if (localChangesDetector.wasMessageDetected()) {
        LocalChangesWouldBeOverwrittenHelper.showErrorNotification(project, repository.getRoot(), getActionName(), localChangesDetector.getRelativeFilePaths());
    } else if (untrackedFilesDetector.wasMessageDetected()) {
        GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), getActionName(), null);
    } else {
        GitUIUtil.notifyError(project, "Git " + getActionName() + " Failed", result.getErrorOutputAsJoinedString(), true, null);
        repositoryManager.updateRepository(root);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) GitRepositoryManager(git4idea.repo.GitRepositoryManager)

Example 2 with GitRepositoryManager

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

the class GitResetHead method perform.

/**
   * {@inheritDoc}
   */
protected void perform(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot) {
    GitResetDialog d = new GitResetDialog(project, gitRoots, defaultRoot);
    if (!d.showAndGet()) {
        return;
    }
    GitLineHandler h = d.handler();
    AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
    try {
        GitHandlerUtil.doSynchronously(h, GitBundle.getString("resetting.title"), h.printableCommandLine());
    } finally {
        token.finish();
    }
    GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
    manager.updateRepository(d.getGitRoot());
    VfsUtil.markDirtyAndRefresh(true, true, false, d.getGitRoot());
    if (!h.errors().isEmpty()) {
        showErrors(project, getActionName(), h.errors());
    }
}
Also used : GitLineHandler(git4idea.commands.GitLineHandler) GitResetDialog(git4idea.ui.GitResetDialog) AccessToken(com.intellij.openapi.application.AccessToken) GitRepositoryManager(git4idea.repo.GitRepositoryManager)

Example 3 with GitRepositoryManager

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

the class GitUtil method getRepositoryForRootOrLogError.

@Nullable
public static GitRepository getRepositoryForRootOrLogError(@NotNull Project project, @NotNull VirtualFile root) {
    GitRepositoryManager manager = getRepositoryManager(project);
    GitRepository repository = manager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository is null for root " + root);
    }
    return repository;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitRepositoryManager(git4idea.repo.GitRepositoryManager) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with GitRepositoryManager

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

the class GitUtil method getRepositoriesForFiles.

@NotNull
public static Collection<GitRepository> getRepositoriesForFiles(@NotNull Project project, @NotNull Collection<VirtualFile> files) {
    final GitRepositoryManager manager = getRepositoryManager(project);
    com.google.common.base.Function<VirtualFile, GitRepository> ROOT_TO_REPO = new com.google.common.base.Function<VirtualFile, GitRepository>() {

        @Override
        public GitRepository apply(@Nullable VirtualFile root) {
            return root != null ? manager.getRepositoryForRoot(root) : null;
        }
    };
    return Collections2.filter(Collections2.transform(sortFilesByGitRootsIgnoringOthers(files).keySet(), ROOT_TO_REPO), Predicates.notNull());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) Function(com.intellij.util.Function) GitRepository(git4idea.repo.GitRepository) GitRepositoryManager(git4idea.repo.GitRepositoryManager) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull)

Example 5 with GitRepositoryManager

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

the class GitCheckinEnvironment method commit.

public List<VcsException> commit(@NotNull List<Change> changes, @NotNull String message, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
    List<VcsException> exceptions = new ArrayList<>();
    Map<VirtualFile, Collection<Change>> sortedChanges = sortChangesByGitRoot(changes, exceptions);
    LOG.assertTrue(!sortedChanges.isEmpty(), "Trying to commit an empty list of changes: " + changes);
    for (Map.Entry<VirtualFile, Collection<Change>> entry : sortedChanges.entrySet()) {
        VirtualFile root = entry.getKey();
        File messageFile;
        try {
            messageFile = createMessageFile(root, message);
        } catch (IOException ex) {
            //noinspection ThrowableInstanceNeverThrown
            exceptions.add(new VcsException("Creation of commit message file failed", ex));
            continue;
        }
        Set<FilePath> added = new HashSet<>();
        Set<FilePath> removed = new HashSet<>();
        final Set<Change> caseOnlyRenames = new HashSet<>();
        for (Change change : entry.getValue()) {
            switch(change.getType()) {
                case NEW:
                case MODIFICATION:
                    added.add(change.getAfterRevision().getFile());
                    break;
                case DELETED:
                    removed.add(change.getBeforeRevision().getFile());
                    break;
                case MOVED:
                    FilePath afterPath = change.getAfterRevision().getFile();
                    FilePath beforePath = change.getBeforeRevision().getFile();
                    if (!SystemInfo.isFileSystemCaseSensitive && GitUtil.isCaseOnlyChange(beforePath.getPath(), afterPath.getPath())) {
                        caseOnlyRenames.add(change);
                    } else {
                        added.add(afterPath);
                        removed.add(beforePath);
                    }
                    break;
                default:
                    throw new IllegalStateException("Unknown change type: " + change.getType());
            }
        }
        try {
            if (!caseOnlyRenames.isEmpty()) {
                List<VcsException> exs = commitWithCaseOnlyRename(myProject, root, caseOnlyRenames, added, removed, messageFile, myNextCommitAuthor);
                exceptions.addAll(map(exs, GitCheckinEnvironment::cleanupExceptionText));
            } else {
                try {
                    Set<FilePath> files = new HashSet<>();
                    files.addAll(added);
                    files.addAll(removed);
                    commit(myProject, root, files, messageFile);
                } catch (VcsException ex) {
                    PartialOperation partialOperation = isMergeCommit(ex);
                    if (partialOperation == PartialOperation.NONE) {
                        throw ex;
                    }
                    if (!mergeCommit(myProject, root, added, removed, messageFile, myNextCommitAuthor, exceptions, partialOperation)) {
                        throw ex;
                    }
                }
            }
        } catch (VcsException e) {
            exceptions.add(cleanupExceptionText(e));
        } finally {
            if (!messageFile.delete()) {
                LOG.warn("Failed to remove temporary file: " + messageFile);
            }
        }
    }
    if (myNextCommitIsPushed != null && myNextCommitIsPushed.booleanValue() && exceptions.isEmpty()) {
        GitRepositoryManager manager = getRepositoryManager(myProject);
        Collection<GitRepository> repositories = GitUtil.getRepositoriesFromRoots(manager, sortedChanges.keySet());
        final List<GitRepository> preselectedRepositories = newArrayList(repositories);
        GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, GitBranchUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
    }
    return exceptions;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRepository(git4idea.repo.GitRepository) VcsPushDialog(com.intellij.dvcs.push.ui.VcsPushDialog) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Aggregations

GitRepositoryManager (git4idea.repo.GitRepositoryManager)18 GitRepository (git4idea.repo.GitRepository)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 VcsException (com.intellij.openapi.vcs.VcsException)3 ArrayList (java.util.ArrayList)3 AccessToken (com.intellij.openapi.application.AccessToken)2 Project (com.intellij.openapi.project.Project)2 FilePath (com.intellij.openapi.vcs.FilePath)2 GitUtil.getLogString (git4idea.GitUtil.getLogString)2 VcsPushDialog (com.intellij.dvcs.push.ui.VcsPushDialog)1 Label (com.intellij.history.Label)1 BooleanOptionDescription (com.intellij.ide.ui.search.BooleanOptionDescription)1 Disposable (com.intellij.openapi.Disposable)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1