diff options
author | Shawn Pearce <sop@google.com> | 2013-03-11 18:33:55 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2013-03-11 18:33:55 -0400 |
commit | ef91da360590b2e2bc64cb895a2aa6b58be7afb5 (patch) | |
tree | 84c6d94c77befa3baffb73e23f3c86cea350b53d /org.eclipse.jgit.test | |
parent | 9105e1c9afe161a84cf612d532454f57207383fa (diff) | |
parent | 30ba407a9a8983fd7aaed73d8baa70469dee0689 (diff) | |
download | jgit-ef91da360590b2e2bc64cb895a2aa6b58be7afb5.tar.gz jgit-ef91da360590b2e2bc64cb895a2aa6b58be7afb5.zip |
Merge "Add a NameRevCommand for describing IDs in terms of refnames"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java new file mode 100644 index 0000000000..82839e3bc1 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2013, Google Inc. + * 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.api; + +import static org.junit.Assert.assertEquals; + +import java.util.Map; + +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.junit.Before; +import org.junit.Test; + +public class NameRevCommandTest extends RepositoryTestCase { + private TestRepository<Repository> tr; + private Git git; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + tr = new TestRepository<Repository>(db); + git = new Git(db); + } + + @Test + public void nameExact() throws Exception { + RevCommit c = tr.commit().create(); + tr.update("master", c); + assertOneResult("master", c); + } + + @Test + public void prefix() throws Exception { + RevCommit c = tr.commit().create(); + tr.update("refs/heads/master", c); + tr.update("refs/tags/tag", c); + assertOneResult("master", c); + assertOneResult("master", + git.nameRev().addPrefix("refs/heads/").addPrefix("refs/tags/"), + c); + assertOneResult("tag", + git.nameRev().addPrefix("refs/tags/").addPrefix("refs/heads/"), + c); + } + + @Test + public void simpleAncestor() throws Exception { + // 0--1--2 + RevCommit c0 = tr.commit().create(); + RevCommit c1 = tr.commit().parent(c0).create(); + RevCommit c2 = tr.commit().parent(c1).create(); + tr.update("master", c2); + Map<ObjectId, String> result = git.nameRev().add(c0).add(c1).add(c2).call(); + assertEquals(3, result.size()); + assertEquals("master~2", result.get(c0)); + assertEquals("master~1", result.get(c1)); + assertEquals("master", result.get(c2)); + } + + @Test + public void multiplePathsNoMerge() throws Exception { + // 0--1 <- master + // \-2--3 <- branch + RevCommit c0 = tr.commit().create(); + RevCommit c1 = tr.commit().parent(c0).create(); + RevCommit c2 = tr.commit().parent(c0).create(); + RevCommit c3 = tr.commit().parent(c2).create(); + tr.update("master", c1); + tr.update("branch", c3); + assertOneResult("master~1", c0); + } + + @Test + public void onePathMerge() throws Exception { + // 0--1--3 + // \-2-/ + RevCommit c0 = tr.commit().create(); + RevCommit c1 = tr.commit().parent(c0).create(); + RevCommit c2 = tr.commit().parent(c0).create(); + RevCommit c3 = tr.commit().parent(c1).parent(c2).create(); + tr.update("master", c3); + assertOneResult("master^1~1", c0); + } + + @Test + public void oneMergeDifferentLengths() throws Exception { + // 0--1--2--4 + // \--3---/ + RevCommit c0 = tr.commit().create(); + RevCommit c1 = tr.commit().parent(c0).create(); + RevCommit c2 = tr.commit().parent(c1).create(); + RevCommit c3 = tr.commit().parent(c0).create(); + RevCommit c4 = tr.commit().parent(c2).parent(c3).create(); + tr.update("master", c4); + assertOneResult("master^2~1", c0); + } + + @Test + public void longerPathWithoutMerge() throws Exception { + // 0--1--2--4 <- master + // \ \-3-/ + // \--5--6--7--8--9 <- branch + RevCommit c0 = tr.commit().create(); + RevCommit c1 = tr.commit().parent(c0).create(); + RevCommit c2 = tr.commit().parent(c1).create(); + RevCommit c3 = tr.commit().parent(c1).create(); + RevCommit c4 = tr.commit().parent(c2).parent(c3).create(); + RevCommit c5 = tr.commit().parent(c0).create(); + RevCommit c6 = tr.commit().parent(c5).create(); + RevCommit c7 = tr.commit().parent(c6).create(); + RevCommit c8 = tr.commit().parent(c7).create(); + RevCommit c9 = tr.commit().parent(c8).create(); + tr.update("master", c4); + tr.update("branch", c9); + assertOneResult("branch~5", c0); + } + + private static void assertOneResult(String expected, NameRevCommand nameRev, + ObjectId id) throws Exception { + Map<ObjectId, String> result = nameRev.add(id).call(); + assertEquals(1, result.size()); + assertEquals(expected, result.get(id)); + } + + private void assertOneResult(String expected, ObjectId id) throws Exception { + assertOneResult(expected, git.nameRev(), id); + } +} |