aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2013-05-10 00:10:27 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2013-05-11 22:45:29 +0200
commitc93a59330249677cd990820b59558a39f747009f (patch)
treee0e2c37be94e699edeb83245587cfc66e92f4522 /org.eclipse.jgit.test/tst
parenta62770a3dda7ac4a0fa7877e1cd42db3a99a8ecc (diff)
downloadjgit-c93a59330249677cd990820b59558a39f747009f.tar.gz
jgit-c93a59330249677cd990820b59558a39f747009f.zip
Fix CommitCommand not to destroy repo
There was a severe bug in CommitCommand which could corrupt repos. When merging an annotated tag the JGit MergeCommand writes correctly the ID of the tag (and not the id of the commit the tag was pointing to) into MERGE_HEAD. Native git does the same. But CommitCommand was reading this file and trusting blindly that it will contain only IDs of commits. Then the CommitCommand created a commit which has as parent a non-commit object (the tag object). That's so corrupt that even native git gives up when you call "git log" in such a repo. To reproduce that with EGit simply right-click on a tag in the Repository View and select Merge. The result was a corrupt repo! Bug: 336291 Change-Id: I24cd5de19ce6ca7b68b4052c9e73dcc6d207b57c Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index ba0847bd8d..67e1879d37 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
@@ -327,6 +327,33 @@ public class MergeCommandTest extends RepositoryTestCase {
}
@Test
+ public void testMergeTag() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "a");
+ git.add().addFilepattern("a").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile("b", "b");
+ git.add().addFilepattern("b").call();
+ RevCommit secondCommit = git.commit().setMessage("side").call();
+ Ref tag = git.tag().setAnnotated(true).setMessage("my tag 01")
+ .setName("tag01").setObjectId(secondCommit).call();
+
+ checkoutBranch("refs/heads/master");
+
+ writeTrashFile("a", "a2");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("main").call();
+
+ MergeResult result = git.merge().include(tag).setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+ }
+
+ @Test
public void testMergeMessage() throws Exception {
Git git = new Git(db);