~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-18 02:49:45 UTC
  • mfrom: (3249.4.2 mv.dir.after)
  • Revision ID: pqm@pqm.ubuntu.com-20080318024945-zhs03078h06fbk6l
(Lukas Lalinsky) Make 'mv a b' work for already renamed directories,
 like it does for files. (#107967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
534
534
        if len(names_list) < 2:
535
535
            raise errors.BzrCommandError("missing file argument")
536
536
        tree, rel_names = tree_files(names_list)
 
537
        tree.lock_write()
 
538
        try:
 
539
            self._run(tree, names_list, rel_names, after)
 
540
        finally:
 
541
            tree.unlock()
537
542
 
538
 
        dest = names_list[-1]
539
 
        isdir = os.path.isdir(dest)
540
 
        if (isdir and not tree.case_sensitive and len(rel_names) == 2
541
 
            and rel_names[0].lower() == rel_names[1].lower()):
542
 
                isdir = False
543
 
        if isdir:
 
543
    def _run(self, tree, names_list, rel_names, after):
 
544
        into_existing = osutils.isdir(names_list[-1])
 
545
        if into_existing and len(names_list) == 2:
 
546
            # special cases:
 
547
            # a. case-insensitive filesystem and change case of dir
 
548
            # b. move directory after the fact (if the source used to be
 
549
            #    a directory, but now doesn't exist in the working tree
 
550
            #    and the target is an existing directory, just rename it)
 
551
            if (not tree.case_sensitive
 
552
                and rel_names[0].lower() == rel_names[1].lower()):
 
553
                into_existing = False
 
554
            else:
 
555
                inv = tree.inventory
 
556
                from_id = tree.path2id(rel_names[0])
 
557
                if (not osutils.lexists(names_list[0]) and
 
558
                    from_id and inv.get_file_kind(from_id) == "directory"):
 
559
                    into_existing = False
 
560
        # move/rename
 
561
        if into_existing:
544
562
            # move into existing directory
545
563
            for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
546
564
                self.outf.write("%s => %s\n" % pair)