def test_mv_already_moved_files_forcing_after(self): """Test bzr mv versioned_files to directory/unversioned_file. Tests if an attempt to move an existing versioned file to an existing unversioned file in some other directory will fail, informing the user to use the --after option to force this. Setup: a1, a2, sub are versioned and in the working tree, sub/a1, sub/a2 are in working tree. User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub """ self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2']) tree = self.make_branch_and_tree('.') tree.add(['a1', 'a2', 'sub']) osutils.rename('a1', 'sub/a1') osutils.rename('a2', 'sub/a2') self.build_tree(['a1']) #touch a1 self.build_tree(['a2']) #touch a2 self.run_bzr_error( ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files" " exist. \(Use --after to tell bzr about a rename that has already" " happened\)$"], 'mv a1 a2 sub') self.failUnlessExists('a1') self.failUnlessExists('a2') self.failUnlessExists('sub/a1') self.failUnlessExists('sub/a2')
def test_mv_already_moved_files_using_after(self): """Test bzr mv --after versioned_file to directory/unversioned_file. Tests if an existing versioned file can be forced to move to an existing unversioned file in some other directory using the --after option. With the result that bazaar considers directory/unversioned_file to be moved from versioned_file and versioned_file will become unversioned. Setup: a1, a2, sub are versioned and in the working tree, sub/a1, sub/a2 are in working tree. User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after """ self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2']) tree = self.make_branch_and_tree('.') tree.add(['a1', 'a2', 'sub']) osutils.rename('a1', 'sub/a1') osutils.rename('a2', 'sub/a2') self.build_tree(['a1']) #touch a1 self.build_tree(['a2']) #touch a2 self.run_bzr('mv a1 a2 sub --after') self.failUnlessExists('a1') self.failUnlessExists('a2') self.failUnlessExists('sub/a1') self.failUnlessExists('sub/a2') self.assertInWorkingTree('sub/a1') self.assertInWorkingTree('sub/a2')
def test_mv_already_moved_file_forcing_after(self): """Test bzr mv versioned_file to unversioned_file. Tests if an attempt to move an existing versioned file to an existing unversioned file will fail, informing the user to use the --after option to force this. Setup: a is in the working tree, b not versioned. User does: mv a b; touch a; bzr mv a b """ self.build_tree(["a", "b"]) tree = self.make_branch_and_tree(".") tree.add(["a"]) osutils.rename("a", "b") self.build_tree(["a"]) # touch a self.run_bzr_error( [ "^bzr: ERROR: Could not rename a => b because both files exist." " \(Use --after to tell bzr about a rename that has already" " happened\)$" ], "mv a b", ) self.assertPathExists("a") self.assertPathExists("b")
def make_abcd_tree(self): tree = self.make_branch_and_tree('tree') self.build_tree(['tree/a', 'tree/c']) tree.add(['a', 'c']) tree.commit('record old names') osutils.rename('tree/a', 'tree/b') osutils.rename('tree/c', 'tree/d') return tree
def make_abcd_tree(self): tree = self.make_branch_and_tree("tree") self.build_tree(["tree/a", "tree/c"]) tree.add(["a", "c"]) tree.commit("record old names") osutils.rename("tree/a", "tree/b") osutils.rename("tree/c", "tree/d") return tree
def move(self, rel_from, rel_to): """Move the item at rel_from to the location at rel_to""" path_from = self._abspath(rel_from) path_to = self._abspath(rel_to) try: # this version will delete the destination if necessary osutils.rename(path_from, path_to) except (IOError, OSError),e: # TODO: What about path_to? self._translate_error(e, path_from)
def test_join_error(self): base_tree, sub_tree = self.make_trees() os.mkdir('tree/subtree2') osutils.rename('tree/subtree', 'tree/subtree2/subtree') self.run_bzr_error( ('Cannot join .*subtree. Parent directory is not versioned',), 'join tree/subtree2/subtree') # disabled because this gives an ugly error at present -- mbp 20070306 ## self.run_bzr_error( ## ('Cannot join .*subtree. Parent directory is not versioned',), ## 'join', '--reference', 'tree/subtree2/subtree') self.run_bzr_error(('Not a branch:.*subtree2',), 'join tree/subtree2')
def test_mv_already_moved_file_into_subdir(self): """Test bzr mv original_file to versioned_directory/file. Tests if a file which has already been moved into a versioned directory by an external tool, is handled correctly by bzr mv. Setup: a and sub/ are in the working tree. User does: mv a sub/a; bzr mv a sub/a """ self.build_tree(['a', 'sub/']) tree = self.make_branch_and_tree('.') tree.add(['a', 'sub']) osutils.rename('a', 'sub/a') self.run_bzr('mv a sub/a') self.assertMoved('a','sub/a')
def test_mv_already_moved_file(self): """Test bzr mv original_file to moved_file. Tests if a file which has allready been moved by an external tool, is handled correctly by bzr mv. Setup: a is in the working tree, b does not exist. User does: mv a b; bzr mv a b """ self.build_tree(['a']) tree = self.make_branch_and_tree('.') tree.add(['a']) osutils.rename('a', 'b') self.run_bzr('mv a b') self.assertMoved('a','b')
def test_re_add(self): """Test than when a file has 'unintentionally' changed case, we can't add a new entry using the new case.""" wt = self.make_branch_and_tree('.') # create a file on disk with the mixed-case name self.build_tree(['MixedCase']) run_script(self, """ $ bzr add MixedCase adding MixedCase """) # 'accidently' rename the file on disk osutils.rename('MixedCase', 'mixedcase') run_script(self, """ $ bzr add mixedcase """)
def test_mv_newcase_after(self): wt = self._make_mixed_case_tree() self.run_bzr('add') self.run_bzr('ci -m message') # perform a mv to the new case - we must ensure the file-system has the # new case first. osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase') run_script(self, """ $ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase CamelCaseParent/CamelCase => CamelCaseParent/camelCase """) # bzr should not have renamed the file to a different case self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'), 'CamelCaseParent/camelCase')
def test_mv_already_moved_files_into_subdir(self): """Test bzr mv original_files to versioned_directory. Tests if files which has already been moved into a versioned directory by an external tool, is handled correctly by bzr mv. Setup: a1, a2, sub are in the working tree. User does: mv a1 sub/.; bzr mv a1 a2 sub """ self.build_tree(['a1', 'a2', 'sub/']) tree = self.make_branch_and_tree('.') tree.add(['a1', 'a2', 'sub']) osutils.rename('a1', 'sub/a1') self.run_bzr('mv a1 a2 sub') self.assertMoved('a1','sub/a1') self.assertMoved('a2','sub/a2')
def test_re_add(self): """Test than when a file has 'unintentionally' changed case, we can't add a new entry using the new case.""" wt = self.make_branch_and_tree('.') # create a file on disk with the mixed-case name self.build_tree(['MixedCase']) run_script( self, """ $ bzr add MixedCase adding MixedCase """) # 'accidently' rename the file on disk osutils.rename('MixedCase', 'mixedcase') run_script(self, """ $ bzr add mixedcase """)
def test_mv_already_moved_file_into_unversioned_subdir(self): """Test bzr mv original_file to unversioned_directory/file. Tests if an attempt to move an existing versioned file into an unversioned directory will fail. Setup: a is in the working tree, sub/ is not. User does: mv a sub/a; bzr mv a sub/a """ self.build_tree(["a", "sub/"]) tree = self.make_branch_and_tree(".") tree.add(["a"]) osutils.rename("a", "sub/a") self.run_bzr_error(["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"], "mv a sub/a") self.assertPathDoesNotExist("a") self.assertPathExists("sub/a")
def test_mv_newname_exists_after(self): # test a 'mv --after', but when the target already exists with a name # that differs only by case. Note that this is somewhat unlikely # but still reasonable. wt = self._make_mixed_case_tree() self.run_bzr('add') self.run_bzr('ci -m message') # Remove the source and create a destination file on disk with a different case. # bzr should report that the filename is already versioned. os.unlink('CamelCaseParent/CamelCase') osutils.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE') run_script(self, """ $ bzr mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE 2>bzr: ERROR: Could not move CamelCase => lowercase: \ lowercaseparent/lowercase is already versioned. """)
def test_re_add_dir(self): # like re-add, but tests when the operation is on a directory. """Test than when a file has 'unintentionally' changed case, we can't add a new entry using the new case.""" wt = self.make_branch_and_tree('.') # create a file on disk with the mixed-case name self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase']) run_script(self, """ $ bzr add MixedCaseParent adding MixedCaseParent adding MixedCaseParent/MixedCase """) # 'accidently' rename the directory on disk osutils.rename('MixedCaseParent', 'mixedcaseparent') run_script(self, """ $ bzr add mixedcaseparent """)
def test_mv_newname_exists_after(self): # test a 'mv --after', but when the target already exists with a name # that differs only by case. Note that this is somewhat unlikely # but still reasonable. wt = self._make_mixed_case_tree() self.run_bzr('add') self.run_bzr('ci -m message') # Remove the source and create a destination file on disk with a different case. # bzr should report that the filename is already versioned. os.unlink('CamelCaseParent/CamelCase') osutils.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE') run_script( self, """ $ bzr mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE 2>bzr: ERROR: Could not move CamelCase => lowercase: \ lowercaseparent/lowercase is already versioned. """)
def test_mv_already_moved_file_to_versioned_target(self): """Test bzr mv existing_file to versioned_file. Tests if an attempt to move an existing versioned file to another versiond file will fail. Setup: a and b are in the working tree. User does: rm b; mv a b; bzr mv a b """ self.build_tree(["a", "b"]) tree = self.make_branch_and_tree(".") tree.add(["a", "b"]) os.remove("b") osutils.rename("a", "b") self.run_bzr_error(["^bzr: ERROR: Could not move a => b. b is already versioned\.$"], "mv a b") # check that nothing changed self.assertPathDoesNotExist("a") self.assertPathExists("b")
def test_re_add_dir(self): # like re-add, but tests when the operation is on a directory. """Test than when a file has 'unintentionally' changed case, we can't add a new entry using the new case.""" wt = self.make_branch_and_tree('.') # create a file on disk with the mixed-case name self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase']) run_script( self, """ $ bzr add MixedCaseParent adding MixedCaseParent adding MixedCaseParent/MixedCase """) # 'accidently' rename the directory on disk osutils.rename('MixedCaseParent', 'mixedcaseparent') run_script(self, """ $ bzr add mixedcaseparent """)
def test_mv_newcase_after(self): wt = self._make_mixed_case_tree() self.run_bzr('add') self.run_bzr('ci -m message') # perform a mv to the new case - we must ensure the file-system has the # new case first. osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase') run_script( self, """ $ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase CamelCaseParent/CamelCase => CamelCaseParent/camelCase """) # bzr should not have renamed the file to a different case self.failUnlessEqual( canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'), 'CamelCaseParent/camelCase')
def test_mv_already_moved_file_into_unversioned_subdir(self): """Test bzr mv original_file to unversioned_directory/file. Tests if an attempt to move an existing versioned file into an unversioned directory will fail. Setup: a is in the working tree, sub/ is not. User does: mv a sub/a; bzr mv a sub/a """ self.build_tree(['a', 'sub/']) tree = self.make_branch_and_tree('.') tree.add(['a']) osutils.rename('a', 'sub/a') self.run_bzr_error( ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"], 'mv a sub/a') self.failIfExists('a') self.failUnlessExists('sub/a')
def test_mv_already_moved_file_to_versioned_target(self): """Test bzr mv existing_file to versioned_file. Tests if an attempt to move an existing versioned file to another versiond file will fail. Setup: a and b are in the working tree. User does: rm b; mv a b; bzr mv a b """ self.build_tree(['a', 'b']) tree = self.make_branch_and_tree('.') tree.add(['a', 'b']) os.remove('b') osutils.rename('a', 'b') self.run_bzr_error( ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"], 'mv a b') #check that nothing changed self.failIfExists('a') self.failUnlessExists('b')
def test_mv_already_moved_files_into_unversioned_subdir(self): """Test bzr mv original_file to unversioned_directory. Tests if an attempt to move existing versioned file into an unversioned directory will fail. Setup: a1, a2 are in the working tree, sub is not. User does: mv a1 sub/.; bzr mv a1 a2 sub """ self.build_tree(['a1', 'a2', 'sub/']) tree = self.make_branch_and_tree('.') tree.add(['a1', 'a2']) osutils.rename('a1', 'sub/a1') self.run_bzr_error( ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"], 'mv a1 a2 sub') self.failIfExists('a1') self.failUnlessExists('sub/a1') self.failUnlessExists('a2') self.failIfExists('sub/a2')
def test_mv_already_moved_directory(self): """Use `bzr mv a b` to mark a directory as renamed. https://bugs.launchpad.net/bzr/+bug/107967/ """ self.build_tree(['a/', 'c/']) tree = self.make_branch_and_tree('.') tree.add(['a', 'c']) osutils.rename('a', 'b') osutils.rename('c', 'd') # mv a b should work just like it does for already renamed files self.run_bzr('mv a b') self.failIfExists('a') self.assertNotInWorkingTree('a') self.failUnlessExists('b') self.assertInWorkingTree('b') # and --after should work, too (technically it's ignored) self.run_bzr('mv --after c d') self.failIfExists('c') self.assertNotInWorkingTree('c') self.failUnlessExists('d') self.assertInWorkingTree('d')
def test_mv_already_moved_directory(self): """Use `bzr mv a b` to mark a directory as renamed. https://bugs.launchpad.net/bzr/+bug/107967/ """ self.build_tree(["a/", "c/"]) tree = self.make_branch_and_tree(".") tree.add(["a", "c"]) osutils.rename("a", "b") osutils.rename("c", "d") # mv a b should work just like it does for already renamed files self.run_bzr("mv a b") self.assertPathDoesNotExist("a") self.assertNotInWorkingTree("a") self.assertPathExists("b") self.assertInWorkingTree("b") # and --after should work, too (technically it's ignored) self.run_bzr("mv --after c d") self.assertPathDoesNotExist("c") self.assertNotInWorkingTree("c") self.assertPathExists("d") self.assertInWorkingTree("d")
def test_mv_already_moved_file_using_after(self): """Test bzr mv --after versioned_file to unversioned_file. Tests if an existing versioned file can be forced to move to an existing unversioned file using the --after option. With the result that bazaar considers the unversioned_file to be moved from versioned_file and versioned_file will become unversioned. Setup: a is in the working tree and b exists. User does: mv a b; touch a; bzr mv a b --after Resulting in a => b and a is unknown. """ self.build_tree(['a', 'b']) tree = self.make_branch_and_tree('.') tree.add(['a']) osutils.rename('a', 'b') self.build_tree(['a']) #touch a self.run_bzr('mv a b --after') self.failUnlessExists('a') self.assertNotInWorkingTree('a')#a should be unknown now. self.failUnlessExists('b') self.assertInWorkingTree('b')
def test_mv_already_moved_file_forcing_after(self): """Test bzr mv versioned_file to unversioned_file. Tests if an attempt to move an existing versioned file to an existing unversioned file will fail, informing the user to use the --after option to force this. Setup: a is in the working tree, b not versioned. User does: mv a b; touch a; bzr mv a b """ self.build_tree(['a', 'b']) tree = self.make_branch_and_tree('.') tree.add(['a']) osutils.rename('a', 'b') self.build_tree(['a']) #touch a self.run_bzr_error( ["^bzr: ERROR: Could not rename a => b because both files exist." " \(Use --after to tell bzr about a rename that has already" " happened\)$"], 'mv a b') self.failUnlessExists('a') self.failUnlessExists('b')
def prepare_lightweight_switch(self): branch = self.make_branch('branch') branch.create_checkout('tree', lightweight=True) osutils.rename('branch', 'branch1')