Browse Source

Test the reflog message for commit, cherry-pick, revert and merge

Change-Id: I319f09577b3e04f6c31399fe8e57e9a9ad2c8a6c
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-1.2
Robin Rosenberg 13 years ago committed by Matthias Sohn
parent
commit
ad50a0b7c0
  1. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
  2. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
  3. 37
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  4. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java

@ -59,6 +59,7 @@ import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.ReflogReader;
import org.junit.Test; import org.junit.Test;
/** /**
@ -223,5 +224,14 @@ public class CherryPickCommandTest extends RepositoryTestCase {
// index shall be unchanged // index shall be unchanged
assertEquals(indexState, indexState(CONTENT)); assertEquals(indexState, indexState(CONTENT));
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); 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: "));
}
} }
} }

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java

@ -109,6 +109,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
assertEquals(l, -1); assertEquals(l, -1);
ReflogReader reader = db.getReflogReader(Constants.HEAD); ReflogReader reader = db.getReflogReader(Constants.HEAD);
assertTrue(reader.getLastEntry().getComment().startsWith("commit:")); assertTrue(reader.getLastEntry().getComment().startsWith("commit:"));
reader = db.getReflogReader(db.getBranch());
assertTrue(reader.getLastEntry().getComment().startsWith("commit:"));
} }
@Test @Test
@ -318,6 +320,9 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
ReflogReader reader = db.getReflogReader(Constants.HEAD); ReflogReader reader = db.getReflogReader(Constants.HEAD);
assertTrue(reader.getLastEntry().getComment() assertTrue(reader.getLastEntry().getComment()
.startsWith("commit (amend):")); .startsWith("commit (amend):"));
reader = db.getReflogReader(db.getBranch());
assertTrue(reader.getLastEntry().getComment()
.startsWith("commit (amend):"));
} }
@Test @Test

37
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -80,6 +80,13 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(db.getRef(Constants.HEAD)).call(); MergeResult result = git.merge().include(db.getRef(Constants.HEAD)).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); 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 @Test
@ -92,7 +99,11 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(db.getRef("refs/heads/branch1")).call(); MergeResult result = git.merge().include(db.getRef("refs/heads/branch1")).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
assertEquals(second, result.getNewHead()); 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 @Test
@ -109,6 +120,10 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead()); 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 @Test
@ -136,6 +151,10 @@ public class MergeCommandTest extends RepositoryTestCase {
assertTrue(new File(db.getWorkTree(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead()); 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 @Test
@ -190,6 +209,14 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().setStrategy(mergeStrategy) MergeResult result = git.merge().setStrategy(mergeStrategy)
.include(db.getRef(Constants.MASTER)).call(); .include(db.getRef(Constants.MASTER)).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); 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 @Test
@ -370,6 +397,14 @@ public class MergeCommandTest extends RepositoryTestCase {
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED, result.getMergeStatus());
assertEquals("1\nb(1)\n3\n", read(new File(db.getWorkTree(), "b"))); 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 @Test

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java

@ -50,8 +50,10 @@ import java.util.Iterator;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.ReflogReader;
import org.junit.Test; import org.junit.Test;
/** /**
@ -100,5 +102,13 @@ public class RevertCommandTest extends RepositoryTestCase {
assertEquals("create b", history.next().getFullMessage()); assertEquals("create b", history.next().getFullMessage());
assertEquals("create a", history.next().getFullMessage()); assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext()); 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 \""));
} }
} }

Loading…
Cancel
Save