aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java124
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java7
2 files changed, 126 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
index 82d509f6f3..4bfb128cbc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
@@ -72,12 +72,14 @@ import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.Sets;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
@@ -86,6 +88,7 @@ import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
public class CheckoutCommandTest extends RepositoryTestCase {
@@ -556,4 +559,125 @@ public class CheckoutCommandTest extends RepositoryTestCase {
}
org.junit.Assume.assumeTrue(foundUnsmudged);
}
+
+ @Test
+ public void testSmudgeFilter_modifyExisting() throws IOException, GitAPIException {
+ File script = writeTempFile("sed s/o/e/g");
+ StoredConfig config = git.getRepository().getConfig();
+ config.setString("filter", "tstFilter", "smudge",
+ "sh " + slashify(script.getPath()));
+ config.save();
+
+ writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
+ git.add().addFilepattern(".gitattributes").call();
+ git.commit().setMessage("add filter").call();
+
+ writeTrashFile("src/a.tmp", "x");
+ // Caution: we need a trailing '\n' since sed on mac always appends
+ // linefeeds if missing
+ writeTrashFile("src/a.txt", "x\n");
+ git.add().addFilepattern("src/a.tmp").addFilepattern("src/a.txt")
+ .call();
+ RevCommit content1 = git.commit().setMessage("add content").call();
+
+ writeTrashFile("src/a.tmp", "foo");
+ writeTrashFile("src/a.txt", "foo\n");
+ git.add().addFilepattern("src/a.tmp").addFilepattern("src/a.txt")
+ .call();
+ RevCommit content2 = git.commit().setMessage("changed content").call();
+
+ git.checkout().setName(content1.getName()).call();
+ git.checkout().setName(content2.getName()).call();
+
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][src/a.tmp, mode:100644, content:foo][src/a.txt, mode:100644, content:foo\n]",
+ indexState(CONTENT));
+ assertEquals(Sets.of("src/a.txt"), git.status().call().getModified());
+ assertEquals("foo", read("src/a.tmp"));
+ assertEquals("fee\n", read("src/a.txt"));
+ }
+
+ @Test
+ public void testSmudgeFilter_createNew()
+ throws IOException, GitAPIException {
+ File script = writeTempFile("sed s/o/e/g");
+ StoredConfig config = git.getRepository().getConfig();
+ config.setString("filter", "tstFilter", "smudge",
+ "sh " + slashify(script.getPath()));
+ config.save();
+
+ writeTrashFile("foo", "foo");
+ git.add().addFilepattern("foo").call();
+ RevCommit initial = git.commit().setMessage("initial").call();
+
+ writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
+ git.add().addFilepattern(".gitattributes").call();
+ git.commit().setMessage("add filter").call();
+
+ writeTrashFile("src/a.tmp", "foo");
+ // Caution: we need a trailing '\n' since sed on mac always appends
+ // linefeeds if missing
+ writeTrashFile("src/a.txt", "foo\n");
+ git.add().addFilepattern("src/a.tmp").addFilepattern("src/a.txt")
+ .call();
+ RevCommit content = git.commit().setMessage("added content").call();
+
+ git.checkout().setName(initial.getName()).call();
+ git.checkout().setName(content.getName()).call();
+
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][foo, mode:100644, content:foo][src/a.tmp, mode:100644, content:foo][src/a.txt, mode:100644, content:foo\n]",
+ indexState(CONTENT));
+ assertEquals("foo", read("src/a.tmp"));
+ assertEquals("fee\n", read("src/a.txt"));
+ }
+
+ @Test
+ @Ignore
+ public void testSmudgeAndClean() throws IOException, GitAPIException {
+ // @TODO: fix this test
+ File clean_filter = writeTempFile("sed s/V1/@version/g -");
+ File smudge_filter = writeTempFile("sed s/@version/V1/g -");
+
+ Git git = new Git(db);
+ StoredConfig config = git.getRepository().getConfig();
+ config.setString("filter", "tstFilter", "smudge",
+ "sh " + slashify(smudge_filter.getPath()));
+ config.setString("filter", "tstFilter", "clean",
+ "sh " + slashify(clean_filter.getPath()));
+ config.save();
+ writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
+ git.add().addFilepattern(".gitattributes").call();
+ git.commit().setMessage("add attributes").call();
+
+ writeTrashFile("filterTest.txt", "hello world, V1");
+ git.add().addFilepattern("filterTest.txt").call();
+ git.commit().setMessage("add filterText.txt").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
+ indexState(CONTENT));
+
+ git.checkout().setCreateBranch(true).setName("test2").call();
+ writeTrashFile("filterTest.txt", "bon giorno world, V1");
+ git.add().addFilepattern("filterTest.txt").call();
+ git.commit().setMessage("modified filterText.txt").call();
+
+ assertTrue(git.status().call().isClean());
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:bon giorno world, @version]",
+ indexState(CONTENT));
+
+ git.checkout().setName("refs/heads/test").call();
+ assertTrue(git.status().call().isClean());
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
+ indexState(CONTENT));
+ assertEquals("hello world, V1", read("filterTest.txt"));
+ }
+
+ private File writeTempFile(String body) throws IOException {
+ File f = File.createTempFile("AddCommandTest_", "");
+ JGitTestUtil.write(f, body);
+ return f;
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
index 51a6b5a8f5..d768e0fa0b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
@@ -113,7 +113,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
return dco.getRemoved();
}
- private Map<String, ObjectId> getUpdated() {
+ private Map<String, String> getUpdated() {
return dco.getUpdated();
}
@@ -268,8 +268,6 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test
public void testRules1thru3_NoIndexEntry() throws IOException {
ObjectId head = buildTree(mk("foo"));
- TreeWalk tw = TreeWalk.forPath(db, "foo", head);
- ObjectId objectId = tw.getObjectId(0);
ObjectId merge = db.newObjectInserter().insert(Constants.OBJ_TREE,
new byte[0]);
@@ -279,10 +277,9 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
prescanTwoTrees(merge, head);
- assertEquals(objectId, getUpdated().get("foo"));
+ assertTrue(getUpdated().containsKey("foo"));
merge = buildTree(mkmap("foo", "a"));
- tw = TreeWalk.forPath(db, "foo", merge);
prescanTwoTrees(head, merge);