|
43 | 43 | package org.eclipse.jgit.pgm;
|
44 | 44 |
|
45 | 45 | import static org.junit.Assert.assertEquals;
|
| 46 | +import static org.junit.Assert.assertArrayEquals; |
46 | 47 |
|
47 | 48 | import org.eclipse.jgit.api.Git;
|
48 | 49 | import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
|
51 | 52 | import org.junit.Test;
|
52 | 53 |
|
53 | 54 | public class MergeTest extends CLIRepositoryTestCase {
|
| 55 | + |
| 56 | + private Git git; |
| 57 | + |
54 | 58 | @Override
|
55 | 59 | @Before
|
56 | 60 | public void setUp() throws Exception {
|
57 | 61 | super.setUp();
|
58 |
| - new Git(db).commit().setMessage("initial commit").call(); |
| 62 | + git = new Git(db); |
| 63 | + git.commit().setMessage("initial commit").call(); |
59 | 64 | }
|
60 | 65 |
|
61 | 66 | @Test
|
62 | 67 | public void testMergeSelf() throws Exception {
|
63 | 68 | assertEquals("Already up-to-date.", execute("git merge master")[0]);
|
64 | 69 | }
|
65 | 70 |
|
| 71 | + @Test |
| 72 | + public void testSquashSelf() throws Exception { |
| 73 | + assertEquals(" (nothing to squash)Already up-to-date.", |
| 74 | + execute("git merge master --squash")[0]); |
| 75 | + } |
| 76 | + |
66 | 77 | @Test
|
67 | 78 | public void testFastForward() throws Exception {
|
68 |
| - new Git(db).commit().setMessage("initial commit").call(); |
69 |
| - new Git(db).branchCreate().setName("side").call(); |
| 79 | + git.branchCreate().setName("side").call(); |
70 | 80 | writeTrashFile("file", "master");
|
71 |
| - new Git(db).add().addFilepattern("file").call(); |
72 |
| - new Git(db).commit().setMessage("commit").call(); |
73 |
| - new Git(db).checkout().setName("side").call(); |
| 81 | + git.add().addFilepattern("file").call(); |
| 82 | + git.commit().setMessage("commit").call(); |
| 83 | + git.checkout().setName("side").call(); |
74 | 84 |
|
75 | 85 | assertEquals("Fast-forward", execute("git merge master")[0]);
|
76 | 86 | }
|
77 | 87 |
|
78 | 88 | @Test
|
79 | 89 | public void testMerge() throws Exception {
|
80 |
| - new Git(db).commit().setMessage("initial commit").call(); |
81 |
| - new Git(db).branchCreate().setName("side").call(); |
| 90 | + git.branchCreate().setName("side").call(); |
82 | 91 | writeTrashFile("master", "content");
|
83 |
| - new Git(db).add().addFilepattern("master").call(); |
84 |
| - new Git(db).commit().setMessage("master commit").call(); |
85 |
| - new Git(db).checkout().setName("side").call(); |
| 92 | + git.add().addFilepattern("master").call(); |
| 93 | + git.commit().setMessage("master commit").call(); |
| 94 | + git.checkout().setName("side").call(); |
86 | 95 | writeTrashFile("side", "content");
|
87 |
| - new Git(db).add().addFilepattern("side").call(); |
88 |
| - new Git(db).commit().setMessage("side commit").call(); |
| 96 | + git.add().addFilepattern("side").call(); |
| 97 | + git.commit().setMessage("side commit").call(); |
89 | 98 |
|
90 | 99 | assertEquals("Merge made by the '" + MergeStrategy.RESOLVE.getName()
|
91 | 100 | + "' strategy.", execute("git merge master")[0]);
|
92 | 101 | }
|
| 102 | + |
| 103 | + @Test |
| 104 | + public void testSquash() throws Exception { |
| 105 | + git.branchCreate().setName("side").call(); |
| 106 | + writeTrashFile("file1", "content1"); |
| 107 | + git.add().addFilepattern("file1").call(); |
| 108 | + git.commit().setMessage("file1 commit").call(); |
| 109 | + writeTrashFile("file2", "content2"); |
| 110 | + git.add().addFilepattern("file2").call(); |
| 111 | + git.commit().setMessage("file2 commit").call(); |
| 112 | + git.checkout().setName("side").call(); |
| 113 | + writeTrashFile("side", "content"); |
| 114 | + git.add().addFilepattern("side").call(); |
| 115 | + git.commit().setMessage("side commit").call(); |
| 116 | + |
| 117 | + assertArrayEquals( |
| 118 | + new String[] { "Squash commit -- not updating HEAD", |
| 119 | + "Automatic merge went well; stopped before committing as requested", |
| 120 | + "" }, |
| 121 | + execute("git merge master --squash")); |
| 122 | + } |
93 | 123 | }
|
0 commit comments