[MERGE][Bug #105432] how to create a working tree? add "create-tree" alias to "checkout"

Daniel Watkins D.M.Watkins at warwick.ac.uk
Sat Aug 25 15:40:07 BST 2007


Attached is a bundle which adds a 'create-tree' command to bzr.  This
takes a location (defaulting to the current directory) and attempts to
create a working tree there.

It has tests to ensure that it gives the correct error if there is
already a working tree and that it will create a working tree both in
the current directory and given a path as appropriate.


Regards,
-- 
Daniel Watkins (Odd_Bloke) <D.M.Watkins at warwick.ac.uk>
University of Warwick Christian Focus President
University of Warwick Computing Society WUGLUG Liaison Officer
-------------- next part --------------
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: d.m.watkins at warwick.ac.uk-20070825143618-\
#   exybmqq7c5i7ozgy
# target_branch: file:///home/daniel/devel/bzr/bzr.dev/
# testament_sha1: ae6c1080ec7f9c9ae5300b9033ac8e151e1e4230
# timestamp: 2007-08-25 16:36:46 +0200
# base_revision_id: pqm at pqm.ubuntu.com-20070824133750-r25v5g25g1flggy6
# 
# Begin patch
=== added file 'bzrlib/tests/blackbox/test_create_tree.py'
--- bzrlib/tests/blackbox/test_create_tree.py	1970-01-01 00:00:00 +0000
+++ bzrlib/tests/blackbox/test_create_tree.py	2007-08-25 14:35:17 +0000
@@ -0,0 +1,70 @@
+# Copyright (C) 2005, 2006 Canonical Ltd
+#
+# 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
+
+"""Tests for the 'create-tree' CLI command."""
+
+import os
+
+from bzrlib import (
+    bzrdir,
+    errors,
+    )
+from bzrlib.tests.blackbox import ExternalBase
+
+class TestCreateTree(ExternalBase):
+
+    def create_treeless_branch(self):
+        os.mkdir('treeless-branch')
+        branch = bzrdir.BzrDir.create_branch_convenience(
+            'treeless-branch',
+            force_new_tree=False,
+            format=bzrdir.BzrDirMetaFormat1())
+        # check no tree was created
+        self.assertRaises(errors.NoWorkingTree, branch.bzrdir.open_workingtree)
+        return branch
+
+    def test_create_tree_in_current_directory(self):
+        branch = self.create_treeless_branch()
+        os.chdir('treeless-branch')
+
+        # doing a 'bzr create-tree' in the directory of a branch with no tree
+        # will reconsistute the tree.
+        out, err = self.run_bzr('create-tree')
+        self.assertEqual(out, "Working tree created.\n")
+
+        # we should have a tree now
+        branch.bzrdir.open_workingtree()
+
+        # with no diff
+        out, err = self.run_bzr('diff')
+        self.assertEqual(out, '')
+
+    def test_create_tree_with_path(self):
+        branch = self.create_treeless_branch()
+        out, err = self.run_bzr('create-tree treeless-branch')
+        self.assertEqual(out, "Working tree created.\n")
+
+        # we should have a tree now
+        branch.bzrdir.open_workingtree()
+
+        # with no diff
+        out, err = self.run_bzr('diff treeless-branch')
+        self.assertEqual(out, '')
+
+    def test_create_existant_tree(self):
+        self.make_branch_and_tree('.')
+        self.run_bzr_error(["A working tree already exists for this branch."],
+                           ['create-tree'])

=== modified file 'NEWS'
--- NEWS	2007-08-24 13:02:26 +0000
+++ NEWS	2007-08-25 14:36:18 +0000
@@ -49,6 +49,9 @@
 
     * Documentation updates (Martin Albisetti)
 
+    * ``create-tree`` has been created, which creates a working tree on a
+      branch without one.  (Daniel Watkins, #105432)
+
   API BREAKS:
 
    * ``Branch.append_revision`` is removed altogether; please use 

=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py	2007-08-21 01:32:29 +0000
+++ bzrlib/builtins.py	2007-08-25 14:35:36 +0000
@@ -962,6 +962,25 @@
         source.create_checkout(to_location, revision_id, lightweight)
 
 
+class cmd_create_tree(Command):
+    """Creates a tree where one does not exist.
+    """
+
+    takes_args = ['branch_location?']
+
+    def run(self, branch_location=None):
+        if branch_location is None:
+            branch_location = osutils.getcwd()
+        source = Branch.open(branch_location)
+        try:
+            source.bzrdir.open_workingtree()
+            raise errors.BzrCommandError("A working tree already exists for"
+                                         " this branch.")
+        except errors.NoWorkingTree:
+            source.bzrdir.create_workingtree()
+            print "Working tree created."
+
+
 class cmd_renames(Command):
     """Show list of renamed files.
     """

=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- bzrlib/tests/blackbox/__init__.py	2007-08-16 18:23:13 +0000
+++ bzrlib/tests/blackbox/__init__.py	2007-08-25 14:35:17 +0000
@@ -57,6 +57,7 @@
                      'bzrlib.tests.blackbox.test_command_encoding',
                      'bzrlib.tests.blackbox.test_commit',
                      'bzrlib.tests.blackbox.test_conflicts',
+                     'bzrlib.tests.blackbox.test_create_tree',
                      'bzrlib.tests.blackbox.test_debug',
                      'bzrlib.tests.blackbox.test_diff',
                      'bzrlib.tests.blackbox.test_exceptions',

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWY27QVAABp//gFRQIIBb9///
/+ferv////BgDO75lye++4UAAANvhLN121rV2VMq0zpY3bWLWgSSINU2ptJpp6mxNNJonqaGjTEa
MTE0ep6mnqaaGmIDSRqbUzU0epPIAExBkwAAABGQw0gwiaozaoNADQaaAADIGIAAAAACREmgjUaZ
T9Khto0mnqnk0m0mnqYg9NT1HlADQaAEUkBGTQ0Ak02lPU9qbTTVNPU2pp5T1APUD1AAAJIgIATQ
IaDRGjU9UNhTahp6gD1PUaaA0PUlRGwkhlCe34O0NEyN2qwflsfmRM1TZ/xtmXwP6O65/dvY3c+n
dr0ZuXSiX92ULUyLTSRDbv4CEfjSFhGBJBshhbZVv9+WBf4J7N5xQXpMguTLc+/6mlp00U0KTJGF
BnnHjTg8lba5Z5sQc7UAIiJCY1626vw2LsktTy2vDKSUz4kuxUpkMwzDN3SdoEI1KqInOfJXO8kp
uywjGGwsSvrihSSBLDBuXWMgZ9E/HwZKaIaH3UN/JWdC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bJxpaW+EQxM8ZAaZPSQM4m+CA
8LHkDHMyJ95I5VxXhhKBYsRvprXTp8SqqIbzU5MiHEO9z6Xu+SEPeD2zou/HiYbhkaqm+AZ5SlFI
aLS9rQ+K6TkuPHgIuHQKZcmR5QsUrkWMojdIqIcaLA+iHKpASSLrQsxoXqezLOnGFOJA85bp1mN0
6AlyBUykMpMMTNbJ6RvKa0NebxyJnHC3L3MI+mFP/F3JFOFCQjbtBUA=
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070825/2a703c8f/attachment.pgp 


More information about the bazaar mailing list