833
833
return self.revision_tree(self.last_revision())
837
def move(self, from_paths, to_name):
840
to_name must exist as a versioned directory.
842
If to_name exists and is a directory, the files are moved into
843
it, keeping their old names. If it is a directory,
845
Note that to_name is only the last component of the new name;
846
this doesn't change the directory.
848
This returns a list of (from_path, to_path) pairs for each
852
## TODO: Option to move IDs only
853
assert not isinstance(from_paths, basestring)
854
tree = self.working_tree()
856
to_abs = self.abspath(to_name)
857
if not isdir(to_abs):
858
raise BzrError("destination %r is not a directory" % to_abs)
859
if not tree.has_filename(to_name):
860
raise BzrError("destination %r not in working directory" % to_abs)
861
to_dir_id = inv.path2id(to_name)
862
if to_dir_id == None and to_name != '':
863
raise BzrError("destination %r is not a versioned directory" % to_name)
864
to_dir_ie = inv[to_dir_id]
865
if to_dir_ie.kind not in ('directory', 'root_directory'):
866
raise BzrError("destination %r is not a directory" % to_abs)
868
to_idpath = inv.get_idpath(to_dir_id)
871
if not tree.has_filename(f):
872
raise BzrError("%r does not exist in working tree" % f)
873
f_id = inv.path2id(f)
875
raise BzrError("%r is not versioned" % f)
876
name_tail = splitpath(f)[-1]
877
dest_path = appendpath(to_name, name_tail)
878
if tree.has_filename(dest_path):
879
raise BzrError("destination %r already exists" % dest_path)
880
if f_id in to_idpath:
881
raise BzrError("can't move %r to a subdirectory of itself" % f)
883
# OK, so there's a race here, it's possible that someone will
884
# create a file in this interval and then the rename might be
885
# left half-done. But we should have caught most problems.
888
name_tail = splitpath(f)[-1]
889
dest_path = appendpath(to_name, name_tail)
890
result.append((f, dest_path))
891
inv.rename(inv.path2id(f), to_dir_id, name_tail)
893
rename(self.abspath(f), self.abspath(dest_path))
895
raise BzrError("failed to rename %r to %r: %s" % (f, dest_path, e[1]),
896
["rename rolled back"])
898
self.working_tree()._write_inventory(inv)
901
835
def get_parent(self):
902
836
"""Return the parent location of the branch.