Browse Source

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
stable-3.4
Robin Rosenberg 11 years ago
parent
commit
1e6407162c
  1. 74
      org.eclipse.jgit.java7.test/src/org/eclipse/jgit/symlinks/SymlinksTest.java

74
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);
}
}

Loading…
Cancel
Save