use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitRebaseUtils method isRebaseAllowed.
private static boolean isRebaseAllowed(@NotNull Project project, @NotNull Collection<GitRepository> repositories) {
// TODO links to 'rebase', 'resolve conflicts', etc.
for (GitRepository repository : repositories) {
Repository.State state = repository.getState();
String in = GitUtil.mention(repository);
String message = null;
switch(state) {
case NORMAL:
if (repository.isFresh()) {
message = "Repository" + in + " is empty.";
}
break;
case MERGING:
message = "There is an unfinished merge process" + in + ".<br/>You should complete the merge before starting a rebase";
break;
case REBASING:
message = "There is an unfinished rebase process" + in + ".<br/>You should complete it before starting another rebase";
break;
case GRAFTING:
message = "There is an unfinished cherry-pick process" + in + ".<br/>You should finish it before starting a rebase.";
break;
case DETACHED:
message = "You are in the detached HEAD state" + in + ".<br/>Rebase is not possible.";
break;
default:
LOG.error("Unknown state [" + state.name() + "]");
message = "Rebase is not possible" + in;
}
if (message != null) {
VcsNotifier.getInstance(project).notifyError("Rebase not Allowed", message);
return false;
}
}
return true;
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitCompareBranchesLogPanel method createNorthPanel.
private JComponent createNorthPanel() {
final JComboBox repoSelector = new JComboBox(ArrayUtil.toObjectArray(myCompareInfo.getRepositories(), GitRepository.class));
repoSelector.setRenderer(new GitRepositoryComboboxListCellRenderer(repoSelector));
repoSelector.setSelectedItem(myInitialRepo);
repoSelector.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GitRepository selectedRepo = (GitRepository) repoSelector.getSelectedItem();
myHeadToBranchListPanel.setCommits(getHeadToBranchCommits(selectedRepo));
myBranchToHeadListPanel.setCommits(getBranchToHeadCommits(selectedRepo));
}
});
JPanel repoSelectorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
JBLabel label = new JBLabel("Repository: ");
label.setLabelFor(repoSelectorPanel);
label.setDisplayedMnemonic(KeyEvent.VK_R);
repoSelectorPanel.add(label);
repoSelectorPanel.add(repoSelector);
if (myCompareInfo.getRepositories().size() < 2) {
repoSelectorPanel.setVisible(false);
}
return repoSelectorPanel;
}
use of git4idea.repo.GitRepository 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.GitRepository in project intellij-community by JetBrains.
the class GitFetcher method fetch.
@NotNull
public GitFetchResult fetch(@NotNull VirtualFile root, @NotNull String remoteName, @Nullable String branch) {
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
return logError("Repository can't be null for " + root, myRepositoryManager.toString());
}
GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
if (remote == null) {
return logError("Couldn't find remote with the name " + remoteName, null);
}
return fetchRemote(repository, remote, branch);
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitFetcher method fetchRootsAndNotify.
/**
* Fetches all specified roots.
* Once a root has failed, stops and displays the notification.
* If needed, displays the successful notification at the end.
* @param roots roots to fetch.
* @param errorNotificationTitle if specified, this notification title will be used instead of the standard "Fetch failed".
* Use this when fetch is a part of a compound process.
* @param notifySuccess if set to {@code true} successful notification will be displayed.
* @return true if all fetches were successful, false if at least one fetch failed.
*/
public boolean fetchRootsAndNotify(@NotNull Collection<GitRepository> roots, @Nullable String errorNotificationTitle, boolean notifySuccess) {
MultiRootMessage additionalInfo = new MultiRootMessage(myProject, GitUtil.getRootsFromRepositories(roots), true);
for (GitRepository repository : roots) {
LOG.info("fetching " + repository);
GitFetchResult result = fetch(repository);
String ai = result.getAdditionalInfo();
if (!StringUtil.isEmptyOrSpaces(ai)) {
additionalInfo.append(repository.getRoot(), ai);
}
if (!result.isSuccess()) {
Collection<Exception> errors = new ArrayList<>(getErrors());
errors.addAll(result.getErrors());
displayFetchResult(myProject, result, errorNotificationTitle, errors);
return false;
}
}
if (notifySuccess) {
VcsNotifier.getInstance(myProject).notifySuccess("Fetched successfully");
}
if (!additionalInfo.asString().isEmpty()) {
VcsNotifier.getInstance(myProject).notifyMinorInfo("Fetch details", additionalInfo.asString());
}
return true;
}
Aggregations