Permalink
Browse files

Merge added in both.

  • Loading branch information...
1 parent 6c6cb94 commit 4ab2d27349cf3f20b34b2b751d24f413d235141a @chrisrossi chrisrossi committed Sep 12, 2012
Showing with 63 additions and 1 deletion.
  1. +30 −0 acidfs/__init__.py
  2. +33 −1 acidfs/tests.py
View
@@ -634,6 +634,10 @@ def expect(expectation, *msg):
state = _MERGE_CHANGED_IN_BOTH
extra_state = []
+ elif line == 'added in both':
+ state = _MERGE_ADDED_IN_BOTH
+ extra_state = []
+
else: # pragma NO COVER
log.debug("Don't know how to merge: %s", line)
raise ConflictError()
@@ -724,6 +728,31 @@ def expect(expectation, *msg):
else:
extra_state.append(line)
+ elif state is _MERGE_ADDED_IN_BOTH:
+ if line[0].isalpha() or line[0] == '@':
+ # Done collecting tree lines, expect two, one for base,
+ # one for our copy, whose sha1s should match
+ expect(len(extra_state) == 2, 'Wrong number of lines')
+ whose, mode, oid, path = extra_state[0].split()
+ expect(whose in ('our', 'their'), 'Unexpected whose: %s',
+ whose)
+ expect(mode == '100644', 'Unexpected mode: %s', mode)
+ whose, mode, oid2, path2 = extra_state[1].split()
+ expect(whose in ('our', 'their'), 'Unexpected whose: %s',
+ whose)
+ expect(mode == '100644', 'Unexpected mode: %s', mode)
+ expect(path == path2, "Paths don't match")
+ # Either it's the same file or a different file.
+ if oid != oid2:
+ # Different files, can't merge
+ raise ConflictError()
+ # Same file, nothing to do
+ state = extra_state = None
+ continue
+
+ else:
+ extra_state.append(line)
+
line = stream.readline()
@@ -962,3 +991,4 @@ def _DirectoryNotEmpty(path):
_MERGE_ADDED_IN_REMOTE = object()
_MERGE_REMOVED_IN_REMOTE = object()
_MERGE_CHANGED_IN_BOTH = object()
+_MERGE_ADDED_IN_BOTH = object()
View
@@ -450,7 +450,7 @@ def test_conflict_error_on_first_commit(self):
with self.assertRaises(ConflictError):
transaction.commit()
- def test_conflict_error(self):
+ def test_unable_to_merge_file(self):
from acidfs import ConflictError
fs = self.make_one()
fs.open('foo', 'w').write('Hello!')
@@ -513,6 +513,38 @@ def test_merge_rm_same_file(self):
self.assertFalse(fs.exists('foo'))
self.assertTrue(fs.exists('bar'))
+ def test_merge_add_same_file(self):
+ fs = self.make_one(head='master')
+ fs.open('foo', 'w').write('Hello\n')
+ transaction.commit()
+
+ base = fs.get_base()
+ fs.open('bar', 'w').write('Grazie\n')
+ transaction.commit()
+
+ fs.set_base(base)
+ fs.open('bar', 'w').write('Grazie\n')
+ # Do something else besides, so commit has different sha1
+ fs.open('baz', 'w').write('Prego\n')
+ transaction.commit()
+
+ self.assertEqual(fs.open('bar').read(), 'Grazie\n')
+
+ def test_merge_add_different_file_same_path(self):
+ from acidfs import ConflictError
+ fs = self.make_one(head='master')
+ fs.open('foo', 'w').write('Hello\n')
+ transaction.commit()
+
+ base = fs.get_base()
+ fs.open('bar', 'w').write('Grazie\n')
+ transaction.commit()
+
+ fs.set_base(base)
+ fs.open('bar', 'w').write('Prego\n')
+ with self.assertRaises(ConflictError):
+ transaction.commit()
+
def test_merge_file(self):
fs = self.make_one()
with fs.open('foo', 'w') as f:

0 comments on commit 4ab2d27

Please sign in to comment.