Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java144
1 files changed, 143 insertions, 1 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 36f94fbd20..89d31c3e8f 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
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016, Christian Halstrick <christian.halstrick@sap.com> and others
+ * Copyright (C) 2016, 2022 Christian Halstrick <christian.halstrick@sap.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -10,12 +10,17 @@
package org.eclipse.jgit.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.attributes.FilterCommand;
import org.eclipse.jgit.attributes.FilterCommandFactory;
@@ -86,6 +91,14 @@ public class FilterCommandsTest extends RepositoryTestCase {
secondCommit = git.commit().setMessage("Second commit").call();
}
+ @Override
+ public void tearDown() throws Exception {
+ Set<String> existingFilters = new HashSet<>(
+ FilterCommandRegistry.getRegisteredFilterCommands());
+ existingFilters.forEach(FilterCommandRegistry::unregister);
+ super.tearDown();
+ }
+
@Test
public void testBuiltinCleanFilter()
throws IOException, GitAPIException {
@@ -217,4 +230,133 @@ public class FilterCommandsTest extends RepositoryTestCase {
config.save();
}
+ @Test
+ public void testBranchSwitch() throws Exception {
+ 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();
+ // We're on the test branch
+ File aFile = writeTrashFile("a.txt", "a");
+ writeTrashFile(".gitattributes", "a.txt filter=test");
+ File cFile = writeTrashFile("cc/c.txt", "C");
+ writeTrashFile("cc/.gitattributes", "c.txt filter=test");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("On test").call();
+ git.checkout().setName("master").call();
+ git.branchCreate().setName("other").call();
+ git.checkout().setName("other").call();
+ writeTrashFile("b.txt", "b");
+ writeTrashFile(".gitattributes", "b.txt filter=test");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("On other").call();
+ git.checkout().setName("test").call();
+ checkFile(aFile, "scsa");
+ checkFile(cFile, "scsC");
+ }
+
+ @Test
+ public void testCheckoutSingleFile() throws Exception {
+ 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();
+ // We're on the test branch
+ File aFile = writeTrashFile("a.txt", "a");
+ File attributes = writeTrashFile(".gitattributes", "a.txt filter=test");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("On test").call();
+ git.checkout().setName("master").call();
+ git.branchCreate().setName("other").call();
+ git.checkout().setName("other").call();
+ writeTrashFile("b.txt", "b");
+ writeTrashFile(".gitattributes", "b.txt filter=test");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("On other").call();
+ git.checkout().setName("master").call();
+ assertFalse(aFile.exists());
+ assertFalse(attributes.exists());
+ git.checkout().setStartPoint("test").addPath("a.txt").call();
+ checkFile(aFile, "scsa");
+ }
+
+ @Test
+ public void testCheckoutSingleFile2() throws Exception {
+ 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();
+ // We're on the test branch
+ File aFile = writeTrashFile("a.txt", "a");
+ File attributes = writeTrashFile(".gitattributes", "a.txt filter=test");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("On test").call();
+ git.checkout().setName("master").call();
+ git.branchCreate().setName("other").call();
+ git.checkout().setName("other").call();
+ writeTrashFile("b.txt", "b");
+ writeTrashFile(".gitattributes", "b.txt filter=test");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("On other").call();
+ git.checkout().setName("master").call();
+ assertFalse(aFile.exists());
+ assertFalse(attributes.exists());
+ writeTrashFile(".gitattributes", "");
+ git.checkout().setStartPoint("test").addPath("a.txt").call();
+ checkFile(aFile, "scsa");
+ }
+
+ @Test
+ public void testMerge() throws Exception {
+ 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();
+ // We're on the test branch. Set up two branches that are expected to
+ // merge cleanly.
+ File aFile = writeTrashFile("a.txt", "a");
+ writeTrashFile(".gitattributes", "a.txt filter=test");
+ git.add().addFilepattern(".").call();
+ RevCommit aCommit = git.commit().setMessage("On test").call();
+ git.checkout().setName("master").call();
+ assertFalse(aFile.exists());
+ git.branchCreate().setName("other").call();
+ git.checkout().setName("other").call();
+ writeTrashFile("b/b.txt", "b");
+ writeTrashFile("b/.gitattributes", "b.txt filter=test");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("On other").call();
+ MergeResult result = git.merge().include(aCommit).call();
+ assertEquals(MergeResult.MergeStatus.MERGED, result.getMergeStatus());
+ checkFile(aFile, "scsa");
+ }
+
}

Back to the top