|
|
@@ -632,6 +632,113 @@ public class CheckoutCommandTest extends RepositoryTestCase { |
|
|
|
assertEquals("fee\n", read("src/a.txt")); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSmudgeFilter_deleteFileAndRestoreFromCommit() |
|
|
|
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(); |
|
|
|
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(); |
|
|
|
|
|
|
|
deleteTrashFile("src/a.txt"); |
|
|
|
git.checkout().setStartPoint(content.getName()).addPath("src/a.txt") |
|
|
|
.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 |
|
|
|
public void testSmudgeFilter_deleteFileAndRestoreFromIndex() |
|
|
|
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(); |
|
|
|
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(); |
|
|
|
git.commit().setMessage("added content").call(); |
|
|
|
|
|
|
|
deleteTrashFile("src/a.txt"); |
|
|
|
git.checkout().addPath("src/a.txt").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 |
|
|
|
public void testSmudgeFilter_deleteFileAndCreateBranchAndRestoreFromCommit() |
|
|
|
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(); |
|
|
|
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(); |
|
|
|
|
|
|
|
deleteTrashFile("src/a.txt"); |
|
|
|
git.checkout().setName("newBranch").setCreateBranch(true) |
|
|
|
.setStartPoint(content).addPath("src/a.txt").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 { |