diff options
Diffstat (limited to 'org.eclipse.jgit.pgm.test')
-rw-r--r-- | org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java | 13 | ||||
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java | 37 |
2 files changed, 50 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java index 559a6d5d40..4bdfa4d5bc 100644 --- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java +++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java @@ -46,6 +46,7 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -76,6 +77,18 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase { return result.toArray(new String[0]); } + /** + * @param link + * the path of the symbolic link to create + * @param target + * the target of the symbolic link + * @return the path to the symbolic link + * @throws Exception + */ + protected Path writeLink(String link, String target) throws Exception { + return JGitTestUtil.writeLink(db, link, target); + } + protected File writeTrashFile(final String name, final String data) throws IOException { return JGitTestUtil.writeTrashFile(db, name, data); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java index 939a9f6fdd..167d8ab512 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java @@ -44,9 +44,14 @@ package org.eclipse.jgit.pgm; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; import java.util.List; import org.eclipse.jgit.api.Git; @@ -59,7 +64,9 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry; import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; +import org.junit.Assume; import org.junit.Test; public class CheckoutTest extends CLIRepositoryTestCase { @@ -578,4 +585,34 @@ public class CheckoutTest extends CLIRepositoryTestCase { execute("git branch")); assertEquals("Hello world b", read(b)); } + + @Test + public void testCheckouSingleFile() throws Exception { + try (Git git = new Git(db)) { + File a = writeTrashFile("a", "file a"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("commit file a").call(); + writeTrashFile("a", "b"); + assertEquals("b", read(a)); + assertEquals("[]", Arrays.toString(execute("git checkout -- a"))); + assertEquals("file a", read(a)); + } + } + + @Test + public void testCheckoutLink() throws Exception { + Assume.assumeTrue(FS.DETECTED.supportsSymlinks()); + try (Git git = new Git(db)) { + Path path = writeLink("a", "link_a"); + assertTrue(Files.isSymbolicLink(path)); + git.add().addFilepattern(".").call(); + git.commit().setMessage("commit link a").call(); + deleteTrashFile("a"); + writeTrashFile("a", "Hello world a"); + assertFalse(Files.isSymbolicLink(path)); + assertEquals("[]", Arrays.toString(execute("git checkout -- a"))); + assertEquals("link_a", FileUtils.readSymLink(path.toFile())); + assertTrue(Files.isSymbolicLink(path)); + } + } } |