[patch] handle 'bzr resolve' in subdirectory

Martin Pool mbp at sourcefrog.net
Wed Apr 12 05:43:33 BST 2006


This fixes a bug I saw the other day: if you're in e.g. bzrlib and type
"bzr resolve branch.py" it doesn't work.  As you might expect it was not
calling relpath() at the right time.

-- 
Martin
-------------- next part --------------
=== modified file 'a/bzrlib/conflicts.py'
--- a/bzrlib/conflicts.py	
+++ b/bzrlib/conflicts.py	
@@ -53,6 +53,7 @@
         wt = WorkingTree.open_containing(u'.')[0]
         for conflict in wt.conflicts():
             print conflict
+
 
 class cmd_resolve(bzrlib.commands.Command):
     """Mark a conflict as resolved.
@@ -81,8 +82,10 @@
             if all:
                 raise BzrCommandError(
                     "If --all is specified, no FILE may be provided")
-        tree = WorkingTree.open_containing(u'.')[0]
-        resolve(tree, file_list)
+                # XXX: arguably this should take a directory and mark as
+                # resolved everything within it?
+        tree = WorkingTree.open_containing(file_list[0])[0]
+        resolve(tree, [tree.relpath(p) for p in file_list])
 
 
 def resolve(tree, paths=None, ignore_misses=False):
@@ -133,7 +136,10 @@
 
 
 class ConflictList(object):
-    """List of conflicts
+    """List of conflicts.
+
+    Typically obtained from WorkingTree.conflicts()
+
     Can be instantiated from stanzas or from Conflict subclasses.
     """
 
@@ -143,6 +149,9 @@
             self.__list = []
         else:
             self.__list = conflicts
+
+    def is_empty(self):
+        return len(self.__list) == 0
 
     def __len__(self):
         return len(self.__list)

=== modified file 'a/bzrlib/tests/blackbox/test_conflicts.py'
--- a/bzrlib/tests/blackbox/test_conflicts.py	
+++ b/bzrlib/tests/blackbox/test_conflicts.py	
@@ -1,5 +1,4 @@
 # Copyright (C) 2006 by Canonical Ltd
-# -*- coding: utf-8 -*-
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,6 +16,7 @@
 
 import os
 
+from bzrlib.workingtree import WorkingTree
 from bzrlib.tests.blackbox import ExternalBase
 
 class TestConflicts(ExternalBase):
@@ -62,3 +62,18 @@
         conflicts = self.runbzr('conflicts', backtick=True)
         self.assertEqual(len(conflicts.splitlines()), 0)
 
+    def test_resolve_in_subdir(self):
+        """resolve when run from subdirectory should handle relative paths"""
+        orig_dir = os.getcwdu()
+        try:
+            os.mkdir("subdir")
+            os.chdir("subdir")
+            self.runbzr("resolve ../myfile")
+            os.chdir("../../b")
+            self.runbzr("resolve ../a/myfile")
+            wt = WorkingTree.open_containing('.')[0]
+            conflicts = wt.conflicts()
+            if not conflicts.is_empty():
+                self.fail("tree still contains conflicts: %r" % conflicts)
+        finally:
+            os.chdir(orig_dir)



More information about the bazaar mailing list