1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.lib;
11
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.List;
15
16 import org.eclipse.jgit.api.Git;
17 import org.eclipse.jgit.junit.RepositoryTestCase;
18 import org.eclipse.jgit.revwalk.RevCommit;
19 import org.eclipse.jgit.storage.file.WindowCacheConfig;
20 import org.eclipse.jgit.storage.pack.PackConfig;
21 import org.junit.Test;
22
23 public class HugeCommitMessageTest extends RepositoryTestCase {
24
25 private static final int HUGE_SIZE = Math.max(15 * WindowCacheConfig.MB,
26 PackConfig.DEFAULT_BIG_FILE_THRESHOLD + WindowCacheConfig.MB);
27
28
29
30
31 @Test
32 public void testHugeCommitMessage() throws Exception {
33 try (Git git = new Git(db)) {
34 writeTrashFile("foo", "foo");
35 git.add().addFilepattern("foo").call();
36 WindowCacheConfig wc = new WindowCacheConfig();
37 wc.setStreamFileThreshold(HUGE_SIZE + WindowCacheConfig.MB);
38 wc.install();
39 RevCommit commit = git.commit()
40 .setMessage(insanelyHugeCommitMessage()).call();
41 Ref master = db.findRef("master");
42 List<Ref> actual = git.branchList().setContains(commit.getName())
43 .call();
44 assertTrue("Should be contained in branch master",
45 actual.contains(master));
46 }
47 }
48
49 private String insanelyHugeCommitMessage() {
50 final String oneLine = "012345678901234567890123456789012345678901234567890123456789\n";
51 StringBuilder b = new StringBuilder(HUGE_SIZE + oneLine.length());
52
53
54
55 b.append("An insanely huge commit message\n\n");
56 while (b.length() < HUGE_SIZE) {
57 b.append(oneLine);
58 }
59 return b.toString();
60 }
61
62 }