}
return new GitBranch(branch, false, remoteFlag);
}
+
+ /**
+ * Get a merge base between the current branch and specified branch.
+ *
+ * @param project the current project
+ * @param root the vcs root
+ * @param branch the branch
+ * @return the common commit or null if the there is no common commit
+ * @throws VcsException the exception
+ */
+ @Nullable
+ public GitRevisionNumber getMergeBase(@NotNull Project project, @NotNull VirtualFile root, @NotNull GitBranch branch)
+ throws VcsException {
+ GitSimpleHandler h = new GitSimpleHandler(project, root, GitHandler.MERGE_BASE);
+ h.addParameters(this.getFullName(), branch.getFullName());
+ String output = h.run().trim();
+ if (output.length() == 0) {
+ return null;
+ }
+ else {
+ return GitRevisionNumber.resolve(project, root, output);
+ }
+ }
}
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import git4idea.GitBranchesSearcher;
+import git4idea.GitRevisionNumber;
import git4idea.GitUtil;
import git4idea.commands.GitSimpleHandler;
myProject = project;
}
- public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote) throws VcsException {
+ public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote)
+ throws VcsException {
LOG.debug("getOutgoingChanges root: " + vcsRoot.getPath());
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, findRemote);
if (searcher.getLocal() == null || searcher.getRemote() == null) {
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, Collections.<CommittedChangeList>emptyList());
}
-
+ final GitRevisionNumber base = searcher.getLocal().getMergeBase(myProject, vcsRoot, searcher.getRemote());
+ if (base == null) {
+ return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, Collections.<CommittedChangeList>emptyList());
+ }
final List<CommittedChangeList> lists = GitUtil.getLocalCommittedChanges(myProject, vcsRoot, new Consumer<GitSimpleHandler>() {
public void consume(final GitSimpleHandler handler) {
- handler.addParameters(searcher.getRemote().getFullName() + "..HEAD");
+ handler.addParameters(base.asString() + "..HEAD");
}
});
- return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, lists);
+ return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(base, lists);
}
}