Browse Source

Add IndexDiff tests for merge conflict state BOTH_ADDED

JGit handled this case improperly which these tests demonstrate. Fixed
by I25915880f304090fe90584c79bddf021231227a2.

Bug: 440537
Change-Id: Ia29c1d6cf8c0ce724cc3ff5ed9e0b396949b44bf
Signed-off-by: Laurent Goubet <laurent.goubet@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-3.5
Laurent Goubet 10 years ago committed by Matthias Sohn
parent
commit
1fd150d565
  1. 116
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

116
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

@ -578,6 +578,122 @@ public class IndexDiffTest extends RepositoryTestCase {
assertTrue(StageState.BOTH_ADDED.hasTheirs());
}
@Test
public void testStageState_mergeAndReset_bug() throws Exception {
Git git = new Git(db);
writeTrashFile("a", "content");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
// create branch and add a new file
final String branchName = Constants.R_HEADS + "branch";
createBranch(initialCommit, branchName);
checkoutBranch(branchName);
writeTrashFile("b", "second file content - branch");
git.add().addFilepattern("b").call();
RevCommit branchCommit = git.commit().setMessage("branch commit")
.call();
// checkout master and add the same new file
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
writeTrashFile("b", "second file content - master");
git.add().addFilepattern("b").call();
git.commit().setMessage("master commit").call();
// try and merge
MergeResult result = git.merge().include(branchCommit).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff();
assertTrue(diff.getChanged().isEmpty());
assertTrue(diff.getAdded().isEmpty());
assertTrue(diff.getRemoved().isEmpty());
assertTrue(diff.getMissing().isEmpty());
assertTrue(diff.getModified().isEmpty());
assertEquals(1, diff.getConflicting().size());
assertTrue(diff.getConflicting().contains("b"));
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
.get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty());
// reset file b to its master state without altering the index
writeTrashFile("b", "second file content - master");
// we should have the same result
iterator = new FileTreeIterator(db);
diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff();
assertTrue(diff.getChanged().isEmpty());
assertTrue(diff.getAdded().isEmpty());
assertTrue(diff.getRemoved().isEmpty());
assertTrue(diff.getMissing().isEmpty());
assertTrue(diff.getModified().isEmpty());
assertEquals(1, diff.getConflicting().size());
assertTrue(diff.getConflicting().contains("b"));
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
.get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty());
}
@Test
public void testStageState_simulated_bug() throws Exception {
Git git = new Git(db);
writeTrashFile("a", "content");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
// create branch and add a new file
final String branchName = Constants.R_HEADS + "branch";
createBranch(initialCommit, branchName);
checkoutBranch(branchName);
writeTrashFile("b", "second file content - branch");
git.add().addFilepattern("b").call();
git.commit().setMessage("branch commit")
.call();
// checkout master and add the same new file
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
writeTrashFile("b", "second file content - master");
git.add().addFilepattern("b").call();
git.commit().setMessage("master commit").call();
// Simulate a failed merge of branch into master
DirCacheBuilder builder = db.lockDirCache().builder();
DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0,
"content");
builder.add(entry);
entry = createEntry("b", FileMode.REGULAR_FILE, 2,
"second file content - master");
builder.add(entry);
entry = createEntry("b", FileMode.REGULAR_FILE, 3,
"second file content - branch");
builder.add(entry);
builder.commit();
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff();
assertTrue(diff.getChanged().isEmpty());
assertTrue(diff.getAdded().isEmpty());
assertTrue(diff.getRemoved().isEmpty());
assertTrue(diff.getMissing().isEmpty());
assertTrue(diff.getModified().isEmpty());
assertEquals(1, diff.getConflicting().size());
assertTrue(diff.getConflicting().contains("b"));
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
.get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty());
}
@Test
public void testAutoCRLFInput() throws Exception {
Git git = new Git(db);

Loading…
Cancel
Save