From 1e6407162c5d061ba8525a4aa0f3d969f24bbb05 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 5 Feb 2014 21:24:41 +0100 Subject: [PATCH] Windows: Test that we can create a symlink before the target is created 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 --- .../eclipse/jgit/symlinks/SymlinksTest.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/symlinks/SymlinksTest.java b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/symlinks/SymlinksTest.java index 366ab9e90..49627db35 100644 --- a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/symlinks/SymlinksTest.java +++ b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/symlinks/SymlinksTest.java @@ -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); + } }