assertFalse(i.hasNext());
}
+ /**
+ * <pre>
+ * A - B - C - M
+ * \ /
+ * -D(side)
+ * </pre>
+ */
+ @Test
+ public void addRangeWithMerge() throws Exception{
+ String fileA = "fileA";
+ String fileB = "fileB";
+ Git git = Git.wrap(db);
+
+ writeTrashFile(fileA, fileA);
+ git.add().addFilepattern(fileA).call();
+ git.commit().setMessage("commit a").call();
+
+ writeTrashFile(fileA, fileA);
+ git.add().addFilepattern(fileA).call();
+ RevCommit b = git.commit().setMessage("commit b").call();
+
+ writeTrashFile(fileA, fileA);
+ git.add().addFilepattern(fileA).call();
+ RevCommit c = git.commit().setMessage("commit c").call();
+
+ createBranch(b, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile(fileB, fileB);
+ git.add().addFilepattern(fileB).call();
+ RevCommit d = git.commit().setMessage("commit d").call();
+
+ checkoutBranch("refs/heads/master");
+ MergeResult m = git.merge().include(d.getId()).call();
+ assertEquals(MergeResult.MergeStatus.MERGED, m.getMergeStatus());
+
+ Iterator<RevCommit> rangeLog = git.log().addRange(b.getId(), m.getNewHead()).call().iterator();
+
+ RevCommit commit = rangeLog.next();
+ assertEquals(m.getNewHead(), commit.getId());
+ commit = rangeLog.next();
+ assertEquals(c.getId(), commit.getId());
+ commit = rangeLog.next();
+ assertEquals(d.getId(), commit.getId());
+ assertFalse(rangeLog.hasNext());
+ }
+
private void setCommitsAndMerge() throws Exception {
Git git = Git.wrap(db);
writeTrashFile("file1", "1\n2\n3\n4\n");
public void testInsertTie() throws Exception {
final RevCommit a = parseBody(commit());
final RevCommit b = parseBody(commit(0, a));
+ final RevCommit c = parseBody(commit(0, b));
+
{
q = create();
q.add(a);
q.add(b);
+ q.add(c);
assertCommit(a, q.next());
assertCommit(b, q.next());
+ assertCommit(c, q.next());
assertNull(q.next());
}
{
q = create();
+ q.add(c);
q.add(b);
q.add(a);
+ assertCommit(c, q.next());
assertCommit(b, q.next());
assertCommit(a, q.next());
assertNull(q.next());
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevSort;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode;
private List<RevCommit> calculatePickList(RevCommit headCommit)
throws GitAPIException, NoHeadException, IOException {
- Iterable<RevCommit> commitsToUse;
- try (Git git = new Git(repo)) {
- LogCommand cmd = git.log().addRange(upstreamCommit, headCommit);
- commitsToUse = cmd.call();
- }
List<RevCommit> cherryPickList = new ArrayList<>();
- for (RevCommit commit : commitsToUse) {
- if (preserveMerges || commit.getParentCount() == 1)
- cherryPickList.add(commit);
+ try (RevWalk r = new RevWalk(repo)) {
+ r.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER, true);
+ r.sort(RevSort.COMMIT_TIME_DESC, true);
+ r.markUninteresting(r.lookupCommit(upstreamCommit));
+ r.markStart(r.lookupCommit(headCommit));
+ Iterator<RevCommit> commitsToUse = r.iterator();
+ while (commitsToUse.hasNext()) {
+ RevCommit commit = commitsToUse.next();
+ if (preserveMerges || commit.getParentCount() == 1) {
+ cherryPickList.add(commit);
+ }
+ }
}
Collections.reverse(cherryPickList);
head = n;
} else {
Entry p = q.next;
- while (p != null && p.commit.commitTime > when) {
+ while (p != null && p.commit.commitTime >= when) {
q = p;
p = q.next;
}