summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java83
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java11
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java126
5 files changed, 230 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
index 9eb44db866..38e7af50fa 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
@@ -55,7 +55,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
/**
- * Test cherry-pick command
+ * Test revert command
*/
public class RevertCommandTest extends RepositoryTestCase {
@Test
@@ -90,7 +90,10 @@ public class RevertCommandTest extends RepositoryTestCase {
checkFile(new File(db.getWorkTree(), "a"),
"first line\nsec. line\nthird line\nfourth line\n");
Iterator<RevCommit> history = git.log().call().iterator();
- assertEquals("Revert \"fixed a\"", history.next().getShortMessage());
+ RevCommit revertCommit = history.next();
+ String expectedMessage = "Revert \"fixed a\"\n\n"
+ + "This reverts commit " + fixingA.getId().getName() + ".\n";
+ assertEquals(expectedMessage, revertCommit.getFullMessage());
assertEquals("fixed b", history.next().getFullMessage());
assertEquals("fixed a", history.next().getFullMessage());
assertEquals("enlarged a", history.next().getFullMessage());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
index 80c779ddfd..77f1238547 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
@@ -176,16 +176,91 @@ public class IndexDiffTest extends RepositoryTestCase {
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff();
- assertEquals("[a, b]",
+ assertEquals("[b]",
new TreeSet<String>(diff.getChanged()).toString());
- assertEquals("[a]", diff.getAdded().toString());
+ assertEquals("[]", diff.getAdded().toString());
assertEquals("[]", diff.getRemoved().toString());
- assertEquals("[a]", diff.getMissing().toString());
- assertEquals("[a]", diff.getModified().toString());
+ assertEquals("[]", diff.getMissing().toString());
+ assertEquals("[]", diff.getModified().toString());
assertEquals("[a]", diff.getConflicting().toString());
}
@Test
+ public void testConflictingDeletedAndModified() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "1\na\n3\n");
+ writeTrashFile("b", "1\nb\n3\n");
+ git.add().addFilepattern("a").addFilepattern("b").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ // create side branch and delete "a"
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+ git.rm().addFilepattern("a").call();
+ RevCommit secondCommit = git.commit().setMessage("side").call();
+
+ // update a on master to generate conflict
+ checkoutBranch("refs/heads/master");
+ writeTrashFile("a", "1\na(main)\n3\n");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("main").call();
+
+ // merge side with master
+ MergeResult result = git.merge().include(secondCommit.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
+
+ FileTreeIterator iterator = new FileTreeIterator(db);
+ IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
+ diff.diff();
+
+ assertEquals("[]", new TreeSet<String>(diff.getChanged()).toString());
+ assertEquals("[]", diff.getAdded().toString());
+ assertEquals("[]", diff.getRemoved().toString());
+ assertEquals("[]", diff.getMissing().toString());
+ assertEquals("[]", diff.getModified().toString());
+ assertEquals("[a]", diff.getConflicting().toString());
+ }
+
+ @Test
+ public void testConflictingFromMultipleCreations() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "1\na\n3\n");
+ git.add().addFilepattern("a").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile("b", "1\nb(side)\n3\n");
+ git.add().addFilepattern("b").call();
+ RevCommit secondCommit = git.commit().setMessage("side").call();
+
+ checkoutBranch("refs/heads/master");
+
+ writeTrashFile("b", "1\nb(main)\n3\n");
+ git.add().addFilepattern("b").call();
+ git.commit().setMessage("main").call();
+
+ MergeResult result = git.merge().include(secondCommit.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
+
+ FileTreeIterator iterator = new FileTreeIterator(db);
+ IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
+ diff.diff();
+
+ assertEquals("[]", new TreeSet<String>(diff.getChanged()).toString());
+ assertEquals("[]", diff.getAdded().toString());
+ assertEquals("[]", diff.getRemoved().toString());
+ assertEquals("[]", diff.getMissing().toString());
+ assertEquals("[]", diff.getModified().toString());
+ assertEquals("[b]", diff.getConflicting().toString());
+ }
+
+ @Test
public void testUnchangedSimple() throws IOException {
GitIndex index = new GitIndex(db);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java
index 04cfa25197..4ccc0f9bed 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java
@@ -169,6 +169,15 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void testIntoHeadOtherThanMaster() throws IOException {
+ Ref a = db.getRef("refs/heads/a");
+ Ref b = db.getRef("refs/heads/b");
+ SymbolicRef head = new SymbolicRef("HEAD", b);
+ String message = formatter.format(Arrays.asList(a), head);
+ assertEquals("Merge branch 'a' into b", message);
+ }
+
+ @Test
public void testIntoSymbolicRefHeadPointingToMaster() throws IOException {
Ref a = db.getRef("refs/heads/a");
Ref master = db.getRef("refs/heads/master");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
index c86869d088..01d3820184 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
@@ -485,6 +485,17 @@ public class URIishTest {
}
@Test
+ public void testGetWindowsPathHumanishName()
+ throws IllegalArgumentException,
+ URISyntaxException {
+ if (File.separatorChar == '\\') {
+ String humanishName = new URIish("file:///C\\a\\b\\c.git/")
+ .getHumanishName();
+ assertEquals("c", humanishName);
+ }
+ }
+
+ @Test
public void testUserPasswordAndPort() throws URISyntaxException {
String str = "http://user:secret@host.xy:80/some/path";
URIish u = new URIish(str);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java
new file mode 100644
index 0000000000..4b45209ea4
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2011, Matthias Sohn <matthias.sohn@sap.com>
+ * 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.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.eclipse.jgit.util.RelativeDateFormatter.YEAR_IN_MILLIS;
+import static org.eclipse.jgit.util.RelativeDateFormatter.SECOND_IN_MILLIS;
+import static org.eclipse.jgit.util.RelativeDateFormatter.MINUTE_IN_MILLIS;
+import static org.eclipse.jgit.util.RelativeDateFormatter.HOUR_IN_MILLIS;
+import static org.eclipse.jgit.util.RelativeDateFormatter.DAY_IN_MILLIS;
+
+import java.util.Date;
+
+import org.eclipse.jgit.util.RelativeDateFormatter;
+import org.junit.Test;
+
+public class RelativeDateFormatterTest {
+
+ private void assertFormat(long ageFromNow, long timeUnit,
+ String expectedFormat) {
+ Date d = new Date(System.currentTimeMillis() - ageFromNow * timeUnit);
+ String s = RelativeDateFormatter.format(d);
+ assertEquals(expectedFormat, s);
+ }
+
+ @Test
+ public void testFuture() {
+ assertFormat(-100, YEAR_IN_MILLIS, "in the future");
+ assertFormat(-1, SECOND_IN_MILLIS, "in the future");
+ }
+
+ @Test
+ public void testFormatSeconds() {
+ assertFormat(1, SECOND_IN_MILLIS, "1 seconds ago");
+ assertFormat(89, SECOND_IN_MILLIS, "89 seconds ago");
+ }
+
+ @Test
+ public void testFormatMinutes() {
+ assertFormat(90, SECOND_IN_MILLIS, "2 minutes ago");
+ assertFormat(3, MINUTE_IN_MILLIS, "3 minutes ago");
+ assertFormat(60, MINUTE_IN_MILLIS, "60 minutes ago");
+ assertFormat(89, MINUTE_IN_MILLIS, "89 minutes ago");
+ }
+
+ @Test
+ public void testFormatHours() {
+ assertFormat(90, MINUTE_IN_MILLIS, "2 hours ago");
+ assertFormat(149, MINUTE_IN_MILLIS, "2 hours ago");
+ assertFormat(35, HOUR_IN_MILLIS, "35 hours ago");
+ }
+
+ @Test
+ public void testFormatDays() {
+ assertFormat(36, HOUR_IN_MILLIS, "2 days ago");
+ assertFormat(13, DAY_IN_MILLIS, "13 days ago");
+ }
+
+ @Test
+ public void testFormatWeeks() {
+ assertFormat(14, DAY_IN_MILLIS, "2 weeks ago");
+ assertFormat(69, DAY_IN_MILLIS, "10 weeks ago");
+ }
+
+ @Test
+ public void testFormatMonths() {
+ assertFormat(70, DAY_IN_MILLIS, "2 months ago");
+ assertFormat(75, DAY_IN_MILLIS, "3 months ago");
+ assertFormat(364, DAY_IN_MILLIS, "12 months ago");
+ }
+
+ @Test
+ public void testFormatYearsMonths() {
+ assertFormat(366, DAY_IN_MILLIS, "1 year, 0 month ago");
+ assertFormat(380, DAY_IN_MILLIS, "1 year, 1 month ago");
+ assertFormat(410, DAY_IN_MILLIS, "1 year, 2 months ago");
+ assertFormat(2, YEAR_IN_MILLIS, "2 years, 0 month ago");
+ assertFormat(1824, DAY_IN_MILLIS, "4 years, 12 months ago");
+ }
+
+ @Test
+ public void testFormatYears() {
+ assertFormat(5, YEAR_IN_MILLIS, "5 years ago");
+ assertFormat(60, YEAR_IN_MILLIS, "60 years ago");
+ }
+}