use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitMergeUpdater method isSaveNeeded.
@Override
public boolean isSaveNeeded() {
try {
if (GitUtil.hasLocalChanges(true, myProject, myRoot)) {
return true;
}
} catch (VcsException e) {
LOG.info("isSaveNeeded failed to check staging area", e);
return true;
}
// git log --name-status master..origin/master
GitBranchPair gitBranchPair = myTrackedBranches.get(myRoot);
String currentBranch = gitBranchPair.getBranch().getName();
String remoteBranch = gitBranchPair.getDest().getName();
try {
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(myRoot);
if (repository == null) {
LOG.error("Repository is null for root " + myRoot);
// fail safe
return true;
}
final Collection<String> remotelyChanged = GitUtil.getPathsDiffBetweenRefs(Git.getInstance(), repository, currentBranch, remoteBranch);
final List<File> locallyChanged = myChangeListManager.getAffectedPaths();
for (final File localPath : locallyChanged) {
if (ContainerUtil.exists(remotelyChanged, new Condition<String>() {
@Override
public boolean value(String remotelyChangedPath) {
return FileUtil.pathsEqual(localPath.getPath(), remotelyChangedPath);
}
})) {
// found a file which was changed locally and remotely => need to save
return true;
}
}
return false;
} catch (VcsException e) {
LOG.info("failed to get remotely changed files for " + currentBranch + ".." + remoteBranch, e);
// fail safe
return true;
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitUnstashDialog method refreshStashList.
private void refreshStashList() {
final DefaultListModel listModel = (DefaultListModel) myStashList.getModel();
listModel.clear();
VirtualFile root = getGitRoot();
GitStashUtils.loadStashStack(myProject, root, new Consumer<StashInfo>() {
@Override
public void consume(StashInfo stashInfo) {
listModel.addElement(stashInfo);
}
});
myBranches.clear();
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
if (repository != null) {
myBranches.addAll(GitBranchUtil.convertBranchesToNames(repository.getBranches().getLocalBranches()));
} else {
LOG.error("Repository is null for root " + root);
}
myStashList.setSelectedIndex(0);
}
use of git4idea.repo.GitRepository 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.repo.GitRepository in project intellij-community by JetBrains.
the class GitBranchPopupActions method createActions.
ActionGroup createActions(@Nullable DefaultActionGroup toInsert, @NotNull String repoInfo, boolean firstLevelGroup) {
DefaultActionGroup popupGroup = new DefaultActionGroup(null, false);
List<GitRepository> repositoryList = Collections.singletonList(myRepository);
popupGroup.addAction(new GitNewBranchAction(myProject, repositoryList));
popupGroup.addAction(new CheckoutRevisionActions(myProject, repositoryList));
if (toInsert != null) {
popupGroup.addAll(toInsert);
}
popupGroup.addSeparator("Local Branches" + repoInfo);
List<BranchActionGroup> localBranchActions = myRepository.getBranches().getLocalBranches().stream().sorted().filter(branch -> !branch.equals(myRepository.getCurrentBranch())).map(branch -> new LocalBranchActions(myProject, repositoryList, branch.getName(), myRepository)).collect(toList());
// if there are only a few local favorites -> show all; for remotes it's better to show only favorites;
wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(localBranchActions, FAVORITE_BRANCH_COMPARATOR), getNumOfTopShownBranches(localBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null, firstLevelGroup);
popupGroup.addSeparator("Remote Branches" + repoInfo);
List<BranchActionGroup> remoteBranchActions = myRepository.getBranches().getRemoteBranches().stream().sorted().map(remoteBranch -> new RemoteBranchActions(myProject, repositoryList, remoteBranch.getName(), myRepository)).collect(toList());
wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(remoteBranchActions, FAVORITE_BRANCH_COMPARATOR), getNumOfTopShownBranches(remoteBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_REMOTES_KEY : null);
return popupGroup;
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitUpdateProcess method update.
/**
* Checks if update is possible, saves local changes and updates all roots.
* In case of error shows notification and returns false. If update completes without errors, returns true.
*
* Perform update on all roots.
* 0. Blocks reloading project on external change, saving/syncing on frame deactivation.
* 1. Checks if update is possible (rebase/merge in progress, no tracked branches...) and provides merge dialog to solve problems.
* 2. Finds updaters to use (merge or rebase).
* 3. Preserves local changes if needed (not needed for merge sometimes).
* 4. Updates via 'git pull' or equivalent.
* 5. Restores local changes if update completed or failed with error. If update is incomplete, i.e. some unmerged files remain,
* local changes are not restored.
*
*/
@NotNull
public GitUpdateResult update(final UpdateMethod updateMethod) {
LOG.info("update started|" + updateMethod);
String oldText = myProgressIndicator.getText();
myProgressIndicator.setText("Updating...");
for (GitRepository repository : myRepositories) {
repository.update();
}
// check if update is possible
if (checkRebaseInProgress() || isMergeInProgress() || areUnmergedFiles() || !checkTrackedBranchesConfigured()) {
return GitUpdateResult.NOT_READY;
}
if (!fetchAndNotify()) {
return GitUpdateResult.NOT_READY;
}
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
GitUpdateResult result;
try {
result = updateImpl(updateMethod);
} finally {
token.finish();
}
myProgressIndicator.setText(oldText);
return result;
}
Aggregations