|
|
|
@ -50,6 +50,7 @@ import static org.junit.Assert.assertFalse;
|
|
|
|
|
import static org.junit.Assert.assertNull; |
|
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
import static org.junit.Assume.assumeTrue; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.util.Iterator; |
|
|
|
@ -96,11 +97,12 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeInItself() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
git.commit().setMessage("initial commit").call(); |
|
|
|
|
|
|
|
|
|
MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call(); |
|
|
|
|
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
// no reflog entry written by merge
|
|
|
|
|
assertEquals("commit (initial): initial commit", |
|
|
|
|
db |
|
|
|
@ -112,7 +114,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testAlreadyUpToDate() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
|
createBranch(first, "refs/heads/branch1"); |
|
|
|
|
|
|
|
|
@ -120,6 +122,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
MergeResult result = git.merge().include(db.exactRef("refs/heads/branch1")).call(); |
|
|
|
|
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); |
|
|
|
|
assertEquals(second, result.getNewHead()); |
|
|
|
|
} |
|
|
|
|
// no reflog entry written by merge
|
|
|
|
|
assertEquals("commit: second commit", db |
|
|
|
|
.getReflogReader(Constants.HEAD).getLastEntry().getComment()); |
|
|
|
@ -129,7 +132,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFastForward() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
|
createBranch(first, "refs/heads/branch1"); |
|
|
|
|
|
|
|
|
@ -141,6 +144,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); |
|
|
|
|
assertEquals(second, result.getNewHead()); |
|
|
|
|
} |
|
|
|
|
assertEquals("merge refs/heads/master: Fast-forward", |
|
|
|
|
db.getReflogReader(Constants.HEAD).getLastEntry().getComment()); |
|
|
|
|
assertEquals("merge refs/heads/master: Fast-forward", |
|
|
|
@ -149,7 +153,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFastForwardNoCommit() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
|
createBranch(first, "refs/heads/branch1"); |
|
|
|
|
|
|
|
|
@ -163,6 +167,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, |
|
|
|
|
result.getMergeStatus()); |
|
|
|
|
assertEquals(second, result.getNewHead()); |
|
|
|
|
} |
|
|
|
|
assertEquals("merge refs/heads/master: Fast-forward", db |
|
|
|
|
.getReflogReader(Constants.HEAD).getLastEntry().getComment()); |
|
|
|
|
assertEquals("merge refs/heads/master: Fast-forward", db |
|
|
|
@ -171,8 +176,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFastForwardWithFiles() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("file1", "file1"); |
|
|
|
|
git.add().addFilepattern("file1").call(); |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
@ -194,6 +198,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertTrue(new File(db.getWorkTree(), "file2").exists()); |
|
|
|
|
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); |
|
|
|
|
assertEquals(second, result.getNewHead()); |
|
|
|
|
} |
|
|
|
|
assertEquals("merge refs/heads/master: Fast-forward", |
|
|
|
|
db.getReflogReader(Constants.HEAD).getLastEntry().getComment()); |
|
|
|
|
assertEquals("merge refs/heads/master: Fast-forward", |
|
|
|
@ -202,8 +207,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMultipleHeads() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("file1", "file1"); |
|
|
|
|
git.add().addFilepattern("file1").call(); |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
@ -231,12 +235,12 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
// expected this exception
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Theory |
|
|
|
|
public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy) |
|
|
|
|
throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit first = git.commit().setMessage("first").call(); |
|
|
|
|
createBranch(first, "refs/heads/side"); |
|
|
|
|
|
|
|
|
@ -252,6 +256,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
MergeResult result = git.merge().setStrategy(mergeStrategy) |
|
|
|
|
.include(db.exactRef(R_HEADS + MASTER)).call(); |
|
|
|
|
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
assertEquals( |
|
|
|
|
"merge refs/heads/master: Merge made by " |
|
|
|
|
+ mergeStrategy.getName() + ".", |
|
|
|
@ -265,8 +270,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
@Theory |
|
|
|
|
public void testMergeSuccessAllStrategiesNoCommit( |
|
|
|
|
MergeStrategy mergeStrategy) throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit first = git.commit().setMessage("first").call(); |
|
|
|
|
createBranch(first, "refs/heads/side"); |
|
|
|
|
|
|
|
|
@ -286,11 +290,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), |
|
|
|
|
thirdCommit.getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testContentMerge() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
writeTrashFile("c/c/c", "1\nc\n3\n"); |
|
|
|
@ -331,11 +335,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeTag() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "a"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial").call(); |
|
|
|
@ -358,11 +362,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
MergeResult result = git.merge().include(tag).setStrategy(MergeStrategy.RESOLVE).call(); |
|
|
|
|
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeMessage() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial").call(); |
|
|
|
@ -387,13 +391,13 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n", |
|
|
|
|
db.readMergeCommitMsg()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeNonVersionedPaths() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
writeTrashFile("c/c/c", "1\nc\n3\n"); |
|
|
|
@ -440,11 +444,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMultipleCreations() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial").call(); |
|
|
|
@ -466,11 +470,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
.setStrategy(MergeStrategy.RESOLVE).call(); |
|
|
|
|
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMultipleCreationsSameContent() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial").call(); |
|
|
|
@ -501,11 +505,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
.getReflogReader(db.getBranch()) |
|
|
|
|
.getLastEntry().getComment()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSuccessfulContentMerge() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
writeTrashFile("c/c/c", "1\nc\n3\n"); |
|
|
|
@ -559,11 +563,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); |
|
|
|
|
// test index state
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSuccessfulContentMergeNoCommit() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
writeTrashFile("c/c/c", "1\nc\n3\n"); |
|
|
|
@ -609,12 +613,12 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertNull(result.getNewHead()); |
|
|
|
|
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSuccessfulContentMergeAndDirtyworkingTree() |
|
|
|
|
throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
writeTrashFile("d", "1\nd\n3\n"); |
|
|
|
@ -670,11 +674,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSingleDeletion() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
writeTrashFile("d", "1\nd\n3\n"); |
|
|
|
@ -725,11 +729,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
read(new File(db.getWorkTree(), "c/c/c"))); |
|
|
|
|
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMultipleDeletions() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial").call(); |
|
|
|
@ -754,11 +758,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
.setStrategy(MergeStrategy.RESOLVE).call(); |
|
|
|
|
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDeletionAndConflict() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
writeTrashFile("d", "1\nd\n3\n"); |
|
|
|
@ -798,11 +802,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
read(new File(db.getWorkTree(), "c/c/c"))); |
|
|
|
|
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDeletionOnMasterConflict() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").addFilepattern("b").call(); |
|
|
|
@ -830,11 +834,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals("1\na(side)\n3\n", read(new File(db.getWorkTree(), "a"))); |
|
|
|
|
assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDeletionOnSideConflict() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").addFilepattern("b").call(); |
|
|
|
@ -864,14 +868,14 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(1, result.getConflicts().size()); |
|
|
|
|
assertEquals(3, result.getConflicts().get("a")[0].length); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testModifiedAndRenamed() throws Exception { |
|
|
|
|
// this test is essentially the same as testDeletionOnSideConflict,
|
|
|
|
|
// however if once rename support is added this test should result in a
|
|
|
|
|
// successful merge instead of a conflict
|
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("x", "add x"); |
|
|
|
|
git.add().addFilepattern("x").call(); |
|
|
|
|
RevCommit initial = git.commit().setMessage("add x").call(); |
|
|
|
@ -903,11 +907,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(1, d2Merge.getConflicts().size()); |
|
|
|
|
assertEquals(3, d2Merge.getConflicts().get("x")[0].length); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeFailingWithDirtyWorkingTree() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").addFilepattern("b").call(); |
|
|
|
@ -942,11 +946,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeConflictFileFolder() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
writeTrashFile("b", "1\nb\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").addFilepattern("b").call(); |
|
|
|
@ -981,11 +985,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSuccessfulMergeFailsDueToDirtyIndex() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
File fileA = writeTrashFile("a", "a"); |
|
|
|
|
RevCommit initialCommit = addAllAndCommit(git); |
|
|
|
|
|
|
|
|
@ -1017,11 +1021,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, |
|
|
|
|
indexState, fileA); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testConflictingMergeFailsDueToDirtyIndex() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
File fileA = writeTrashFile("a", "a"); |
|
|
|
|
RevCommit initialCommit = addAllAndCommit(git); |
|
|
|
|
|
|
|
|
@ -1055,11 +1059,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, |
|
|
|
|
indexState, fileA); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSuccessfulMergeFailsDueToDirtyWorktree() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
File fileA = writeTrashFile("a", "a"); |
|
|
|
|
RevCommit initialCommit = addAllAndCommit(git); |
|
|
|
|
|
|
|
|
@ -1090,11 +1094,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, |
|
|
|
|
indexState, fileA); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testConflictingMergeFailsDueToDirtyWorktree() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
File fileA = writeTrashFile("a", "a"); |
|
|
|
|
RevCommit initialCommit = addAllAndCommit(git); |
|
|
|
|
|
|
|
|
@ -1127,6 +1131,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, |
|
|
|
|
indexState, fileA); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeRemovingFolders() throws Exception { |
|
|
|
@ -1143,7 +1148,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
file = new File(folder2, "file2.txt"); |
|
|
|
|
write(file, "folder2--file2.txt"); |
|
|
|
|
|
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
git.add().addFilepattern(folder1.getName()) |
|
|
|
|
.addFilepattern(folder2.getName()).call(); |
|
|
|
|
RevCommit commit1 = git.commit().setMessage("adding folders").call(); |
|
|
|
@ -1167,6 +1172,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertFalse(folder1.exists()); |
|
|
|
|
assertFalse(folder2.exists()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeRemovingFoldersWithoutFastForward() throws Exception { |
|
|
|
@ -1183,7 +1189,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
file = new File(folder2, "file2.txt"); |
|
|
|
|
write(file, "folder2--file2.txt"); |
|
|
|
|
|
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
git.add().addFilepattern(folder1.getName()) |
|
|
|
|
.addFilepattern(folder2.getName()).call(); |
|
|
|
|
RevCommit base = git.commit().setMessage("adding folders").call(); |
|
|
|
@ -1212,14 +1218,13 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
result.getMergeStatus()); |
|
|
|
|
assertFalse(folder1.exists()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFileModeMerge() throws Exception { |
|
|
|
|
if (!FS.DETECTED.supportsExecute()) |
|
|
|
|
return; |
|
|
|
|
// Only Java6
|
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
assumeTrue(FS.DETECTED.supportsExecute()); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("mergeableMode", "a"); |
|
|
|
|
setExecutable(git, "mergeableMode", false); |
|
|
|
|
writeTrashFile("conflictingModeWithBase", "a"); |
|
|
|
@ -1251,15 +1256,14 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertTrue(canExecute(git, "mergeableMode")); |
|
|
|
|
assertFalse(canExecute(git, "conflictingModeNoBase")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFileModeMergeWithDirtyWorkTree() throws Exception { |
|
|
|
|
if (!FS.DETECTED.supportsExecute()) |
|
|
|
|
return; |
|
|
|
|
// Only Java6 (or set x bit in index)
|
|
|
|
|
assumeTrue(FS.DETECTED.supportsExecute()); |
|
|
|
|
|
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("mergeableButDirty", "a"); |
|
|
|
|
setExecutable(git, "mergeableButDirty", false); |
|
|
|
|
RevCommit initialCommit = addAllAndCommit(git); |
|
|
|
@ -1284,11 +1288,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(MergeStatus.FAILED, result.getMergeStatus()); |
|
|
|
|
assertFalse(canExecute(git, "mergeableButDirty")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSquashFastForward() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("file1", "file1"); |
|
|
|
|
git.add().addFilepattern("file1").call(); |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
@ -1350,11 +1354,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
Status stat = git.status().call(); |
|
|
|
|
assertEquals(Sets.of("file2", "file3"), stat.getAdded()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSquashMerge() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("file1", "file1"); |
|
|
|
|
git.add().addFilepattern("file1").call(); |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
@ -1408,11 +1412,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
Status stat = git.status().call(); |
|
|
|
|
assertEquals(Sets.of("file3"), stat.getAdded()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSquashMergeConflict() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("file1", "file1"); |
|
|
|
|
git.add().addFilepattern("file1").call(); |
|
|
|
|
RevCommit first = git.commit().setMessage("initial commit").call(); |
|
|
|
@ -1464,10 +1468,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
Status stat = git.status().call(); |
|
|
|
|
assertEquals(Sets.of("file2"), stat.getConflicting()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFastForwardOnly() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial commit") |
|
|
|
|
.call(); |
|
|
|
|
createBranch(initialCommit, "refs/heads/branch1"); |
|
|
|
@ -1481,10 +1486,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testNoFastForward() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial commit") |
|
|
|
|
.call(); |
|
|
|
|
createBranch(initialCommit, "refs/heads/branch1"); |
|
|
|
@ -1498,11 +1504,12 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testNoFastForwardNoCommit() throws Exception { |
|
|
|
|
// given
|
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial commit") |
|
|
|
|
.call(); |
|
|
|
|
createBranch(initialCommit, "refs/heads/branch1"); |
|
|
|
@ -1525,10 +1532,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertNull(result.getNewHead()); |
|
|
|
|
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFastForwardOnlyNotPossible() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial commit") |
|
|
|
|
.call(); |
|
|
|
|
createBranch(initialCommit, "refs/heads/branch1"); |
|
|
|
@ -1544,6 +1552,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testRecursiveMergeWithConflict() throws Exception { |
|
|
|
@ -1577,8 +1586,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeWithMessageOption() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial").call(); |
|
|
|
@ -1607,11 +1615,11 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
RevCommit newHead = it.next(); |
|
|
|
|
assertEquals("user message", newHead.getFullMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMergeConflictWithMessageOption() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
writeTrashFile("a", "1\na\n3\n"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
RevCommit initialCommit = git.commit().setMessage("initial").call(); |
|
|
|
@ -1637,6 +1645,7 @@ public class MergeCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals("user message\n\nConflicts:\n\ta\n", |
|
|
|
|
db.readMergeCommitMsg()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void setExecutable(Git git, String path, boolean executable) { |
|
|
|
|
FS.DETECTED.setExecute( |
|
|
|
|