]> source.dussan.org Git - jgit.git/commitdiff
Windows: Test that we can create a symlink before the target is created 85/21585/15
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 5 Feb 2014 20:24:41 +0000 (21:24 +0100)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 12 Feb 2014 22:29:41 +0000 (23:29 +0100)
According to Win32 API, you need to specificy whether a symlink
points to a file or directory. These tests suggests a symlink created
for a file, can actually point to a directory. We can also create the
link before the target exists, so at least in this respect Windows
symbolic links appears to work as POSIX links.

On POSIX systems these tests have no relevance.

Change-Id: Id3991a4fc4333087c6f569acf04f503b0a0f170d

org.eclipse.jgit.java7.test/src/org/eclipse/jgit/symlinks/SymlinksTest.java

index 366ab9e904e09b9e385d33cb170218c72cb380c6..49627db35233f8ca13778def033479ef933b7ded 100644 (file)
@@ -260,4 +260,78 @@ public class SymlinksTest extends RepositoryTestCase {
                assertEquals(FileMode.MISSING, scan.get(0).getNewMode());
                assertEquals(FileMode.SYMLINK, scan.get(0).getOldMode());
        }
+
+       @Test
+       public void createSymlinkAfterTarget() throws Exception {
+               Git git = new Git(db);
+               writeTrashFile("a", "start");
+               git.add().addFilepattern("a").call();
+               RevCommit base = git.commit().setMessage("init").call();
+               writeTrashFile("target", "someData");
+               FileUtils.createSymLink(new File(db.getWorkTree(), "link"), "target");
+               git.add().addFilepattern("target").addFilepattern("link").call();
+               git.commit().setMessage("add target").call();
+               assertEquals(4, db.getWorkTree().list().length); // self-check
+               git.checkout().setName(base.name()).call();
+               assertEquals(2, db.getWorkTree().list().length); // self-check
+               git.checkout().setName("master").call();
+               assertEquals(4, db.getWorkTree().list().length);
+               String data = read(new File(db.getWorkTree(), "target"));
+               assertEquals(8, new File(db.getWorkTree(), "target").length());
+               assertEquals("someData", data);
+               data = read(new File(db.getWorkTree(), "link"));
+               assertEquals("target",
+                               FileUtils.readSymLink(new File(db.getWorkTree(), "link")));
+               ;
+               assertEquals("someData", data);
+       }
+
+       @Test
+       public void createFileSymlinkBeforeTarget() throws Exception {
+               Git git = new Git(db);
+               writeTrashFile("a", "start");
+               git.add().addFilepattern("a").call();
+               RevCommit base = git.commit().setMessage("init").call();
+               writeTrashFile("target", "someData");
+               FileUtils.createSymLink(new File(db.getWorkTree(), "tlink"), "target");
+               git.add().addFilepattern("target").addFilepattern("tlink").call();
+               git.commit().setMessage("add target").call();
+               assertEquals(4, db.getWorkTree().list().length); // self-check
+               git.checkout().setName(base.name()).call();
+               assertEquals(2, db.getWorkTree().list().length); // self-check
+               git.checkout().setName("master").call();
+               assertEquals(4, db.getWorkTree().list().length);
+               String data = read(new File(db.getWorkTree(), "target"));
+               assertEquals(8, new File(db.getWorkTree(), "target").length());
+               assertEquals("someData", data);
+               data = read(new File(db.getWorkTree(), "tlink"));
+               assertEquals("target",
+                               FileUtils.readSymLink(new File(db.getWorkTree(), "tlink")));
+               assertEquals("someData", data);
+       }
+
+       @Test
+       public void createDirSymlinkBeforeTarget() throws Exception {
+               Git git = new Git(db);
+               writeTrashFile("a", "start");
+               git.add().addFilepattern("a").call();
+               RevCommit base = git.commit().setMessage("init").call();
+               FileUtils.createSymLink(new File(db.getWorkTree(), "link"), "target");
+               FileUtils.mkdir(new File(db.getWorkTree(), "target"));
+               writeTrashFile("target/file", "someData");
+               git.add().addFilepattern("target").addFilepattern("link").call();
+               git.commit().setMessage("add target").call();
+               assertEquals(4, db.getWorkTree().list().length); // self-check
+               git.checkout().setName(base.name()).call();
+               assertEquals(2, db.getWorkTree().list().length); // self-check
+               git.checkout().setName("master").call();
+               assertEquals(4, db.getWorkTree().list().length);
+               String data = read(new File(db.getWorkTree(), "target/file"));
+               assertEquals(8, new File(db.getWorkTree(), "target/file").length());
+               assertEquals("someData", data);
+               data = read(new File(db.getWorkTree(), "link/file"));
+               assertEquals("target",
+                               FileUtils.readSymLink(new File(db.getWorkTree(), "link")));
+               assertEquals("someData", data);
+       }
 }