Browse Source

diff_tree: Fix add/add and add/exact rename conflicts.

Change-Id: I4217af86a6da6a3dfcbcbd8ff45e95544e33f1e2
Dave Borowitz 13 years ago
parent
commit
1c7cb6c250
3 changed files with 25 additions and 2 deletions
  1. 3 0
      NEWS
  2. 2 0
      dulwich/diff_tree.py
  3. 20 2
      dulwich/tests/test_diff_tree.py

+ 3 - 0
NEWS

@@ -51,6 +51,9 @@
 
   * Correctly advertise capabilities during receive-pack. (Dave Borowitz)
 
+  * Fix add/add and add/rename conflicts in tree_changes_for_merge.
+    (Dave Borowitz)
+
  API CHANGES
 
   * write_pack no longer takes the num_objects argument and requires an object

+ 2 - 0
dulwich/diff_tree.py

@@ -288,6 +288,8 @@ def tree_changes_for_merge(store, parent_tree_ids, tree_id,
         if _all_eq(have, change_type, CHANGE_DELETE):
             if not _all_same(have, old_sha):
                 yield changes
+        elif not _all_same(have, change_type):
+            yield changes
         elif not _matches_any_parent(store, parent_tree_ids, changes):
             yield changes
 

+ 20 - 2
dulwich/tests/test_diff_tree.py

@@ -426,7 +426,25 @@ class TreeChangesTest(DiffTestCase):
             None]],
           [parent1, parent2, parent3], merge)
 
-    def test_tree_changes_for_merge_octopus_add_rename_conflict(self):
+    def test_tree_changes_for_merge_add_add_same_conflict(self):
+        blob = make_object(Blob, data='a\nb\nc\nd\n')
+        parent1 = self.commit_tree([('a', blob)])
+        parent2 = self.commit_tree([])
+        merge = self.commit_tree([('b', blob)])
+        add = TreeChange.add(('b', F, blob.id))
+        self.assertChangesForMergeEqual([[add, add]], [parent1, parent2], merge)
+
+    def test_tree_changes_for_merge_add_exact_rename_conflict(self):
+        blob = make_object(Blob, data='a\nb\nc\nd\n')
+        parent1 = self.commit_tree([('a', blob)])
+        parent2 = self.commit_tree([])
+        merge = self.commit_tree([('b', blob)])
+        self.assertChangesForMergeEqual(
+          [[TreeChange(CHANGE_RENAME, ('a', F, blob.id), ('b', F, blob.id)),
+            TreeChange.add(('b', F, blob.id))]],
+          [parent1, parent2], merge, rename_detector=self.detector)
+
+    def test_tree_changes_for_merge_add_content_rename_conflict(self):
         blob1 = make_object(Blob, data='a\nb\nc\nd\n')
         blob2 = make_object(Blob, data='a\nb\nc\ne\n')
         parent1 = self.commit_tree([('a', blob1)])
@@ -437,7 +455,7 @@ class TreeChangesTest(DiffTestCase):
             TreeChange.add(('b', F, blob2.id))]],
           [parent1, parent2], merge, rename_detector=self.detector)
 
-    def test_tree_changes_for_merge_octopus_modify_rename_conflict(self):
+    def test_tree_changes_for_merge_modify_rename_conflict(self):
         blob1 = make_object(Blob, data='a\nb\nc\nd\n')
         blob2 = make_object(Blob, data='a\nb\nc\ne\n')
         parent1 = self.commit_tree([('a', blob1)])