edgimar avatar edgimar committed 08d9f2e

- create treemerge function which depends on diff3_text
- add (simple) test for treemerge function

Comments (0)

Files changed (2)

 import sys
 import re
 import cStringIO
-
+import diff3
 
 class TasksTree(object):
     """
     
     return joined_tree
 
+def treemerge(new_tree, old_tree, other_tree):
+    old = str(old_tree)
+    other = str(other_tree)
+    new = str(new_tree)
+    merged_text, was_conflict = diff3.merge3_text(new, old, other)
+    
+    merged_tree = parse_text(merged_text)
+    
+    return merged_tree, was_conflict
 
 def get_service():
     """
             ** Headline A2.1
             """)
         self.assertEqual(str(target_tree), target_text)
+        
+    def test_merge(self):
+        org_text0 = textwrap.dedent("""\
+            * Headline A1
+            * Headline A2
+            ** Headline A2.1
+            * Headline B1
+            ** Headline B1.1
+            * Headline B2
+            """)
+        org_text1 = textwrap.dedent("""\
+            * Headline A1
+            * Headline B1
+            ** Headline B1.1
+            * Headline A2
+            ** Headline A2.1
+            * Headline B2
+            """)
+        org_text2 = textwrap.dedent("""\
+            * Headline A1
+            * Headline A2
+            ** Headline A2.1
+            * Headline B1
+            ** Headline B1.1
+            * Headline B2 modified
+            New B2 body text.
+            """)
+        tree0 = m.parse_text(org_text0) # original tree
+        tree1 = m.parse_text(org_text1) # modified tree 1
+        tree2 = m.parse_text(org_text2) # modified tree 2
+        
+        merged_tree, had_conflict = m.treemerge(tree1, tree0, tree2)
+        self.assertTrue(had_conflict)
+        self.assertTrue(str(merged_tree).find("<<<<<<< MINE"))
 
 if __name__ == '__main__':
     unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.