summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2016-05-03 14:59:57 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2016-09-20 10:02:20 +0200
commitd97248467a95d26934ddeb8617c3bbf3f673f69d (patch)
tree1d14b4dccc659bfd1a8e2245e790da99c4c3a9b2 /org.eclipse.jgit.test/tst
parentb5bec73715e28cac6a08c98ec1499f02e6095cfc (diff)
downloadjgit-d97248467a95d26934ddeb8617c3bbf3f673f69d.tar.gz
jgit-d97248467a95d26934ddeb8617c3bbf3f673f69d.zip
Add support for built-in smudge filters
JGit supports smudge filters defined in repository configuration. The filters are implemented as external programs filtering content by accepting the original content (as seen in git's object database) on stdin and which emit the filtered content on stdout. This content is then written to the file in the working tree. To run such a filter JGit has to start an external process and pump data into/from this process. This commit adds support for built-in smudge filters which are implemented in Java and which are executed by jgit's main thread. When a filter is defined in the configuration as "jgit://builtin/<filterDriverName>/smudge" then JGit will lookup in a static map whether a builtin filter is registered under this name. If found such a filter is called to do the filtering. The functionality in this commit requires that a program using JGit explicitly calls the JGit API to register built-in implementations for specific smudge filters. In follow-up commits configuration parameters will be added which trigger such registrations. Change-Id: Ia743aa0dbed795e71e5792f35ae55660e0eb3c24
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java
index 5fb894e911..0d31811257 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java
@@ -154,4 +154,98 @@ public class FilterCommandsTest extends RepositoryTestCase {
config.setString("filter", "test", "clean", null);
config.save();
}
+
+ @Test
+ public void testBuiltinSmudgeFilter() throws IOException, GitAPIException {
+ String builtinCommandName = "jgit://builtin/test/smudge";
+ FilterCommandRegistry.register(builtinCommandName,
+ new TestCommandFactory('s'));
+ StoredConfig config = git.getRepository().getConfig();
+ config.setString("filter", "test", "smudge", builtinCommandName);
+ config.save();
+
+ writeTrashFile(".gitattributes", "*.txt filter=test");
+ git.add().addFilepattern(".gitattributes").call();
+ git.commit().setMessage("add filter").call();
+
+ writeTrashFile("Test.txt", "Hello again");
+ git.add().addFilepattern("Test.txt").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=test][Test.txt, mode:100644, content:Hello again]",
+ indexState(CONTENT));
+ assertEquals("Hello again", read("Test.txt"));
+ deleteTrashFile("Test.txt");
+ git.checkout().addPath("Test.txt").call();
+ assertEquals("sHseslslsos sasgsasisn", read("Test.txt"));
+
+ writeTrashFile("Test.bin", "Hello again");
+ git.add().addFilepattern("Test.bin").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=test][Test.bin, mode:100644, content:Hello again][Test.txt, mode:100644, content:Hello again]",
+ indexState(CONTENT));
+ deleteTrashFile("Test.bin");
+ git.checkout().addPath("Test.bin").call();
+ assertEquals("Hello again", read("Test.bin"));
+
+ config.setString("filter", "test", "clean", null);
+ config.save();
+
+ git.add().addFilepattern("Test.txt").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=test][Test.bin, mode:100644, content:Hello again][Test.txt, mode:100644, content:sHseslslsos sasgsasisn]",
+ indexState(CONTENT));
+
+ config.setString("filter", "test", "clean", null);
+ config.save();
+ }
+
+ @Test
+ public void testBuiltinCleanAndSmudgeFilter() throws IOException, GitAPIException {
+ String builtinCommandPrefix = "jgit://builtin/test/";
+ FilterCommandRegistry.register(builtinCommandPrefix + "smudge",
+ new TestCommandFactory('s'));
+ FilterCommandRegistry.register(builtinCommandPrefix + "clean",
+ new TestCommandFactory('c'));
+ StoredConfig config = git.getRepository().getConfig();
+ config.setString("filter", "test", "smudge", builtinCommandPrefix+"smudge");
+ config.setString("filter", "test", "clean",
+ builtinCommandPrefix + "clean");
+ config.save();
+
+ writeTrashFile(".gitattributes", "*.txt filter=test");
+ git.add().addFilepattern(".gitattributes").call();
+ git.commit().setMessage("add filter").call();
+
+ writeTrashFile("Test.txt", "Hello again");
+ git.add().addFilepattern("Test.txt").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=test][Test.txt, mode:100644, content:cHceclclcoc cacgcacicn]",
+ indexState(CONTENT));
+ assertEquals("Hello again", read("Test.txt"));
+ deleteTrashFile("Test.txt");
+ git.checkout().addPath("Test.txt").call();
+ assertEquals("scsHscsescslscslscsoscs scsascsgscsascsiscsn",
+ read("Test.txt"));
+
+ writeTrashFile("Test.bin", "Hello again");
+ git.add().addFilepattern("Test.bin").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=test][Test.bin, mode:100644, content:Hello again][Test.txt, mode:100644, content:cHceclclcoc cacgcacicn]",
+ indexState(CONTENT));
+ deleteTrashFile("Test.bin");
+ git.checkout().addPath("Test.bin").call();
+ assertEquals("Hello again", read("Test.bin"));
+
+ config.setString("filter", "test", "clean", null);
+ config.save();
+
+ git.add().addFilepattern("Test.txt").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=test][Test.bin, mode:100644, content:Hello again][Test.txt, mode:100644, content:scsHscsescslscslscsoscs scsascsgscsascsiscsn]",
+ indexState(CONTENT));
+
+ config.setString("filter", "test", "clean", null);
+ config.save();
+ }
+
}