use of git4idea.config.GitVcsSettings 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.config.GitVcsSettings in project intellij-community by JetBrains.
the class GitBranchPopup method getInstance.
/**
* @param currentRepository Current repository, which means the repository of the currently open or selected file.
* In the case of synchronized branch operations current repository matter much less, but sometimes is used,
* for example, it is preselected in the repositories combobox in the compare branches dialog.
*/
static GitBranchPopup getInstance(@NotNull final Project project, @NotNull GitRepository currentRepository) {
final GitVcsSettings vcsSettings = GitVcsSettings.getInstance(project);
Condition<AnAction> preselectActionCondition = action -> {
if (action instanceof GitBranchPopupActions.LocalBranchActions) {
GitBranchPopupActions.LocalBranchActions branchAction = (GitBranchPopupActions.LocalBranchActions) action;
String branchName = branchAction.getBranchName();
String recentBranch;
List<GitRepository> repositories = branchAction.getRepositories();
if (repositories.size() == 1) {
recentBranch = vcsSettings.getRecentBranchesByRepository().get(repositories.iterator().next().getRoot().getPath());
} else {
recentBranch = vcsSettings.getRecentCommonBranch();
}
if (recentBranch != null && recentBranch.equals(branchName)) {
return true;
}
}
return false;
};
return new GitBranchPopup(currentRepository, GitUtil.getRepositoryManager(project), vcsSettings, preselectActionCondition);
}
use of git4idea.config.GitVcsSettings in project intellij-community by JetBrains.
the class GitResetAction method actionPerformed.
@Override
protected void actionPerformed(@NotNull final Project project, @NotNull final Map<GitRepository, VcsFullCommitDetails> commits) {
GitVcsSettings settings = GitVcsSettings.getInstance(project);
GitResetMode defaultMode = ObjectUtils.notNull(settings.getResetMode(), GitResetMode.getDefault());
GitNewResetDialog dialog = new GitNewResetDialog(project, commits, defaultMode);
if (dialog.showAndGet()) {
final GitResetMode selectedMode = dialog.getResetMode();
settings.setResetMode(selectedMode);
new Task.Backgroundable(project, "Git reset", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Map<GitRepository, Hash> hashes = commits.keySet().stream().collect(Collectors.toMap(Function.identity(), repo -> commits.get(repo).getId()));
new GitResetOperation(project, hashes, selectedMode, indicator).execute();
}
}.queue();
}
}
Aggregations