Search in sources :

Example 81 with GitRepository

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

the class GitStashChangesSaver method loadRoot.

/**
   * Returns true if the root was loaded with conflict.
   * False is returned in all other cases: in the case of success and in case of some other error.
   */
private boolean loadRoot(final VirtualFile root) {
    LOG.info("loadRoot " + root);
    myProgressIndicator.setText(GitHandlerUtil.formatOperationName("Unstashing changes to", root));
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository is null for root " + root);
        return false;
    }
    GitSimpleEventDetector conflictDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT_ON_UNSTASH);
    GitCommandResult result = myGit.stashPop(repository, conflictDetector);
    VfsUtil.markDirtyAndRefresh(false, true, false, root);
    if (result.success()) {
        return false;
    } else if (conflictDetector.hasHappened()) {
        return true;
    } else {
        LOG.info("unstash failed " + result.getErrorOutputAsJoinedString());
        GitUIUtil.notifyImportantError(myProject, "Couldn't unstash", "<br/>" + result.getErrorOutputAsHtmlString());
        return false;
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitSimpleEventDetector(git4idea.commands.GitSimpleEventDetector) GitCommandResult(git4idea.commands.GitCommandResult)

Example 82 with GitRepository

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

the class GitStashChangesSaver method save.

@Override
protected void save(@NotNull Collection<VirtualFile> rootsToSave) throws VcsException {
    LOG.info("saving " + rootsToSave);
    for (VirtualFile root : rootsToSave) {
        final String message = GitHandlerUtil.formatOperationName("Stashing changes from", root);
        LOG.info(message);
        final String oldProgressTitle = myProgressIndicator.getText();
        myProgressIndicator.setText(message);
        GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
        if (repository == null) {
            LOG.error("Repository is null for root " + root);
        } else {
            GitCommandResult result = myGit.stashSave(repository, myStashMessage);
            if (result.success() && somethingWasStashed(result)) {
                myStashedRoots.add(root);
            } else {
                String error = "stash " + repository.getRoot() + ": " + result.getErrorOutputAsJoinedString();
                if (!result.success()) {
                    throw new VcsException(error);
                } else {
                    LOG.warn(error);
                }
            }
        }
        myProgressIndicator.setText(oldProgressTitle);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) VcsException(com.intellij.openapi.vcs.VcsException) GitCommandResult(git4idea.commands.GitCommandResult)

Example 83 with GitRepository

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

the class GitNewResetDialog method prepareDescription.

@NotNull
private static String prepareDescription(@NotNull Project project, @NotNull Map<GitRepository, VcsFullCommitDetails> commits) {
    if (commits.size() == 1 && !isMultiRepo(project)) {
        Map.Entry<GitRepository, VcsFullCommitDetails> entry = commits.entrySet().iterator().next();
        return String.format("%s -> %s", getSourceText(entry.getKey()), getTargetText(entry.getValue()));
    }
    StringBuilder desc = new StringBuilder("");
    for (Map.Entry<GitRepository, VcsFullCommitDetails> entry : commits.entrySet()) {
        GitRepository repository = entry.getKey();
        VcsFullCommitDetails commit = entry.getValue();
        desc.append(String.format("%s in %s -> %s<br/>", getSourceText(repository), getShortRepositoryName(repository), getTargetText(commit)));
    }
    return desc.toString();
}
Also used : GitRepository(git4idea.repo.GitRepository) Map(java.util.Map) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with GitRepository

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

the class GitRollbackEnvironment method unindex.

/**
   * Remove file paths from index (git remove --cached).
   *
   * @param root  a git root
   * @param files files to remove from index.
   * @param toUnversioned passed true if the file will be unversioned after unindexing, i.e. it was added before the revert operation.
   * @throws VcsException if there is a problem with running git
   */
private void unindex(final VirtualFile root, final List<FilePath> files, boolean toUnversioned) throws VcsException {
    GitFileUtils.delete(myProject, root, files, "--cached", "-f");
    if (toUnversioned) {
        final GitRepository repo = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
        final GitUntrackedFilesHolder untrackedFilesHolder = (repo == null ? null : repo.getUntrackedFilesHolder());
        for (FilePath path : files) {
            final VirtualFile vf = VcsUtil.getVirtualFile(path.getIOFile());
            if (untrackedFilesHolder != null && vf != null) {
                untrackedFilesHolder.add(vf);
            }
        }
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitUntrackedFilesHolder(git4idea.repo.GitUntrackedFilesHolder)

Example 85 with GitRepository

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

the class GitPusher method rememberTargets.

private void rememberTargets(@NotNull Map<GitRepository, PushSpec<GitPushSource, GitPushTarget>> pushSpecs) {
    for (Map.Entry<GitRepository, PushSpec<GitPushSource, GitPushTarget>> entry : pushSpecs.entrySet()) {
        GitRepository repository = entry.getKey();
        GitPushSource source = entry.getValue().getSource();
        GitPushTarget target = entry.getValue().getTarget();
        GitPushTarget defaultTarget = myPushSupport.getDefaultTarget(repository);
        if (defaultTarget == null || !target.getBranch().equals(defaultTarget.getBranch())) {
            mySettings.setPushTarget(repository, source.getBranch().getName(), target.getBranch().getRemote().getName(), target.getBranch().getNameForRemoteOperations());
        }
    }
}
Also used : PushSpec(com.intellij.dvcs.push.PushSpec) GitRepository(git4idea.repo.GitRepository) Map(java.util.Map)

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