diff options
Diffstat (limited to 'org.eclipse.jgit.test')
3 files changed, 282 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index 925976d300..f074273137 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -63,6 +63,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Set; +import org.eclipse.jgit.api.MergeCommand.FastForwardMode; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.util.FS; @@ -321,6 +322,74 @@ public class ConfigTest { } @Test + public void testGetFastForwardMergeoptions() throws ConfigInvalidException { + Config c = new Config(null); // not set + assertSame(FastForwardMode.FF, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, FastForwardMode.FF)); + c = parse("[branch \"side\"]\n\tmergeoptions = --ff-only\n"); + assertSame(FastForwardMode.FF_ONLY, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, + FastForwardMode.FF_ONLY)); + c = parse("[branch \"side\"]\n\tmergeoptions = --ff\n"); + assertSame(FastForwardMode.FF, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, FastForwardMode.FF)); + c = parse("[branch \"side\"]\n\tmergeoptions = --no-ff\n"); + assertSame(FastForwardMode.NO_FF, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, FastForwardMode.NO_FF)); + } + + @Test + public void testSetFastForwardMergeoptions() { + final Config c = new Config(); + c.setEnum("branch", "side", "mergeoptions", FastForwardMode.FF); + assertEquals("[branch \"side\"]\n\tmergeoptions = --ff\n", c.toText()); + c.setEnum("branch", "side", "mergeoptions", FastForwardMode.FF_ONLY); + assertEquals("[branch \"side\"]\n\tmergeoptions = --ff-only\n", + c.toText()); + c.setEnum("branch", "side", "mergeoptions", FastForwardMode.NO_FF); + assertEquals("[branch \"side\"]\n\tmergeoptions = --no-ff\n", + c.toText()); + } + + @Test + public void testGetFastForwardMerge() throws ConfigInvalidException { + Config c = new Config(null); // not set + assertSame(FastForwardMode.Merge.TRUE, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.TRUE)); + c = parse("[merge]\n\tff = only\n"); + assertSame(FastForwardMode.Merge.ONLY, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.ONLY)); + c = parse("[merge]\n\tff = true\n"); + assertSame(FastForwardMode.Merge.TRUE, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.TRUE)); + c = parse("[merge]\n\tff = false\n"); + assertSame(FastForwardMode.Merge.FALSE, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.FALSE)); + } + + @Test + public void testSetFastForwardMerge() { + final Config c = new Config(); + c.setEnum("merge", null, "ff", + FastForwardMode.Merge.valueOf(FastForwardMode.FF)); + assertEquals("[merge]\n\tff = true\n", c.toText()); + c.setEnum("merge", null, "ff", + FastForwardMode.Merge.valueOf(FastForwardMode.FF_ONLY)); + assertEquals("[merge]\n\tff = only\n", c.toText()); + c.setEnum("merge", null, "ff", + FastForwardMode.Merge.valueOf(FastForwardMode.NO_FF)); + assertEquals("[merge]\n\tff = false\n", c.toText()); + } + + @Test public void testReadLong() throws ConfigInvalidException { assertReadLong(1L); assertReadLong(-1L); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java index 4752a3fb20..281715f5ee 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java @@ -66,6 +66,7 @@ import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository.BranchBuilder; +import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; @@ -77,6 +78,7 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.PackIndex.MutableEntry; import org.eclipse.jgit.storage.pack.PackConfig; import org.eclipse.jgit.storage.pack.PackWriter; +import org.eclipse.jgit.storage.pack.PackWriter.ObjectIdSet; import org.eclipse.jgit.transport.PackParser; import org.junit.After; import org.junit.Before; @@ -463,7 +465,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { RevCommit c1 = bb.commit().add("f", contentA).create(); testRepo.getRevWalk().parseHeaders(c1); PackIndex pf1 = writePack(repo, Collections.singleton(c1), - Collections.<PackIndex> emptySet()); + Collections.<ObjectIdSet> emptySet()); assertContent( pf1, Arrays.asList(c1.getId(), c1.getTree().getId(), @@ -472,7 +474,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { RevCommit c2 = bb.commit().add("f", contentB).create(); testRepo.getRevWalk().parseHeaders(c2); PackIndex pf2 = writePack(repo, Collections.singleton(c2), - Collections.singleton(pf1)); + Collections.singleton(objectIdSet(pf1))); assertContent( pf2, Arrays.asList(c2.getId(), c2.getTree().getId(), @@ -490,12 +492,12 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { } private static PackIndex writePack(FileRepository repo, - Set<? extends ObjectId> want, Set<PackIndex> excludeObjects) + Set<? extends ObjectId> want, Set<ObjectIdSet> excludeObjects) throws IOException { PackWriter pw = new PackWriter(repo); pw.setDeltaBaseAsOffset(true); pw.setReuseDeltaCommits(false); - for (PackIndex idx : excludeObjects) + for (ObjectIdSet idx : excludeObjects) pw.excludeObjects(idx); pw.preparePack(NullProgressMonitor.INSTANCE, want, Collections.<ObjectId> emptySet()); @@ -668,4 +670,12 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { assertEquals(objectsOrder[i++].toObjectId(), me.toObjectId()); } } + + private static ObjectIdSet objectIdSet(final PackIndex idx) { + return new ObjectIdSet() { + public boolean contains(AnyObjectId objectId) { + return idx.hasObject(objectId); + } + }; + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java new file mode 100644 index 0000000000..13fe426873 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2013, Robin Rosenberg <robin.rosenberg@dewire.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.treewalk.filter; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.eclipse.jgit.dircache.DirCache; +import org.eclipse.jgit.dircache.DirCacheEditor; +import org.eclipse.jgit.dircache.DirCacheEntry; +import org.eclipse.jgit.dircache.DirCacheIterator; +import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; +import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.FileMode; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.storage.file.FileRepository; +import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Before; +import org.junit.Test; + +public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { + + private FileRepository db; + + @Before + public void setUp() throws Exception { + super.setUp(); + db = createWorkRepository(); + } + + @Test + public void testEmpty() throws IOException { + DirCache dc1 = DirCache.newInCore(); + DirCache dc2 = DirCache.newInCore(); + TreeWalk tw = new TreeWalk(db); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + assertFalse(tw.next()); + } + + static final class AddEdit extends PathEdit { + + private final ObjectId data; + + private final long length; + + private boolean assumeValid; + + private FileMode type; + + public AddEdit(String entryPath, FileMode type, ObjectId data, + long length, + boolean assumeValid) { + super(entryPath); + this.type = type; + this.data = data; + this.length = length; + this.assumeValid = assumeValid; + } + + @Override + public void apply(DirCacheEntry ent) { + ent.setFileMode(type); + ent.setLength(length); + ent.setObjectId(data); + ent.setAssumeValid(assumeValid); + } + } + + private ObjectId id(String data) { + byte[] bytes = data.getBytes(); + return db.newObjectInserter().idFor(Constants.OBJ_BLOB, bytes); + } + + @Test + public void testOneOnly() throws IOException { + DirCache dc1 = DirCache.newInCore(); + DirCache dc2 = DirCache.newInCore(); + DirCacheEditor editor = dc1.editor(); + editor.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); + editor.finish(); + + TreeWalk tw = new TreeWalk(db); + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); + assertTrue(tw.next()); + assertEquals("a/a", tw.getPathString()); + assertFalse(tw.next()); + } + + @Test + public void testTwoSame() throws IOException { + DirCache dc1 = DirCache.newInCore(); + DirCache dc2 = DirCache.newInCore(); + DirCacheEditor ed1 = dc1.editor(); + ed1.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); + ed1.finish(); + DirCacheEditor ed2 = dc2.editor(); + ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); + ed2.finish(); + + TreeWalk tw = new TreeWalk(db); + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); + + assertFalse(tw.next()); + } + + @Test + public void testTwoSameDifferByAssumeValid() throws IOException { + DirCache dc1 = DirCache.newInCore(); + DirCache dc2 = DirCache.newInCore(); + DirCacheEditor ed1 = dc1.editor(); + ed1.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); + ed1.finish(); + DirCacheEditor ed2 = dc2.editor(); + ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true)); + ed2.finish(); + + TreeWalk tw = new TreeWalk(db); + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); + + assertTrue(tw.next()); + assertEquals("a/a", tw.getPathString()); + assertFalse(tw.next()); + } + + @Test + public void testTwoSameSameAssumeValidDifferentContent() + throws IOException { + DirCache dc1 = DirCache.newInCore(); + DirCache dc2 = DirCache.newInCore(); + DirCacheEditor ed1 = dc1.editor(); + ed1.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true)); + ed1.finish(); + DirCacheEditor ed2 = dc2.editor(); + ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("b"), 1, true)); + ed2.finish(); + + TreeWalk tw = new TreeWalk(db); + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); + + assertFalse(tw.next()); + } +} |