aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2010-05-19 10:01:25 +0200
committerChristian Halstrick <christian.halstrick@sap.com>2010-05-21 01:49:46 +0200
commit6ca9843f3ebbea152969a8b795efce1d4ff15dbf (patch)
tree516f608960debe427e540912941b300ace2b033a /org.eclipse.jgit.test/tst/org/eclipse/jgit
parent3c667b328ae086dcbfe159a22b3c86779a4590e5 (diff)
downloadjgit-6ca9843f3ebbea152969a8b795efce1d4ff15dbf.tar.gz
jgit-6ca9843f3ebbea152969a8b795efce1d4ff15dbf.zip
Added merge support to CommitCommand
The CommitCommand should take care to create a merge commit if the file $GIT_DIR/MERGE_HEAD exists. It should then read the parents for the merge commit out of this file. It should also take care that when commiting a merge and no commit message was specified to read the message from $GIT_DIR/MERGE_MSG. Finally the CommitCommand should remove these files if the commit succeeded. Change-Id: I4e292115085099d5b86546d2021680cb1454266c Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java47
1 files changed, 42 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
index d8fbb9578a..a62045dc9f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
@@ -42,14 +42,22 @@
*/
package org.eclipse.jgit.api;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
import org.eclipse.jgit.errors.UnmergedPathException;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
public class CommitAndLogCommandTests extends RepositoryTestCase {
public void testSomeCommits() throws NoHeadException, NoMessageException,
- UnmergedPathException, ConcurrentRefUpdateException {
+ UnmergedPathException, ConcurrentRefUpdateException,
+ JGitInternalException, WrongRepositoryStateException {
// do 4 commits
Git git = new Git(db);
@@ -62,8 +70,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
// check that all commits came in correctly
PersonIdent defaultCommitter = new PersonIdent(db);
- PersonIdent expectedAuthors[] = new PersonIdent[] {
- defaultCommitter, committer, author, author };
+ PersonIdent expectedAuthors[] = new PersonIdent[] { defaultCommitter,
+ committer, author, author };
PersonIdent expectedCommitters[] = new PersonIdent[] {
defaultCommitter, committer, defaultCommitter, committer };
String expectedMessages[] = new String[] { "initial commit",
@@ -82,7 +90,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
// try to do a commit without specifying a message. Should fail!
public void testWrongParams() throws UnmergedPathException,
- NoHeadException, ConcurrentRefUpdateException {
+ NoHeadException, ConcurrentRefUpdateException,
+ JGitInternalException, WrongRepositoryStateException {
Git git = new Git(db);
try {
git.commit().setAuthor(author).call();
@@ -95,7 +104,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
// exceptions
public void testMultipleInvocations() throws NoHeadException,
ConcurrentRefUpdateException, NoMessageException,
- UnmergedPathException {
+ UnmergedPathException, JGitInternalException,
+ WrongRepositoryStateException {
Git git = new Git(db);
CommitCommand commitCmd = git.commit();
commitCmd.setMessage("initial commit").call();
@@ -114,4 +124,31 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
} catch (IllegalStateException e) {
}
}
+
+ public void testMergeEmptyBranches() throws IOException, NoHeadException,
+ NoMessageException, ConcurrentRefUpdateException,
+ JGitInternalException, WrongRepositoryStateException {
+ Git git = new Git(db);
+ git.commit().setMessage("initial commit").call();
+ RefUpdate r = db.updateRef("refs/heads/side");
+ r.setNewObjectId(db.resolve(Constants.HEAD));
+ assertEquals(r.forceUpdate(), RefUpdate.Result.NEW);
+ RevCommit second = git.commit().setMessage("second commit").setCommitter(committer).call();
+ db.updateRef(Constants.HEAD).link("refs/heads/side");
+ RevCommit firstSide = git.commit().setMessage("first side commit").setAuthor(author).call();
+
+ FileWriter wr = new FileWriter(new File(db.getDirectory(),
+ Constants.MERGE_HEAD));
+ wr.write(ObjectId.toString(db.resolve("refs/heads/master")));
+ wr.close();
+ wr = new FileWriter(new File(db.getDirectory(), Constants.MERGE_MSG));
+ wr.write("merging");
+ wr.close();
+
+ RevCommit commit = git.commit().call();
+ RevCommit[] parents = commit.getParents();
+ assertEquals(parents[0], firstSide);
+ assertEquals(parents[1], second);
+ assertTrue(parents.length==2);
+ }
}