[merge][rfc] New command: 'bzr remove-tree'

Daniel Silverstone dsilvers at digital-scurf.org
Fri Nov 10 22:37:19 GMT 2006


There is a lot of conversation about the correct name for this command
but I coded up the minor builtin 'remove-tree' and added blackbox tests
and a NEWS item for it.

There is talk of making it a hidden command until a better name comes
up, but I'm not clever enough to do that yet I don't think (or at least
I don't know how to do it :-)

You can find it at http://bzr.digital-scurf.org/trees/dsilvers/bzr.dev

Also, the bundle is attached.

I'd like opinions on the UI for it, and its functionality limits.

D.

-- 
Daniel Silverstone                         http://www.digital-scurf.org/
PGP mail accepted and encouraged.            Key Id: 2BC8 4016 2068 7895

-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Add remove-tree and its blackbox tests
# committer: Daniel Silverstone <dsilvers at digital-scurf.org>
# date: Fri 2006-11-10 19:30:26.000000000 +0000

=== added file bzrlib/tests/blackbox/test_remove_tree.py // file-id:test_remove
... _tree.py-20061110192919-5j3xjciiaqbs2dvo-1
--- /dev/null
+++ bzrlib/tests/blackbox/test_remove_tree.py
@@ -0,0 +1,81 @@
+# Copyright (C) 2005 Canonical Ltd
+# -*- coding: utf-8 -*-
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+"""Black-box tests for bzr remove-tree.
+"""
+
+import os
+
+from bzrlib.tests.blackbox import ExternalBase
+
+class TestRemoveTree(ExternalBase):
+
+    def _present(self, f):
+        self.assertEquals(os.path.exists(f), True)
+
+    def _absent(self, f):
+        self.assertEquals(os.path.exists(f), False)
+
+
+    def test_remove_tree(self):
+
+        def bzr(*args, **kwargs):
+            return self.run_bzr(*args, **kwargs)[0]
+
+        os.mkdir('branch1')
+        os.chdir('branch1')
+        bzr('init')
+        f=open('foo','wb')
+        f.write("foo\n")
+        f.close()
+        bzr('add', 'foo')
+
+        bzr('commit', '-m', '1')
+
+        os.chdir("..")
+
+        self._present("branch1/foo")
+        bzr('branch', 'branch1', 'branch2')
+        self._present("branch2/foo")
+        bzr('checkout', 'branch1', 'branch3')
+        self._present("branch3/foo")
+        bzr('checkout', '--lightweight', 'branch1', 'branch4')
+        self._present("branch4/foo")
+
+        # branch1 == branch
+        # branch2 == branch of branch1
+        # branch3 == checkout of branch1
+        # branch4 == lightweight checkout of branch1
+
+        # bzr remove-tree (CWD)
+        os.chdir("branch1")
+        bzr('remove-tree')
+        os.chdir("..")
+        self._absent("branch1/foo")
+
+        # bzr remove-tree (path)
+        bzr('remove-tree', 'branch2')
+        self._absent("branch2/foo")
+
+        # bzr remove-tree (checkout)
+        bzr('remove-tree', 'branch3')
+        self._absent("branch3/foo")
+
+        # bzr remove-tree (lightweight checkout, refuse)
+        bzr('remove-tree', 'branch4', retcode=3)
+        self._present("branch4/foo")

=== modified file NEWS
--- NEWS
+++ NEWS
@@ -2,6 +2,10 @@
 
   IMPROVEMENTS:
 
+    * New command ``bzr remove-tree`` allows the removal of the working
+      tree from a branch.
+      (Daniel Silverstone)
+
     * ``bzr export`` allows an optional branch parameter, to export a bzr
       tree from some other url. For example:
       ``bzr export bzr.tar.gz http://bazaar-vcs.org/bzr/bzr.dev``

=== modified file bzrlib/builtins.py
--- bzrlib/builtins.py
+++ bzrlib/builtins.py
@@ -213,6 +213,29 @@
                 self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
     
 
+class cmd_remove_tree(Command):
+    """Remove the working tree from a given branch/checkout.
+
+    Since a lightweight checkout is little more than a working tree
+    this will refuse to run against one.
+    """
+
+    takes_args = ['location?']
+
+    def run(self, location=u'.'):
+        d = bzrdir.BzrDir.open_containing(location)[0]
+        try:
+            working = d.open_workingtree()
+            working_path = working.bzrdir.root_transport.base
+            branch_path = working.branch.bzrdir.root_transport.base
+            if working_path != branch_path:
+                raise errors.BzrCommandError("Cannot remove working tree from lightweight checkout")
+        except (errors.NoWorkingTree, errors.NotLocalUrl):
+            raise errors.BzrCommandError("No working tree to remove")
+        
+        d.destroy_workingtree()
+        
+
 class cmd_revno(Command):
     """Show current revision number.
 

=== modified file bzrlib/tests/blackbox/__init__.py
--- bzrlib/tests/blackbox/__init__.py
+++ bzrlib/tests/blackbox/__init__.py
@@ -76,6 +76,7 @@
                      'bzrlib.tests.blackbox.test_remerge',
                      'bzrlib.tests.blackbox.test_remove',
                      'bzrlib.tests.blackbox.test_re_sign',
+                     'bzrlib.tests.blackbox.test_remove_tree',
                      'bzrlib.tests.blackbox.test_revert',
                      'bzrlib.tests.blackbox.test_revno',
                      'bzrlib.tests.blackbox.test_revision_history',

# revision id: dsilvers at digital-scurf.org-20061110193026-773bf69678268da9
# sha1: b94ebe90702265d5645706047fa8d327e9e5c8bc
# inventory sha1: ffbfaaddddd97b8efb36e456491cf0ff414bddf3
# parent ids:
#   pqm at pqm.ubuntu.com-20061110033744-421471bcb63181ca
# base id: pqm at pqm.ubuntu.com-20061110033744-421471bcb63181ca
# properties:
#   branch-nick: bzr.dev



More information about the bazaar mailing list