aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorLaurent Goubet <laurent.goubet@obeo.fr>2014-07-28 14:27:05 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2014-08-02 23:36:31 +0200
commit1fd150d565c10da901784071c2d82319a3fd8be4 (patch)
treecd8f3d85c448d70009bf4c1798a6b9fecaf44afc /org.eclipse.jgit.test/tst/org/eclipse/jgit
parentddbf67e0588379f2a063cf57b1d3ca926b43e63d (diff)
downloadjgit-1fd150d565c10da901784071c2d82319a3fd8be4.tar.gz
jgit-1fd150d565c10da901784071c2d82319a3fd8be4.zip
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>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java116
1 files changed, 116 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
index a1e16e4cf7..a85198f019 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
@@ -579,6 +579,122 @@ public class IndexDiffTest extends RepositoryTestCase {
}
@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);
FileBasedConfig config = db.getConfig();