/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Marius Kruger
  • Date: 2007-02-16 06:16:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2455.
  • Revision ID: amanic@gmail.com-20070216061611-sjscmgi4v5rozq6h
"bzr remove" and "bzr rm" will now remove the working file.
This has been done for consistency with svn and the unix rm command.

The old remove behaviour has been retained in the new command
"bzr unversion", which will just stop versioning the file,
but not delete it.
(Addressing Bug #82602)

Exisitng tests have been reworked and new tests were added to test these
changes properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1614
1614
        return result
1615
1615
 
1616
1616
    @needs_tree_write_lock
1617
 
    def remove(self, files, verbose=False, to_file=None):
 
1617
    def remove(self, files, verbose=False, to_file=None, delete_files=False):
1618
1618
        """Remove nominated files from the working inventory..
1619
1619
 
1620
 
        This does not remove their text.  This does not run on XXX on what? RBC
1621
 
 
1622
1620
        TODO: Refuse to remove modified files unless --force is given?
1623
1621
 
1624
1622
        TODO: Do something useful with directories.
1625
1623
 
1626
 
        TODO: Should this remove the text or not?  Tough call; not
1627
 
        removing may be useful and the user can just use use rm, and
1628
 
        is the opposite of add.  Removing it is consistent with most
1629
 
        other tools.  Maybe an option.
 
1624
        :delete_files: If true, the files will also be delete.
 
1625
                       At present recursion is not supported.
1630
1626
        """
1631
1627
        ## TODO: Normalize names
1632
1628
        ## TODO: Remove nested loops; better scalability
1635
1631
 
1636
1632
        inv = self.inventory
1637
1633
 
 
1634
        # Sort needed when deleting files:
 
1635
        # first delete directory content before the directory
 
1636
        if delete_files:
 
1637
            files = files[:]
 
1638
            files.sort(reverse=True)
 
1639
 
1638
1640
        # do this before any modifications
1639
1641
        for f in files:
1640
1642
            fid = inv.path2id(f)
 
1643
            message=None
1641
1644
            if not fid:
1642
 
                note("%s is not versioned."%f)
 
1645
                message="%s is not versioned."%f
1643
1646
            else:
1644
1647
                if verbose:
1645
1648
                    # having remove it, it must be either ignored or unknown
1650
1653
                    textui.show_status(new_status, inv[fid].kind, f,
1651
1654
                                       to_file=to_file)
1652
1655
                del inv[fid]
1653
 
 
 
1656
            if delete_files:
 
1657
                if osutils.lexists(f):
 
1658
                    osutils.delete_any(f)
 
1659
                else:
 
1660
                    message="%s does not exist."%f
 
1661
            # print only one message per file.
 
1662
            if message is not None:
 
1663
                note(message)
1654
1664
        self._write_inventory(inv)
1655
1665
 
1656
1666
    @needs_tree_write_lock