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);
}
}
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);
}
});
}
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 };
}
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);
}
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();
}
Aggregations