summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorTomasz Zarna <Tomasz.Zarna@pl.ibm.com>2012-06-13 23:28:55 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2012-06-15 08:59:41 +0200
commit2656ac1b5acb9b73c6b47e2cf8830a0a0b2cc214 (patch)
tree1f48ca5fafef4ae7482c88b2084d532508bb944c /org.eclipse.jgit.test
parentc4087af65ddfd976f2a2513a773f50b1fd790336 (diff)
downloadjgit-2656ac1b5acb9b73c6b47e2cf8830a0a0b2cc214.tar.gz
jgit-2656ac1b5acb9b73c6b47e2cf8830a0a0b2cc214.zip
Add "--squash" option to MergeCommand
CQ: 6570 Bug: 351806 Change-Id: I5e47810376419264ecf4247b5a333af5c8945080 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java43
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java189
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java34
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java77
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java89
6 files changed, 430 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
index 3aec611f44..9b597d32da 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, GitHub Inc.
+ * Copyright (C) 2011-2012, GitHub Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -44,6 +44,7 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -68,7 +69,7 @@ import org.eclipse.jgit.util.FS;
import org.junit.Test;
/**
- * Unit tests of {@link CommitCommand}
+ * Unit tests of {@link CommitCommand}.
*/
public class CommitCommandTest extends RepositoryTestCase {
@@ -365,4 +366,42 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(file1Size, cache.getEntry("file1.txt").getLength());
assertEquals(0, cache.getEntry("file2.txt").getLength());
}
+
+ @Test
+ public void commitAfterSquashMerge() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit first = git.commit().setMessage("initial commit").call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ createBranch(first, "refs/heads/branch1");
+ checkoutBranch("refs/heads/branch1");
+
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("second commit").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ checkoutBranch("refs/heads/master");
+
+ MergeResult result = git.merge().include(db.getRef("branch1"))
+ .setSquash(true).call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+ assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED,
+ result.getMergeStatus());
+
+ // comment not set, should be inferred from SQUASH_MSG
+ RevCommit squashedCommit = git.commit().call();
+
+ assertEquals(1, squashedCommit.getParentCount());
+ assertNull(db.readSquashCommitMsg());
+ assertEquals("commit: Squashed commit of the following:", db
+ .getReflogReader(Constants.HEAD).getLastEntry().getComment());
+ assertEquals("commit: Squashed commit of the following:", db
+ .getReflogReader(db.getBranch()).getLastEntry().getComment());
+ }
}
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 30a94520d1..c6875b4832 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
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010, Stefan Lay <stefan.lay@sap.com>
- * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
+ * Copyright (C) 2010-2012, Christian Halstrick <christian.halstrick@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -45,6 +45,7 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -62,6 +63,9 @@ import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.GitDateFormatter;
+import org.eclipse.jgit.util.GitDateFormatter.Format;
+import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
@@ -74,6 +78,15 @@ public class MergeCommandTest extends RepositoryTestCase {
public static @DataPoints
MergeStrategy[] mergeStrategies = MergeStrategy.get();
+ private GitDateFormatter dateFormatter;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ dateFormatter = new GitDateFormatter(Format.DEFAULT);
+ }
+
@Test
public void testMergeInItself() throws Exception {
Git git = new Git(db);
@@ -1096,6 +1109,180 @@ public class MergeCommandTest extends RepositoryTestCase {
assertFalse(canExecute(git, "mergeableButDirty"));
}
+ @Test
+ public void testSquashFastForward() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit first = git.commit().setMessage("initial commit").call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ createBranch(first, "refs/heads/branch1");
+ checkoutBranch("refs/heads/branch1");
+
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ RevCommit second = git.commit().setMessage("second commit").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ writeTrashFile("file3", "file3");
+ git.add().addFilepattern("file3").call();
+ RevCommit third = git.commit().setMessage("third commit").call();
+ assertTrue(new File(db.getWorkTree(), "file3").exists());
+
+ checkoutBranch("refs/heads/master");
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ assertFalse(new File(db.getWorkTree(), "file2").exists());
+ assertFalse(new File(db.getWorkTree(), "file3").exists());
+
+ MergeResult result = git.merge().include(db.getRef("branch1"))
+ .setSquash(true).call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+ assertTrue(new File(db.getWorkTree(), "file3").exists());
+ assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED,
+ result.getMergeStatus());
+ assertEquals(first, result.getNewHead()); // HEAD didn't move
+ assertEquals(first, db.resolve(Constants.HEAD + "^{commit}"));
+
+ assertEquals(
+ "Squashed commit of the following:\n\ncommit "
+ + third.getName()
+ + "\nAuthor: "
+ + third.getAuthorIdent().getName()
+ + " <"
+ + third.getAuthorIdent().getEmailAddress()
+ + ">\nDate: "
+ + dateFormatter.formatDate(third
+ .getAuthorIdent())
+ + "\n\n\tthird commit\n\ncommit "
+ + second.getName()
+ + "\nAuthor: "
+ + second.getAuthorIdent().getName()
+ + " <"
+ + second.getAuthorIdent().getEmailAddress()
+ + ">\nDate: "
+ + dateFormatter.formatDate(second
+ .getAuthorIdent()) + "\n\n\tsecond commit\n",
+ db.readSquashCommitMsg());
+ assertNull(db.readMergeCommitMsg());
+
+ Status stat = git.status().call();
+ assertEquals(StatusCommandTest.set("file2", "file3"), stat.getAdded());
+ }
+
+ @Test
+ public void testSquashMerge() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit first = git.commit().setMessage("initial commit").call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ createBranch(first, "refs/heads/branch1");
+
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ RevCommit second = git.commit().setMessage("second commit").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ checkoutBranch("refs/heads/branch1");
+
+ writeTrashFile("file3", "file3");
+ git.add().addFilepattern("file3").call();
+ RevCommit third = git.commit().setMessage("third commit").call();
+ assertTrue(new File(db.getWorkTree(), "file3").exists());
+
+ checkoutBranch("refs/heads/master");
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+ assertFalse(new File(db.getWorkTree(), "file3").exists());
+
+ MergeResult result = git.merge().include(db.getRef("branch1"))
+ .setSquash(true).call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+ assertTrue(new File(db.getWorkTree(), "file3").exists());
+ assertEquals(MergeResult.MergeStatus.MERGED_SQUASHED,
+ result.getMergeStatus());
+ assertEquals(second, result.getNewHead()); // HEAD didn't move
+ assertEquals(second, db.resolve(Constants.HEAD + "^{commit}"));
+
+ assertEquals(
+ "Squashed commit of the following:\n\ncommit "
+ + third.getName()
+ + "\nAuthor: "
+ + third.getAuthorIdent().getName()
+ + " <"
+ + third.getAuthorIdent().getEmailAddress()
+ + ">\nDate: "
+ + dateFormatter.formatDate(third
+ .getAuthorIdent()) + "\n\n\tthird commit\n",
+ db.readSquashCommitMsg());
+ assertNull(db.readMergeCommitMsg());
+
+ Status stat = git.status().call();
+ assertEquals(StatusCommandTest.set("file3"), stat.getAdded());
+ }
+
+ @Test
+ public void testSquashMergeConflict() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit first = git.commit().setMessage("initial commit").call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ createBranch(first, "refs/heads/branch1");
+
+ writeTrashFile("file2", "master");
+ git.add().addFilepattern("file2").call();
+ RevCommit second = git.commit().setMessage("second commit").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ checkoutBranch("refs/heads/branch1");
+
+ writeTrashFile("file2", "branch");
+ git.add().addFilepattern("file2").call();
+ RevCommit third = git.commit().setMessage("third commit").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ checkoutBranch("refs/heads/master");
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ MergeResult result = git.merge().include(db.getRef("branch1"))
+ .setSquash(true).call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+ assertEquals(MergeResult.MergeStatus.CONFLICTING,
+ result.getMergeStatus());
+ assertNull(result.getNewHead());
+ assertEquals(second, db.resolve(Constants.HEAD + "^{commit}"));
+
+ assertEquals(
+ "Squashed commit of the following:\n\ncommit "
+ + third.getName()
+ + "\nAuthor: "
+ + third.getAuthorIdent().getName()
+ + " <"
+ + third.getAuthorIdent().getEmailAddress()
+ + ">\nDate: "
+ + dateFormatter.formatDate(third
+ .getAuthorIdent()) + "\n\n\tthird commit\n",
+ db.readSquashCommitMsg());
+ assertEquals("\nConflicts:\n\tfile2\n", db.readMergeCommitMsg());
+
+ Status stat = git.status().call();
+ assertEquals(StatusCommandTest.set("file2"), stat.getConflicting());
+ }
+
private void setExecutable(Git git, String path, boolean executable) {
FS.DETECTED.setExecute(
new File(git.getRepository().getWorkTree(), path), executable);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index 0806cf0dd0..c55775c9fe 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Chris Aniszczyk <caniszczyk@gmail.com>
+ * Copyright (C) 2011-2012, Chris Aniszczyk <caniszczyk@gmail.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -46,6 +46,7 @@ import static org.eclipse.jgit.api.ResetCommand.ResetType.HARD;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -359,6 +360,37 @@ public class ResetCommandTest extends RepositoryTestCase {
assertTrue(head.equals(secondCommit));
}
+ @Test
+ public void testHardResetAfterSquashMerge() throws Exception {
+ Git g = new Git(db);
+
+ writeTrashFile("file1", "file1");
+ g.add().addFilepattern("file1").call();
+ RevCommit first = g.commit().setMessage("initial commit").call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ createBranch(first, "refs/heads/branch1");
+ checkoutBranch("refs/heads/branch1");
+
+ writeTrashFile("file2", "file2");
+ g.add().addFilepattern("file2").call();
+ g.commit().setMessage("second commit").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ checkoutBranch("refs/heads/master");
+
+ MergeResult result = g.merge().include(db.getRef("branch1"))
+ .setSquash(true).call();
+
+ assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED,
+ result.getMergeStatus());
+ assertNotNull(db.readSquashCommitMsg());
+
+ g.reset().setMode(ResetType.HARD).setRef(first.getName()).call();
+
+ assertNull(db.readSquashCommitMsg());
+ }
+
private void assertReflog(ObjectId prevHead, ObjectId head)
throws IOException {
// Check the reflog for HEAD
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java
index 4e128e7f25..ed1f96776b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
+ * Copyright (C) 2010-2012 Christian Halstrick <christian.halstrick@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -78,7 +78,7 @@ public class MergeHeadMsgTest extends RepositoryTestCase {
assertEquals(db.readMergeHeads().size(), 2);
assertEquals(db.readMergeHeads().get(0), ObjectId.zeroId());
assertEquals(db.readMergeHeads().get(1), ObjectId.fromString(sampleId));
- db.writeMergeHeads(Collections.EMPTY_LIST);
+ db.writeMergeHeads(Collections.<ObjectId> emptyList());
assertEquals(read(new File(db.getDirectory(), "MERGE_HEAD")), "");
assertEquals(db.readMergeHeads(), null);
fos = new FileOutputStream(new File(db.getDirectory(),
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
new file mode 100644
index 0000000000..4374e4747e
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2012, IBM Corporation and others.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.lib;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class SquashCommitMsgTest extends RepositoryTestCase {
+ private static final String squashMsg = "squashed commit";
+
+ @Test
+ public void testReadWriteMergeMsg() throws IOException {
+ assertEquals(db.readSquashCommitMsg(), null);
+ assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
+ db.writeSquashCommitMsg(squashMsg);
+ assertEquals(squashMsg, db.readSquashCommitMsg());
+ assertEquals(read(new File(db.getDirectory(), Constants.SQUASH_MSG)),
+ squashMsg);
+ db.writeSquashCommitMsg(null);
+ assertEquals(db.readSquashCommitMsg(), null);
+ assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
+ FileOutputStream fos = new FileOutputStream(new File(db.getDirectory(),
+ Constants.SQUASH_MSG));
+ try {
+ fos.write(squashMsg.getBytes(Constants.CHARACTER_ENCODING));
+ } finally {
+ fos.close();
+ }
+ assertEquals(db.readSquashCommitMsg(), squashMsg);
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java
new file mode 100644
index 0000000000..4274d8baff
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2012, IBM Corporation and others.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.merge;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.util.GitDateFormatter;
+import org.eclipse.jgit.util.GitDateFormatter.Format;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test construction of squash message by {@link SquashMessageFormatterTest}.
+ */
+public class SquashMessageFormatterTest extends SampleDataRepositoryTestCase {
+ private GitDateFormatter dateFormatter;
+ private SquashMessageFormatter msgFormatter;
+ private RevCommit revCommit;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ dateFormatter = new GitDateFormatter(Format.DEFAULT);
+ msgFormatter = new SquashMessageFormatter();
+ }
+
+ @Test
+ public void testCommit() throws Exception {
+ Git git = new Git(db);
+ revCommit = git.commit().setMessage("squash_me").call();
+
+ Ref master = db.getRef("refs/heads/master");
+ String message = msgFormatter.format(Arrays.asList(revCommit), master);
+ assertEquals(
+ "Squashed commit of the following:\n\ncommit "
+ + revCommit.getName() + "\nAuthor: "
+ + revCommit.getAuthorIdent().getName() + " <"
+ + revCommit.getAuthorIdent().getEmailAddress()
+ + ">\nDate: " + dateFormatter.formatDate(author)
+ + "\n\n\tsquash_me\n", message);
+ }
+}