use of git4idea.branch.GitBranchPair 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.branch.GitBranchPair in project intellij-community by JetBrains.
the class GitRebaseUpdater method getRemoteBranchToMerge.
@NotNull
private String getRemoteBranchToMerge() {
GitBranchPair gitBranchPair = myTrackedBranches.get(myRoot);
GitBranch dest = gitBranchPair.getDest();
LOG.assertTrue(dest != null, String.format("Destination branch is null for source branch %s in %s", gitBranchPair.getBranch().getName(), myRoot));
return dest.getName();
}
use of git4idea.branch.GitBranchPair in project intellij-community by JetBrains.
the class GitUpdateProcess method checkTrackedBranchesConfigured.
/**
* For each root check that the repository is on branch, and this branch is tracking a remote branch,
* and the remote branch exists.
* If it is not true for at least one of roots, notify and return false.
* If branch configuration is OK for all roots, return true.
*/
private boolean checkTrackedBranchesConfigured() {
LOG.info("checking tracked branch configuration...");
for (GitRepository repository : myRepositories) {
VirtualFile root = repository.getRoot();
final GitLocalBranch branch = repository.getCurrentBranch();
if (branch == null) {
LOG.info("checkTrackedBranchesConfigured: current branch is null in " + repository);
notifyImportantError(myProject, "Can't update: no current branch", "You are in 'detached HEAD' state, which means that you're not on any branch" + rootStringIfNeeded(root) + "Checkout a branch to make update possible.");
return false;
}
GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, branch);
if (trackInfo == null) {
final String branchName = branch.getName();
LOG.info(String.format("checkTrackedBranchesConfigured: no track info for current branch %s in %s", branch, repository));
String recommendedCommand = String.format(GitVersionSpecialty.KNOWS_SET_UPSTREAM_TO.existsIn(repository.getVcs().getVersion()) ? "git branch --set-upstream-to origin/%1$s %1$s" : "git branch --set-upstream %1$s origin/%1$s", branchName);
notifyImportantError(myProject, "Can't update: no tracked branch", "No tracked branch configured for branch " + code(branchName) + rootStringIfNeeded(root) + "To make your branch track a remote branch call, for example,<br/>" + "<code>" + recommendedCommand + "</code>");
return false;
}
myTrackedBranches.put(root, new GitBranchPair(branch, trackInfo.getRemoteBranch()));
}
return true;
}
Aggregations