aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.java7.test
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2014-02-05 21:24:41 +0100
committerRobin Rosenberg <robin.rosenberg@dewire.com>2014-02-12 23:29:41 +0100
commit1e6407162c5d061ba8525a4aa0f3d969f24bbb05 (patch)
tree5d6fb51cffef724a20ed960f8d0101517ffac0be /org.eclipse.jgit.java7.test
parentd86c88308231b79a4b569032546c4043570c3921 (diff)
downloadjgit-1e6407162c5d061ba8525a4aa0f3d969f24bbb05.tar.gz
jgit-1e6407162c5d061ba8525a4aa0f3d969f24bbb05.zip
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
Diffstat (limited to 'org.eclipse.jgit.java7.test')
-rw-r--r--org.eclipse.jgit.java7.test/src/org/eclipse/jgit/symlinks/SymlinksTest.java74
1 files changed, 74 insertions, 0 deletions
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 366ab9e904..49627db352 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);
+ }
}