Search in sources :

Example 6 with GitRepositoryManager

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

the class GitCheckinEnvironment method commit.

private void commit(@NotNull Project project, @NotNull VirtualFile root, @NotNull Collection<FilePath> files, @NotNull File message) throws VcsException {
    boolean amend = myNextCommitAmend;
    for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
        GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT);
        handler.setStdoutSuppressed(false);
        if (myNextCommitSignOff) {
            handler.addParameters("--signoff");
        }
        if (amend) {
            handler.addParameters("--amend");
        } else {
            amend = true;
        }
        handler.addParameters("--only", "-F", message.getAbsolutePath());
        if (myNextCommitAuthor != null) {
            handler.addParameters("--author=" + myNextCommitAuthor);
        }
        if (myNextCommitAuthorDate != null) {
            handler.addParameters("--date", COMMIT_DATE_FORMAT.format(myNextCommitAuthorDate));
        }
        handler.endOptions();
        handler.addParameters(paths);
        handler.run();
    }
    if (!project.isDisposed()) {
        GitRepositoryManager manager = getRepositoryManager(project);
        manager.updateRepository(root);
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitUtil.getLogString(git4idea.GitUtil.getLogString)

Example 7 with GitRepositoryManager

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

the class GitShowExternalLogAction method createManagerAndContent.

@NotNull
private static MyContentComponent createManagerAndContent(@NotNull Project project, @NotNull final GitVcs vcs, @NotNull final List<VirtualFile> roots, @Nullable String tabName) {
    final GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(project);
    for (VirtualFile root : roots) {
        repositoryManager.addExternalRepository(root, GitRepositoryImpl.getInstance(root, project, true));
    }
    VcsLogManager manager = new VcsLogManager(project, ServiceManager.getService(project, VcsLogTabsProperties.class), ContainerUtil.map(roots, root -> new VcsRoot(vcs, root)));
    return new MyContentComponent(manager.createLogPanel(calcLogId(roots), tabName), roots, () -> {
        for (VirtualFile root : roots) {
            repositoryManager.removeExternalRepository(root);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) Arrays(java.util.Arrays) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRepositoryImpl(git4idea.repo.GitRepositoryImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) VcsLogContentProvider(com.intellij.vcs.log.impl.VcsLogContentProvider) GitVcs(git4idea.GitVcs) GitUtil(git4idea.GitUtil) Task(com.intellij.openapi.progress.Task) VcsRoot(com.intellij.openapi.vcs.VcsRoot) Comparing(com.intellij.openapi.util.Comparing) GitVersion(git4idea.config.GitVersion) WindowWrapper(com.intellij.openapi.ui.WindowWrapper) Disposer(com.intellij.openapi.util.Disposer) VcsLogManager(com.intellij.vcs.log.impl.VcsLogManager) Project(com.intellij.openapi.project.Project) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) ProgressManager(com.intellij.openapi.progress.ProgressManager) ToolWindow(com.intellij.openapi.wm.ToolWindow) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) ChangesViewContentManager(com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager) Content(com.intellij.ui.content.Content) Disposable(com.intellij.openapi.Disposable) File(java.io.File) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) ContentFactory(com.intellij.ui.content.ContentFactory) WindowWrapperBuilder(com.intellij.openapi.ui.WindowWrapperBuilder) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ContentManager(com.intellij.ui.content.ContentManager) ObjectUtils(com.intellij.util.ObjectUtils) VcsLogTabsProperties(com.intellij.vcs.log.impl.VcsLogTabsProperties) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) FileChooser(com.intellij.openapi.fileChooser.FileChooser) javax.swing(javax.swing) VcsLogManager(com.intellij.vcs.log.impl.VcsLogManager) VcsLogTabsProperties(com.intellij.vcs.log.impl.VcsLogTabsProperties) GitRepositoryManager(git4idea.repo.GitRepositoryManager) VcsRoot(com.intellij.openapi.vcs.VcsRoot) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with GitRepositoryManager

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

the class GitLogBranchOperationsActionGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(AnActionEvent e) {
    if (e == null)
        return AnAction.EMPTY_ARRAY;
    Project project = e.getProject();
    VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG);
    VcsLogUi logUI = e.getData(VcsLogDataKeys.VCS_LOG_UI);
    List<VcsRef> branches = e.getData(VcsLogDataKeys.VCS_LOG_BRANCHES);
    if (project == null || log == null || logUI == null || branches == null) {
        return AnAction.EMPTY_ARRAY;
    }
    List<CommitId> commits = log.getSelectedCommits();
    if (commits.size() != 1)
        return AnAction.EMPTY_ARRAY;
    CommitId commit = commits.get(0);
    GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(project);
    final GitRepository root = repositoryManager.getRepositoryForRoot(commit.getRoot());
    if (root == null)
        return AnAction.EMPTY_ARRAY;
    List<VcsRef> vcsRefs = ContainerUtil.filter(branches, new Condition<VcsRef>() {

        @Override
        public boolean value(VcsRef ref) {
            if (ref.getType() == GitRefManager.LOCAL_BRANCH) {
                return !ref.getName().equals(root.getCurrentBranchName());
            }
            if (ref.getType() == GitRefManager.REMOTE_BRANCH)
                return true;
            return false;
        }
    });
    VcsLogProvider provider = logUI.getDataPack().getLogProviders().get(root.getRoot());
    if (provider != null) {
        VcsLogRefManager refManager = provider.getReferenceManager();
        Comparator<VcsRef> comparator = refManager.getLabelsOrderComparator();
        ContainerUtil.sort(vcsRefs, comparator);
    }
    if (vcsRefs.isEmpty())
        return AnAction.EMPTY_ARRAY;
    GitVcsSettings settings = GitVcsSettings.getInstance(project);
    boolean showBranchesPopup = vcsRefs.size() > MAX_BRANCH_GROUPS;
    List<AnAction> branchActionGroups = new ArrayList<>();
    for (VcsRef ref : vcsRefs) {
        branchActionGroups.add(createBranchGroup(project, ref, root, repositoryManager, settings, showBranchesPopup));
    }
    DefaultActionGroup branchesGroup = new DefaultActionGroup("Branches", branchActionGroups);
    branchesGroup.setPopup(showBranchesPopup);
    return new AnAction[] { branchesGroup };
}
Also used : GitVcsSettings(git4idea.config.GitVcsSettings) ArrayList(java.util.ArrayList) GitRepositoryManager(git4idea.repo.GitRepositoryManager) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GitRepositoryManager

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

the class GitUpdateEnvironment method updateDirectories.

@NotNull
public UpdateSession updateDirectories(@NotNull FilePath[] filePaths, UpdatedFiles updatedFiles, ProgressIndicator progressIndicator, @NotNull Ref<SequentialUpdatesContext> sequentialUpdatesContextRef) throws ProcessCanceledException {
    Set<VirtualFile> roots = gitRoots(Arrays.asList(filePaths));
    GitRepositoryManager repositoryManager = getRepositoryManager(myProject);
    final GitUpdateProcess gitUpdateProcess = new GitUpdateProcess(myProject, progressIndicator, getRepositoriesFromRoots(repositoryManager, roots), updatedFiles, true);
    boolean result = gitUpdateProcess.update(mySettings.getUpdateType()).isSuccess();
    return new GitUpdateSession(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepositoryManager(git4idea.repo.GitRepositoryManager) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with GitRepositoryManager

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

the class GithubShareAction method shareProjectOnGithub.

public static void shareProjectOnGithub(@NotNull final Project project, @Nullable final VirtualFile file) {
    BasicAction.saveAll();
    // get gitRepository
    final GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
    final boolean gitDetected = gitRepository != null;
    final VirtualFile root = gitDetected ? gitRepository.getRoot() : project.getBaseDir();
    final GithubAuthDataHolder authHolder = GithubAuthDataHolder.createFromSettings();
    // check for existing git repo
    Set<String> existingRemotes = Collections.emptySet();
    if (gitDetected) {
        final String githubRemote = GithubUtil.findGithubRemoteUrl(gitRepository);
        if (githubRemote != null) {
            if (!checkExistingRemote(project, authHolder, githubRemote))
                return;
        }
        existingRemotes = ContainerUtil.map2Set(gitRepository.getRemotes(), GitRemote::getName);
    }
    // get available GitHub repos with modal progress
    final GithubInfo githubInfo = loadGithubInfoWithModal(authHolder, project);
    if (githubInfo == null) {
        return;
    }
    // Show dialog (window)
    final GithubShareDialog shareDialog = new GithubShareDialog(project, githubInfo.getRepositoryNames(), existingRemotes, githubInfo.getUser().canCreatePrivateRepo());
    DialogManager.show(shareDialog);
    if (!shareDialog.isOK()) {
        return;
    }
    final boolean isPrivate = shareDialog.isPrivate();
    final String name = shareDialog.getRepositoryName();
    final String description = shareDialog.getDescription();
    final String remoteName = shareDialog.getRemoteName();
    new Task.Backgroundable(project, "Sharing Project on GitHub...") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            // create GitHub repo (network)
            LOG.info("Creating GitHub repository");
            indicator.setText("Creating GitHub repository...");
            final String url = createGithubRepository(project, authHolder, indicator, name, description, isPrivate);
            if (url == null) {
                return;
            }
            LOG.info("Successfully created GitHub repository");
            // creating empty git repo if git is not initialized
            LOG.info("Binding local project with GitHub");
            if (!gitDetected) {
                LOG.info("No git detected, creating empty git repo");
                indicator.setText("Creating empty git repo...");
                if (!createEmptyGitRepository(project, root, indicator)) {
                    return;
                }
            }
            GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
            final GitRepository repository = repositoryManager.getRepositoryForRoot(root);
            if (repository == null) {
                GithubNotifications.showError(project, "Failed to create GitHub Repository", "Can't find Git repository");
                return;
            }
            final String remoteUrl = GithubUrlUtil.getCloneUrl(githubInfo.getUser().getLogin(), name);
            //git remote add origin git@github.com:login/name.git
            LOG.info("Adding GitHub as a remote host");
            indicator.setText("Adding GitHub as a remote host...");
            if (!GithubUtil.addGithubRemote(project, repository, remoteName, remoteUrl)) {
                return;
            }
            // create sample commit for binding project
            if (!performFirstCommitIfRequired(project, root, repository, indicator, name, url)) {
                return;
            }
            //git push origin master
            LOG.info("Pushing to github master");
            indicator.setText("Pushing to github master...");
            if (!pushCurrentBranch(project, repository, remoteName, remoteUrl, name, url)) {
                return;
            }
            GithubNotifications.showInfoURL(project, "Successfully shared project on GitHub", name, url);
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) GithubAuthDataHolder(org.jetbrains.plugins.github.util.GithubAuthDataHolder) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRepository(git4idea.repo.GitRepository) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GithubShareDialog(org.jetbrains.plugins.github.ui.GithubShareDialog)

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