]> source.dussan.org Git - jgit.git/commitdiff
Add some test cases for symbolic links with Java7 95/15395/21
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 10 Jul 2013 22:19:10 +0000 (00:19 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 12 Feb 2014 22:00:38 +0000 (23:00 +0100)
Change-Id: Ia4c9c7902316bc0a90fb89d8dea9902835c06dfa

org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF
org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java [new file with mode: 0644]
org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/TreeWalkJava7Test.java [new file with mode: 0644]

index 69220785ece58854666978b700ea49bbdb3021c2..a20c4e379cca3dbdc42d14324363de86118491b0 100644 (file)
@@ -6,10 +6,12 @@ Bundle-Version: 3.3.0.qualifier
 Bundle-Vendor: %provider_name
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Import-Package: org.eclipse.jgit.api;version="[3.3.0,3.4.0)",
+ org.eclipse.jgit.dircache;version="[3.3.0,3.4.0)",
  org.eclipse.jgit.internal.storage.file;version="3.3.0",
  org.eclipse.jgit.junit;version="[3.3.0,3.4.0)",
  org.eclipse.jgit.lib;version="[3.3.0,3.4.0)",
  org.eclipse.jgit.revwalk;version="[3.3.0,3.4.0)",
  org.eclipse.jgit.storage.file;version="[3.3.0,3.4.0)",
+ org.eclipse.jgit.treewalk;version="[3.3.0,3.4.0)",
  org.eclipse.jgit.util;version="[3.3.0,3.4.0)",
  org.junit;version="[4.11.0,5.0.0)"
diff --git a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java
new file mode 100644 (file)
index 0000000..484467b
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2012-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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.ResetCommand.ResetType;
+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.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
+import org.junit.Test;
+
+public class FileTreeIteratorJava7Test extends RepositoryTestCase {
+       @Test
+       public void testFileModeSymLinkIsNotATree() throws IOException {
+               FS fs = db.getFS();
+               // mål = target in swedish, just to get som unicode in here
+               writeTrashFile("mål/data", "targetdata");
+               fs.createSymLink(new File(trash, "länk"), "mål");
+               FileTreeIterator fti = new FileTreeIterator(db);
+               assertFalse(fti.eof());
+               assertEquals("länk", fti.getEntryPathString());
+               assertEquals(FileMode.SYMLINK, fti.getEntryFileMode());
+               fti.next(1);
+               assertFalse(fti.eof());
+               assertEquals("mål", fti.getEntryPathString());
+               assertEquals(FileMode.TREE, fti.getEntryFileMode());
+               fti.next(1);
+               assertTrue(fti.eof());
+       }
+
+       @Test
+       public void testSymlinkNotModifiedThoughNormalized() throws Exception {
+               DirCache dc = db.lockDirCache();
+               DirCacheEditor dce = dc.editor();
+               final String UNNORMALIZED = "target/";
+               final byte[] UNNORMALIZED_BYTES = Constants.encode(UNNORMALIZED);
+               ObjectInserter oi = db.newObjectInserter();
+               final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
+                               UNNORMALIZED_BYTES, 0,
+                               UNNORMALIZED_BYTES.length);
+               oi.release();
+               dce.add(new DirCacheEditor.PathEdit("link") {
+                       @Override
+                       public void apply(DirCacheEntry ent) {
+                               ent.setFileMode(FileMode.SYMLINK);
+                               ent.setObjectId(linkid);
+                               ent.setLength(UNNORMALIZED_BYTES.length);
+                       }
+               });
+               assertTrue(dce.commit());
+               new Git(db).commit().setMessage("Adding link").call();
+               new Git(db).reset().setMode(ResetType.HARD).call();
+               DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
+               FileTreeIterator fti = new FileTreeIterator(db);
+               fti.next(1); // Skips .git
+
+               // self-check
+               assertEquals("link", fti.getEntryPathString());
+               assertEquals("link", dci.getEntryPathString());
+
+               // test
+               assertFalse(fti.isModified(dci.getDirCacheEntry(), true));
+       }
+
+       /**
+        * Like #testSymlinkNotModifiedThoughNormalized but there is no
+        * normalization being done.
+        *
+        * @throws Exception
+        */
+       @Test
+       public void testSymlinkModifiedNotNormalized() throws Exception {
+               DirCache dc = db.lockDirCache();
+               DirCacheEditor dce = dc.editor();
+               final String NORMALIZED = "target";
+               final byte[] NORMALIZED_BYTES = Constants.encode(NORMALIZED);
+               ObjectInserter oi = db.newObjectInserter();
+               final ObjectId linkid = oi.insert(Constants.OBJ_BLOB, NORMALIZED_BYTES,
+                               0, NORMALIZED_BYTES.length);
+               oi.release();
+               dce.add(new DirCacheEditor.PathEdit("link") {
+                       @Override
+                       public void apply(DirCacheEntry ent) {
+                               ent.setFileMode(FileMode.SYMLINK);
+                               ent.setObjectId(linkid);
+                               ent.setLength(NORMALIZED_BYTES.length);
+                       }
+               });
+               assertTrue(dce.commit());
+               new Git(db).commit().setMessage("Adding link").call();
+               new Git(db).reset().setMode(ResetType.HARD).call();
+               DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
+               FileTreeIterator fti = new FileTreeIterator(db);
+               fti.next(1); // Skips .git
+
+               // self-check
+               assertEquals("link", fti.getEntryPathString());
+               assertEquals("link", dci.getEntryPathString());
+
+               // test
+               assertFalse(fti.isModified(dci.getDirCacheEntry(), true));
+       }
+
+       /**
+        * Like #testSymlinkNotModifiedThoughNormalized but here the link is
+        * modified.
+        *
+        * @throws Exception
+        */
+       @Test
+       public void testSymlinkActuallyModified() throws Exception {
+               final String NORMALIZED = "target";
+               final byte[] NORMALIZED_BYTES = Constants.encode(NORMALIZED);
+               ObjectInserter oi = db.newObjectInserter();
+               final ObjectId linkid = oi.insert(Constants.OBJ_BLOB, NORMALIZED_BYTES,
+                               0, NORMALIZED_BYTES.length);
+               oi.release();
+               DirCache dc = db.lockDirCache();
+               DirCacheEditor dce = dc.editor();
+               dce.add(new DirCacheEditor.PathEdit("link") {
+                       @Override
+                       public void apply(DirCacheEntry ent) {
+                               ent.setFileMode(FileMode.SYMLINK);
+                               ent.setObjectId(linkid);
+                               ent.setLength(NORMALIZED_BYTES.length);
+                       }
+               });
+               assertTrue(dce.commit());
+               new Git(db).commit().setMessage("Adding link").call();
+               new Git(db).reset().setMode(ResetType.HARD).call();
+
+               FileUtils.delete(new File(trash, "link"), FileUtils.NONE);
+               FS.DETECTED.createSymLink(new File(trash, "link"), "newtarget");
+               DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
+               FileTreeIterator fti = new FileTreeIterator(db);
+               fti.next(1); // Skips .git
+
+               // self-check
+               assertEquals("link", fti.getEntryPathString());
+               assertEquals("link", dci.getEntryPathString());
+
+               // test
+               assertTrue(fti.isModified(dci.getDirCacheEntry(), true));
+       }
+}
diff --git a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/TreeWalkJava7Test.java b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/TreeWalkJava7Test.java
new file mode 100644 (file)
index 0000000..bb1f2a6
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012-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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.util.FS;
+import org.junit.Test;
+
+public class TreeWalkJava7Test extends RepositoryTestCase {
+       @Test
+       public void testSymlinkToDirNotRecursingViaSymlink() throws Exception {
+               FS fs = db.getFS();
+               assertTrue(fs.supportsSymlinks());
+               writeTrashFile("target/data", "targetdata");
+               fs.createSymLink(new File(trash, "link"), "target");
+               TreeWalk tw = new TreeWalk(db);
+               tw.setRecursive(true);
+               tw.addTree(new FileTreeIterator(db));
+               assertTrue(tw.next());
+               assertEquals("link", tw.getPathString());
+               assertTrue(tw.next());
+               assertEquals("target/data", tw.getPathString());
+               assertFalse(tw.next());
+       }
+}