]> source.dussan.org Git - jgit.git/commitdiff
Test the reflog message for commit, cherry-pick, revert and merge 07/4207/2
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 8 Sep 2011 17:42:19 +0000 (19:42 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 21 Sep 2011 21:36:55 +0000 (23:36 +0200)
Change-Id: I319f09577b3e04f6c31399fe8e57e9a9ad2c8a6c
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java

index 94af81e81244e7f54b7bf140ca660960bd67f358..9f92c045c08fe05e87000d9edeb1c661e00c7557 100644 (file)
@@ -59,6 +59,7 @@ import org.eclipse.jgit.lib.RepositoryState;
 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;
 
 /**
@@ -223,5 +224,14 @@ public class CherryPickCommandTest extends RepositoryTestCase {
                // 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: "));
+               }
        }
 }
index fa97198d8cae6c9e3793fa3a51ed69ee92def2f3..aac1dc149658520380e37c0d4b103dce77bb4b21 100644 (file)
@@ -109,6 +109,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
                assertEquals(l, -1);
                ReflogReader reader = db.getReflogReader(Constants.HEAD);
                assertTrue(reader.getLastEntry().getComment().startsWith("commit:"));
+               reader = db.getReflogReader(db.getBranch());
+               assertTrue(reader.getLastEntry().getComment().startsWith("commit:"));
        }
 
        @Test
@@ -318,6 +320,9 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
                ReflogReader reader = db.getReflogReader(Constants.HEAD);
                assertTrue(reader.getLastEntry().getComment()
                                .startsWith("commit (amend):"));
+               reader = db.getReflogReader(db.getBranch());
+               assertTrue(reader.getLastEntry().getComment()
+                               .startsWith("commit (amend):"));
        }
 
        @Test
index 1c682cae10612969e086f7f3ef521275a0ebb794..bb9058891804e7020c46c87552e3d4ec0b7371e8 100644 (file)
@@ -80,6 +80,13 @@ public class MergeCommandTest extends RepositoryTestCase {
 
                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
@@ -92,7 +99,11 @@ public class MergeCommandTest extends RepositoryTestCase {
                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
@@ -109,6 +120,10 @@ public class MergeCommandTest extends RepositoryTestCase {
 
                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
@@ -136,6 +151,10 @@ public class MergeCommandTest extends RepositoryTestCase {
                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
@@ -190,6 +209,14 @@ public class MergeCommandTest extends RepositoryTestCase {
                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
@@ -370,6 +397,14 @@ public class MergeCommandTest extends RepositoryTestCase {
                                .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
index 38e7af50faff65e519492b9aca977aca92322799..11cef635af36827f505480bdeaf214f97dcf3626 100644 (file)
@@ -50,8 +50,10 @@ import java.util.Iterator;
 
 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;
 
 /**
@@ -100,5 +102,13 @@ public class RevertCommandTest extends RepositoryTestCase {
                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 \""));
+
        }
 }