Rev 7: Handle non-normalized paths being passed in by the user. in http://bzr.arbash-meinel.com/plugins/merge_into

John Arbash Meinel john at arbash-meinel.com
Thu Aug 21 16:51:11 BST 2008


At http://bzr.arbash-meinel.com/plugins/merge_into

------------------------------------------------------------
revno: 7
revision-id: john at arbash-meinel.com-20080821155111-qi179m9m2brnzsuj
parent: john at arbash-meinel.com-20080721181435-clttbrdmno1bmmkq
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: merge_into
timestamp: Thu 2008-08-21 10:51:11 -0500
message:
  Handle non-normalized paths being passed in by the user.
modified:
  merge_into.py                  merge_into.py-20070131214328-dide73mgytkt6kk2-1
  test_bb_merge_into.py          test_bb_merge_into.p-20070131214328-dide73mgytkt6kk2-2
-------------- next part --------------
=== modified file 'merge_into.py'
--- a/merge_into.py	2008-07-21 18:14:35 +0000
+++ b/merge_into.py	2008-08-21 15:51:11 +0000
@@ -157,13 +157,17 @@
     wt.lock_write()
     branch_to_merge.lock_read()
     try:
+        # 'subdir' is given relative to 'this_location', convert it back into a
+        # path relative to wt.basedir. This also normalizes the path, so things
+        # like '.' and '..' are removed.
+        subdir_relpath = wt.relpath(osutils.pathjoin(this_location, subdir))
         target_tree = branch_to_merge.basis_tree()
         target_tree.lock_read()
         try:
             merger = MergeIntoMerger(this_tree=wt,
                                      other_tree=target_tree,
                                      other_branch=branch_to_merge,
-                                     target_subdir=subdir,
+                                     target_subdir=subdir_relpath,
                                     )
             merger.set_base_revision(revision.NULL_REVISION, branch_to_merge)
             conflicts = merger.do_merge()

=== modified file 'test_bb_merge_into.py'
--- a/test_bb_merge_into.py	2008-07-21 18:14:35 +0000
+++ b/test_bb_merge_into.py	2008-08-21 15:51:11 +0000
@@ -52,3 +52,28 @@
         finally:
             project_wt.unlock()
 
+    def test_dotted_name(self):
+        project_wt, lib_wt = self.setup_two_branches()
+
+        self.run_bzr('merge-into ../lib1 ./lib1', working_dir='project')
+
+        project_wt.lock_read()
+        try:
+            new_lib1_id = project_wt.path2id('lib1')
+            # The lib-1 revision should be merged into this one
+            self.assertEqual(['project-1', 'lib-1'],
+                             project_wt.get_parent_ids())
+            files = [(path, ie.kind, ie.file_id)
+                     for path, ie in project_wt.iter_entries_by_dir()]
+            exp_files = [('', 'directory', 'project-root-id'),
+                         ('README', 'file', 'readme-id'),
+                         ('dir', 'directory', 'dir-id'),
+                         ('lib1', 'directory', new_lib1_id),
+                         ('dir/file.c', 'file', 'file.c-id'),
+                         ('lib1/Makefile', 'file', 'makefile-lib-id'),
+                         ('lib1/README', 'file', 'readme-lib-id'),
+                         ('lib1/foo.c', 'file', 'foo.c-lib-id'),
+                        ]
+            self.assertEqual(exp_files, files)
+        finally:
+            project_wt.unlock()



More information about the bazaar-commits mailing list