diff options
author | Laurent Goubet <laurent.goubet@obeo.fr> | 2014-10-31 14:58:07 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2015-02-02 10:22:53 +0100 |
commit | 6aed51e3cea6f7114b42bcbc4f66abb48e6ae490 (patch) | |
tree | 05521323d215b1a5eefc2541499788925f152990 /org.eclipse.jgit.test | |
parent | f5936405a3a66b821f716e551de6ee4c1c33ca0b (diff) | |
download | jgit-6aed51e3cea6f7114b42bcbc4f66abb48e6ae490.tar.gz jgit-6aed51e3cea6f7114b42bcbc4f66abb48e6ae490.zip |
Introduce hook support into the FS implementations
This introduces the background plumbing necessary to run git hooks from
JGit. This implementation will be OS-dependent as it aims to be
compatible with existing hooks, mostly written in Shell. It is
compatible with unix systems and windows as long as an Unix emulator
such as Cygwin is in its PATH.
Change-Id: I1f82a5205138fd8032614dd5b52aef14e02238ed
Signed-off-by: Laurent Goubet <laurent.goubet@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java index 7b1627854f..d4be25c0cd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java @@ -50,6 +50,7 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; +import java.util.regex.Matcher; import org.eclipse.jgit.junit.JGitTestUtil; import org.junit.After; @@ -434,4 +435,82 @@ public class FileUtilTest { String target = fs.readSymLink(new File(trash, "x")); assertEquals("y", target); } + + @Test + public void testRelativize_doc() { + // This is the javadoc example + String base = toOSPathString("c:\\Users\\jdoe\\eclipse\\git\\project"); + String other = toOSPathString("c:\\Users\\jdoe\\eclipse\\git\\another_project\\pom.xml"); + String expected = toOSPathString("..\\another_project\\pom.xml"); + + String actual = FileUtils.relativize(base, other); + assertEquals(expected, actual); + } + + @Test + public void testRelativize_mixedCase() { + SystemReader systemReader = SystemReader.getInstance(); + String oldOSName = null; + String base = toOSPathString("C:\\git\\jgit"); + String other = toOSPathString("C:\\Git\\test\\d\\f.txt"); + String expectedWindows = toOSPathString("..\\test\\d\\f.txt"); + String expectedUnix = toOSPathString("..\\..\\Git\\test\\d\\f.txt"); + + if (!systemReader.isWindows()) { + String actual = FileUtils.relativize(base, other); + assertEquals(expectedUnix, actual); + + // FS_POSIX#isCaseSensitive will return "false" for mac OS X. + // Use this to test both behaviors. + oldOSName = System.getProperty("os.name"); + try { + System.setProperty("os.name", "Mac OS X"); + + actual = FileUtils.relativize(base, other); + assertEquals(expectedWindows, actual); + } finally { + if (oldOSName != null) + System.setProperty("os.name", oldOSName); + } + } else { + String actual = FileUtils.relativize(base, other); + assertEquals(expectedWindows, actual); + } + } + + @Test + public void testRelativize_scheme() { + String base = toOSPathString("file:/home/eclipse/runtime-New_configuration/project_1/file.java"); + String other = toOSPathString("file:/home/eclipse/runtime-New_configuration/project"); + // 'file.java' is treated as a folder + String expected = toOSPathString("../../project"); + + String actual = FileUtils.relativize(base, other); + assertEquals(expected, actual); + } + + @Test + public void testRelativize_equalPaths() { + String base = toOSPathString("file:/home/eclipse/runtime-New_configuration/project_1"); + String other = toOSPathString("file:/home/eclipse/runtime-New_configuration/project_1"); + String expected = ""; + + String actual = FileUtils.relativize(base, other); + assertEquals(expected, actual); + } + + @Test + public void testRelativize_whitespaces() { + String base = toOSPathString("/home/eclipse 3.4/runtime New_configuration/project_1"); + String other = toOSPathString("/home/eclipse 3.4/runtime New_configuration/project_1/file"); + String expected = "file"; + + String actual = FileUtils.relativize(base, other); + assertEquals(expected, actual); + } + + private String toOSPathString(String path) { + return path.replaceAll("/|\\\\", + Matcher.quoteReplacement(File.separator)); + } } |