Search in sources :

Example 16 with GitRepositoryManager

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

the class GithubRebaseAction method doRebaseCurrentBranch.

private static void doRebaseCurrentBranch(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull final ProgressIndicator indicator) {
    final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
    Git git = ServiceManager.getService(Git.class);
    final GitRebaser rebaser = new GitRebaser(project, git, indicator);
    final GitLineHandler handler = new GitLineHandler(project, root, GitCommand.REBASE);
    handler.setStdoutSuppressed(false);
    handler.addParameters("upstream/master");
    final GitRebaseProblemDetector rebaseConflictDetector = new GitRebaseProblemDetector();
    handler.addLineListener(rebaseConflictDetector);
    final GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
    final GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, CHECKOUT);
    handler.addLineListener(untrackedFilesDetector);
    handler.addLineListener(localChangesDetector);
    handler.addLineListener(GitStandardProgressAnalyzer.createListener(indicator));
    String oldText = indicator.getText();
    indicator.setText("Rebasing from upstream/master...");
    GitCommandResult rebaseResult = git.runCommand(handler);
    indicator.setText(oldText);
    repositoryManager.updateRepository(root);
    if (rebaseResult.success()) {
        root.refresh(false, true);
        GithubNotifications.showInfo(project, "Success", "Successfully rebased GitHub fork");
    } else {
        GitUpdateResult result = rebaser.handleRebaseFailure(handler, root, rebaseConflictDetector, untrackedFilesDetector, localChangesDetector);
        if (result == GitUpdateResult.NOTHING_TO_UPDATE || result == GitUpdateResult.SUCCESS || result == GitUpdateResult.SUCCESS_WITH_RESOLVED_CONFLICTS) {
            GithubNotifications.showInfo(project, "Success", "Successfully rebased GitHub fork");
        }
    }
}
Also used : GitUpdateResult(git4idea.update.GitUpdateResult) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRebaseProblemDetector(git4idea.rebase.GitRebaseProblemDetector) GitRebaser(git4idea.rebase.GitRebaser)

Example 17 with GitRepositoryManager

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

the class GitHistoryProvider method canShowHistoryFor.

@Override
public boolean canShowHistoryFor(@NotNull VirtualFile file) {
    GitRepositoryManager manager = GitUtil.getRepositoryManager(myProject);
    GitRepository repository = manager.getRepositoryForFileQuick(file);
    return repository != null && !repository.isFresh();
}
Also used : GitRepository(git4idea.repo.GitRepository) GitRepositoryManager(git4idea.repo.GitRepositoryManager)

Example 18 with GitRepositoryManager

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

the class GitOptionsTopHitProvider method getOptions.

@NotNull
@Override
public Collection<OptionDescription> getOptions(@Nullable Project project) {
    if (project != null) {
        for (VcsDescriptor descriptor : ProjectLevelVcsManager.getInstance(project).getAllVcss()) {
            if ("Git".equals(descriptor.getDisplayName())) {
                final GitVcsSettings settings = GitVcsSettings.getInstance(project);
                ArrayList<BooleanOptionDescription> options = new ArrayList<>();
                options.add(option(project, "Git: Commit automatically on cherry-pick", "isAutoCommitOnCherryPick", "setAutoCommitOnCherryPick"));
                options.add(option(project, "Git: Auto-update if push of the current branch was rejected", "autoUpdateIfPushRejected", "setAutoUpdateIfPushRejected"));
                GitRepositoryManager manager = GitRepositoryManager.getInstance(project);
                if (manager != null && manager.moreThanOneRoot()) {
                    options.add(new BooleanOptionDescription("Git: Control repositories synchronously", "vcs.Git") {

                        @Override
                        public boolean isOptionEnabled() {
                            return settings.getSyncSetting() == DvcsSyncSettings.Value.SYNC;
                        }

                        @Override
                        public void setOptionState(boolean enabled) {
                            settings.setSyncSetting(enabled ? DvcsSyncSettings.Value.SYNC : DvcsSyncSettings.Value.DONT_SYNC);
                        }
                    });
                }
                options.add(option(project, "Git: Warn if CRLF line separators are about to be committed", "warnAboutCrlf", "setWarnAboutCrlf"));
                options.add(option(project, "Git: Warn when committing in detached HEAD or during rebase", "warnAboutDetachedHead", "setWarnAboutDetachedHead"));
                options.add(option(project, "Git: Allow force push", "isForcePushAllowed", "setForcePushAllowed"));
                return Collections.unmodifiableCollection(options);
            }
        }
    }
    return Collections.emptyList();
}
Also used : BooleanOptionDescription(com.intellij.ide.ui.search.BooleanOptionDescription) ArrayList(java.util.ArrayList) GitRepositoryManager(git4idea.repo.GitRepositoryManager) VcsDescriptor(com.intellij.openapi.vcs.impl.VcsDescriptor) NotNull(org.jetbrains.annotations.NotNull)

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