import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.ReflogReader;
import org.junit.Test;
/**
// index shall be unchanged
assertEquals(indexState, indexState(CONTENT));
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+
+ if (reason == null) {
+ ReflogReader reader = db.getReflogReader(Constants.HEAD);
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("cherry-pick: "));
+ reader = db.getReflogReader(db.getBranch());
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("cherry-pick: "));
+ }
}
}
MergeResult result = git.merge().include(db.getRef(Constants.HEAD)).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
+ // no reflog entry written by merge
+ assertEquals("commit: initial commit",
+ db
+ .getReflogReader(Constants.HEAD).getLastEntry().getComment());
+ assertEquals("commit: initial commit",
+ db
+ .getReflogReader(db.getBranch()).getLastEntry().getComment());
}
@Test
MergeResult result = git.merge().include(db.getRef("refs/heads/branch1")).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
assertEquals(second, result.getNewHead());
-
+ // no reflog entry written by merge
+ assertEquals("commit: second commit", db
+ .getReflogReader(Constants.HEAD).getLastEntry().getComment());
+ assertEquals("commit: second commit", db
+ .getReflogReader(db.getBranch()).getLastEntry().getComment());
}
@Test
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
+ assertEquals("merge refs/heads/master: Fast-forward",
+ db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
+ assertEquals("merge refs/heads/master: Fast-forward",
+ db.getReflogReader(db.getBranch()).getLastEntry().getComment());
}
@Test
assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
+ assertEquals("merge refs/heads/master: Fast-forward",
+ db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
+ assertEquals("merge refs/heads/master: Fast-forward",
+ db.getReflogReader(db.getBranch()).getLastEntry().getComment());
}
@Test
MergeResult result = git.merge().setStrategy(mergeStrategy)
.include(db.getRef(Constants.MASTER)).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+ assertEquals(
+ "merge refs/heads/master: Merge made by "
+ + mergeStrategy.getName() + ".",
+ db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
+ assertEquals(
+ "merge refs/heads/master: Merge made by "
+ + mergeStrategy.getName() + ".",
+ db.getReflogReader(db.getBranch()).getLastEntry().getComment());
}
@Test
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
assertEquals("1\nb(1)\n3\n", read(new File(db.getWorkTree(), "b")));
+ assertEquals("merge " + secondCommit.getId().getName()
+ + ": Merge made by resolve.", db
+ .getReflogReader(Constants.HEAD)
+ .getLastEntry().getComment());
+ assertEquals("merge " + secondCommit.getId().getName()
+ + ": Merge made by resolve.", db
+ .getReflogReader(db.getBranch())
+ .getLastEntry().getComment());
}
@Test
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.ReflogReader;
import org.junit.Test;
/**
assertEquals("create b", history.next().getFullMessage());
assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext());
+
+ ReflogReader reader = db.getReflogReader(Constants.HEAD);
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("revert: Revert \""));
+ reader = db.getReflogReader(db.getBranch());
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("revert: Revert \""));
+
}
}