Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java337
1 files changed, 173 insertions, 164 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java
index 3ddc3ded8c..274fa539cb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java
@@ -75,26 +75,27 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestFileThenSymlink() throws Exception {
- Git git = new Git(db);
- writeTrashFile("a", "Hello world a");
- writeTrashFile("b", "Hello world b");
- git.add().addFilepattern(".").call();
- git.commit().setMessage("add files a & b").call();
- Ref branch_1 = git.branchCreate().setName("branch_1").call();
- git.rm().addFilepattern("a").call();
- FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
- git.add().addFilepattern("a").call();
- git.commit().setMessage("add symlink a").call();
+ try (Git git = new Git(db)) {
+ writeTrashFile("a", "Hello world a");
+ writeTrashFile("b", "Hello world b");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("add files a & b").call();
+ Ref branch_1 = git.branchCreate().setName("branch_1").call();
+ git.rm().addFilepattern("a").call();
+ FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("add symlink a").call();
- FileEntry entry = new FileTreeIterator.FileEntry(new File(
- db.getWorkTree(), "a"), db.getFS());
- assertEquals(FileMode.SYMLINK, entry.getMode());
+ FileEntry entry = new FileTreeIterator.FileEntry(new File(
+ db.getWorkTree(), "a"), db.getFS());
+ assertEquals(FileMode.SYMLINK, entry.getMode());
- git.checkout().setName(branch_1.getName()).call();
+ git.checkout().setName(branch_1.getName()).call();
- entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
- db.getFS());
- assertEquals(FileMode.REGULAR_FILE, entry.getMode());
+ entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
+ db.getFS());
+ assertEquals(FileMode.REGULAR_FILE, entry.getMode());
+ }
}
/**
@@ -108,26 +109,27 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestSymlinkThenFile() throws Exception {
- Git git = new Git(db);
- writeTrashFile("b", "Hello world b");
- FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
- git.add().addFilepattern(".").call();
- git.commit().setMessage("add file b & symlink a").call();
- Ref branch_1 = git.branchCreate().setName("branch_1").call();
- git.rm().addFilepattern("a").call();
- writeTrashFile("a", "Hello world a");
- git.add().addFilepattern("a").call();
- git.commit().setMessage("add file a").call();
+ try (Git git = new Git(db)) {
+ writeTrashFile("b", "Hello world b");
+ FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("add file b & symlink a").call();
+ Ref branch_1 = git.branchCreate().setName("branch_1").call();
+ git.rm().addFilepattern("a").call();
+ writeTrashFile("a", "Hello world a");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("add file a").call();
- FileEntry entry = new FileTreeIterator.FileEntry(new File(
- db.getWorkTree(), "a"), db.getFS());
- assertEquals(FileMode.REGULAR_FILE, entry.getMode());
+ FileEntry entry = new FileTreeIterator.FileEntry(new File(
+ db.getWorkTree(), "a"), db.getFS());
+ assertEquals(FileMode.REGULAR_FILE, entry.getMode());
- git.checkout().setName(branch_1.getName()).call();
+ git.checkout().setName(branch_1.getName()).call();
- entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
- db.getFS());
- assertEquals(FileMode.SYMLINK, entry.getMode());
+ entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
+ db.getFS());
+ assertEquals(FileMode.SYMLINK, entry.getMode());
+ }
}
/**
@@ -141,27 +143,28 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestFolderThenSymlink() throws Exception {
- Git git = new Git(db);
- FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
- writeTrashFile("a/b", "Hello world b");
- writeTrashFile("c", "Hello world c");
- git.add().addFilepattern(".").call();
- git.commit().setMessage("add folder a").call();
- Ref branch_1 = git.branchCreate().setName("branch_1").call();
- git.rm().addFilepattern("a").call();
- FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "c");
- git.add().addFilepattern("a").call();
- git.commit().setMessage("add symlink a").call();
+ try (Git git = new Git(db)) {
+ FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
+ writeTrashFile("a/b", "Hello world b");
+ writeTrashFile("c", "Hello world c");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("add folder a").call();
+ Ref branch_1 = git.branchCreate().setName("branch_1").call();
+ git.rm().addFilepattern("a").call();
+ FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "c");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("add symlink a").call();
- FileEntry entry = new FileTreeIterator.FileEntry(new File(
- db.getWorkTree(), "a"), db.getFS());
- assertEquals(FileMode.SYMLINK, entry.getMode());
+ FileEntry entry = new FileTreeIterator.FileEntry(new File(
+ db.getWorkTree(), "a"), db.getFS());
+ assertEquals(FileMode.SYMLINK, entry.getMode());
- git.checkout().setName(branch_1.getName()).call();
+ git.checkout().setName(branch_1.getName()).call();
- entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
- db.getFS());
- assertEquals(FileMode.TREE, entry.getMode());
+ entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
+ db.getFS());
+ assertEquals(FileMode.TREE, entry.getMode());
+ }
}
/**
@@ -175,27 +178,28 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestSymlinkThenFolder() throws Exception {
- Git git = new Git(db);
- writeTrashFile("c", "Hello world c");
- FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "c");
- git.add().addFilepattern(".").call();
- git.commit().setMessage("add symlink a").call();
- Ref branch_1 = git.branchCreate().setName("branch_1").call();
- git.rm().addFilepattern("a").call();
- FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
- writeTrashFile("a/b", "Hello world b");
- git.add().addFilepattern("a").call();
- git.commit().setMessage("add folder a").call();
+ try (Git git = new Git(db)) {
+ writeTrashFile("c", "Hello world c");
+ FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "c");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("add symlink a").call();
+ Ref branch_1 = git.branchCreate().setName("branch_1").call();
+ git.rm().addFilepattern("a").call();
+ FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
+ writeTrashFile("a/b", "Hello world b");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("add folder a").call();
- FileEntry entry = new FileTreeIterator.FileEntry(new File(
- db.getWorkTree(), "a"), db.getFS());
- assertEquals(FileMode.TREE, entry.getMode());
+ FileEntry entry = new FileTreeIterator.FileEntry(new File(
+ db.getWorkTree(), "a"), db.getFS());
+ assertEquals(FileMode.TREE, entry.getMode());
- git.checkout().setName(branch_1.getName()).call();
+ git.checkout().setName(branch_1.getName()).call();
- entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
- db.getFS());
- assertEquals(FileMode.SYMLINK, entry.getMode());
+ entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
+ db.getFS());
+ assertEquals(FileMode.SYMLINK, entry.getMode());
+ }
}
/**
@@ -209,24 +213,25 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestMissingThenSymlink() throws Exception {
- Git git = new Git(db);
- writeTrashFile("b", "Hello world b");
- git.add().addFilepattern(".").call();
- RevCommit commit1 = git.commit().setMessage("add file b").call();
- Ref branch_1 = git.branchCreate().setName("branch_1").call();
- FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
- git.add().addFilepattern("a").call();
- RevCommit commit2 = git.commit().setMessage("add symlink a").call();
+ try (Git git = new Git(db);
+ TreeWalk tw = new TreeWalk(db);) {
+ writeTrashFile("b", "Hello world b");
+ git.add().addFilepattern(".").call();
+ RevCommit commit1 = git.commit().setMessage("add file b").call();
+ Ref branch_1 = git.branchCreate().setName("branch_1").call();
+ FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
+ git.add().addFilepattern("a").call();
+ RevCommit commit2 = git.commit().setMessage("add symlink a").call();
- git.checkout().setName(branch_1.getName()).call();
+ git.checkout().setName(branch_1.getName()).call();
- TreeWalk tw = new TreeWalk(db);
- tw.addTree(commit1.getTree());
- tw.addTree(commit2.getTree());
- List<DiffEntry> scan = DiffEntry.scan(tw);
- assertEquals(1, scan.size());
- assertEquals(FileMode.SYMLINK, scan.get(0).getNewMode());
- assertEquals(FileMode.MISSING, scan.get(0).getOldMode());
+ tw.addTree(commit1.getTree());
+ tw.addTree(commit2.getTree());
+ List<DiffEntry> scan = DiffEntry.scan(tw);
+ assertEquals(1, scan.size());
+ assertEquals(FileMode.SYMLINK, scan.get(0).getNewMode());
+ assertEquals(FileMode.MISSING, scan.get(0).getOldMode());
+ }
}
/**
@@ -240,97 +245,101 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestSymlinkThenMissing() throws Exception {
- Git git = new Git(db);
- writeTrashFile("b", "Hello world b");
- FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
- git.add().addFilepattern(".").call();
- RevCommit commit1 = git.commit().setMessage("add file b & symlink a")
- .call();
- Ref branch_1 = git.branchCreate().setName("branch_1").call();
- git.rm().addFilepattern("a").call();
- RevCommit commit2 = git.commit().setMessage("delete symlink a").call();
+ try (Git git = new Git(db);
+ TreeWalk tw = new TreeWalk(db);) {
+ writeTrashFile("b", "Hello world b");
+ FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
+ git.add().addFilepattern(".").call();
+ RevCommit commit1 = git.commit().setMessage("add file b & symlink a")
+ .call();
+ Ref branch_1 = git.branchCreate().setName("branch_1").call();
+ git.rm().addFilepattern("a").call();
+ RevCommit commit2 = git.commit().setMessage("delete symlink a").call();
- git.checkout().setName(branch_1.getName()).call();
+ git.checkout().setName(branch_1.getName()).call();
- TreeWalk tw = new TreeWalk(db);
- tw.addTree(commit1.getTree());
- tw.addTree(commit2.getTree());
- List<DiffEntry> scan = DiffEntry.scan(tw);
- assertEquals(1, scan.size());
- assertEquals(FileMode.MISSING, scan.get(0).getNewMode());
- assertEquals(FileMode.SYMLINK, scan.get(0).getOldMode());
+ tw.addTree(commit1.getTree());
+ tw.addTree(commit2.getTree());
+ List<DiffEntry> scan = DiffEntry.scan(tw);
+ assertEquals(1, scan.size());
+ 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);
+ try (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);
+ try (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);
+ try (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);
+ }
}
}

Back to the top