Rev 4624: Tests passing for a minimal --interactive implementation. in file:///home/vila/src/bzr/experimental/conflict-manager/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Oct 16 17:31:24 BST 2009
At file:///home/vila/src/bzr/experimental/conflict-manager/
------------------------------------------------------------
revno: 4624
revision-id: v.ladeuil+lp at free.fr-20091016163124-zeitc3cilvvwm9xd
parent: v.ladeuil+lp at free.fr-20091016134119-lph6s0v463k6jv1e
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: description
timestamp: Fri 2009-10-16 18:31:24 +0200
message:
Tests passing for a minimal --interactive implementation.
* bzrlib/tests/test_conflicts.py:
(TestResolveDuplicatePaths.test_resolve_keeping_this,
TestResolveDuplicatePaths.test_resolve_keeping_other): Use better
action names.
* bzrlib/tests/blackbox/test_conflicts.py:
(TestResolve.test_resolve_interactive): Fix failing test by
providing an exiting action.
* bzrlib/conflicts.py:
(_resolve_interactive): Minimal implementation.
-------------- next part --------------
=== modified file 'bzrlib/conflicts.py'
--- a/bzrlib/conflicts.py 2009-10-16 13:41:19 +0000
+++ b/bzrlib/conflicts.py 2009-10-16 16:31:24 +0000
@@ -104,9 +104,11 @@
tree = workingtree.WorkingTree.open_containing('.')[0]
resolve(tree)
elif interactive:
+ tree, file_list = builtins.tree_files(file_list)
if file_list is None or len(file_list) != 1:
raise errors.BzrCommandError(
'--interactive requires a single FILE parameter')
+ _resolve_interactive( tree, file_list[0])
else:
tree, file_list = builtins.tree_files(file_list)
if file_list is None:
@@ -156,6 +158,33 @@
tree.unlock()
+def _resolve_interactive(tree, path):
+ import sys # TEMPORARY
+ tree.lock_tree_write()
+ try:
+ tree_conflicts = tree.conflicts()
+ (remaining,
+ selected) = tree_conflicts.select_conflicts(
+ tree, [path], ignore_misses=True)
+ if not selected:
+ raise errors.NotConflicted(path)
+ # FIXME: we should really do a loop below as some paths may be involved
+ # in several conflicts but it's not yet clear how we will handle that.
+ c = selected[0]
+ action_name = sys.stdin.readline()
+ action_name = action_name.rstrip('\n')
+ # Crude exit
+ if action_name == 'quit':
+ return
+ action = getattr(c, action_name, None)
+ if action is None:
+ raise NotImplementedError(action_name)
+ action(tree)
+ tree.set_conflicts(remaining)
+ finally:
+ tree.unlock()
+
+
def restore(filename):
"""Restore a conflicted file to the state it was in before merging.
@@ -469,6 +498,13 @@
format = 'Conflict adding file %(conflict_path)s. %(action)s %(path)s.'
+ def keep_this(self, tree):
+ tree.remove([self.conflict_path], force=True, keep_files=False)
+ tree.rename_one(self.path, self.conflict_path)
+
+ def keep_other(self, tree):
+ tree.remove([self.path], force=True, keep_files=False)
+
class ParentLoop(HandledPathConflict):
"""An attempt to create an infinitely-looping directory structure.
=== modified file 'bzrlib/tests/blackbox/test_conflicts.py'
--- a/bzrlib/tests/blackbox/test_conflicts.py 2009-10-16 13:41:19 +0000
+++ b/bzrlib/tests/blackbox/test_conflicts.py 2009-10-16 16:31:24 +0000
@@ -122,7 +122,8 @@
self.assertContainsRe(note, 'All conflicts resolved.')
def test_resolve_interactive(self):
- out, err = self.run_bzr('resolve --interactive mydir2', retcode=0)
+ out, err = self.run_bzr('resolve --interactive mydir2', retcode=0,
+ stdin='quit')
def test_resolve_interactive_all(self):
self.run_bzr_error(['--all and --interactive are mutually exclusive'],
=== modified file 'bzrlib/tests/test_conflicts.py'
--- a/bzrlib/tests/test_conflicts.py 2009-10-16 12:54:42 +0000
+++ b/bzrlib/tests/test_conflicts.py 2009-10-16 16:31:24 +0000
@@ -22,6 +22,7 @@
conflicts,
errors,
tests,
+ workingtree,
)
from bzrlib.tests import script
@@ -274,15 +275,15 @@
def test_resolve_keeping_this(self):
self.run_script("""
-$ bzr resolve --interactive file
-<this
+$ bzr resolve --interactive file2
+<keep_this
$ bzr commit --strict -m 'No more conflicts nor unknown files'
""")
def test_resolve_keeping_other(self):
self.run_script("""
-$ bzr resolve --interactive file
-<other
+$ bzr resolve --interactive file2
+<keep_other
$ bzr commit --strict -m 'No more conflicts nor unknown files'
""")
More information about the bazaar-commits
mailing list