Rev 6357: (jelmer) Add -p option to 'bzr mkdir'. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Mon Dec 12 13:05:25 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6357 [merge]
revision-id: pqm at pqm.ubuntu.com-20111212130524-l9s3fwxxy1pujx7t
parent: pqm at pqm.ubuntu.com-20111212124019-h3252w4zq8s89k8c
parent: jelmer at samba.org-20111211023143-ocq0bfsp4j6cvt6x
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-12-12 13:05:24 +0000
message:
  (jelmer) Add -p option to 'bzr mkdir'. (Jelmer Vernooij)
added:
  bzrlib/tests/blackbox/test_mkdir.py test_mkdir.py-20111210210033-4ydo5voarpgjwkj0-1
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2011-11-30 20:06:59 +0000
+++ b/bzrlib/builtins.py	2011-12-11 02:31:43 +0000
@@ -753,20 +753,40 @@
     """
 
     takes_args = ['dir+']
+    takes_options = [
+        Option(
+            'parents',
+            help='No error if existing, make parent directories as needed.',
+            short_name='p'
+            )
+        ]
     encoding_type = 'replace'
 
-    def run(self, dir_list):
-        for d in dir_list:
-            wt, dd = WorkingTree.open_containing(d)
-            base = os.path.dirname(dd)
-            id = wt.path2id(base)
-            if id != None:
-                os.mkdir(d)
-                wt.add([dd])
-                if not is_quiet():
-                    self.outf.write(gettext('added %s\n') % d)
+    @classmethod
+    def add_file_with_parents(cls, wt, relpath):
+        if wt.path2id(relpath) is not None:
+            return
+        cls.add_file_with_parents(wt, osutils.dirname(relpath))
+        wt.add([relpath])
+
+    @classmethod
+    def add_file_single(cls, wt, relpath):
+        wt.add([relpath])
+
+    def run(self, dir_list, parents=False):
+        if parents:
+            add_file = self.add_file_with_parents
+        else:
+            add_file = self.add_file_single
+        for dir in dir_list:
+            wt, relpath = WorkingTree.open_containing(dir)
+            if parents:
+                os.makedirs(dir)
             else:
-                raise errors.NotVersionedError(path=base)
+                os.mkdir(dir)
+            add_file(wt, relpath)
+            if not is_quiet():
+                self.outf.write(gettext('added %s\n') % dir)
 
 
 class cmd_relpath(Command):

=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py	2011-09-27 12:13:53 +0000
+++ b/bzrlib/tests/blackbox/__init__.py	2011-12-10 21:00:34 +0000
@@ -85,6 +85,7 @@
                      'test_merge',
                      'test_merge_directive',
                      'test_missing',
+                     'test_mkdir',
                      'test_modified',
                      'test_mv',
                      'test_nick',

=== added file 'bzrlib/tests/blackbox/test_mkdir.py'
--- a/bzrlib/tests/blackbox/test_mkdir.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/blackbox/test_mkdir.py	2011-12-10 21:21:31 +0000
@@ -0,0 +1,48 @@
+# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+"""Black-box tests for bzr mkdir.
+"""
+
+import os
+from bzrlib import tests
+
+
+class TestMkdir(tests.TestCaseWithTransport):
+
+    def test_mkdir(self):
+        tree = self.make_branch_and_tree('.')
+        self.run_bzr(['mkdir', 'somedir'])
+
+        self.assertEquals(tree.kind(tree.path2id('somedir')), "directory")
+
+    def test_mkdir_multi(self):
+        tree = self.make_branch_and_tree('.')
+        self.run_bzr(['mkdir', 'somedir', 'anotherdir'])
+        self.assertEquals(tree.kind(tree.path2id('somedir')), "directory")
+        self.assertEquals(tree.kind(tree.path2id('anotherdir')), "directory")
+
+    def test_mkdir_parents(self):
+        tree = self.make_branch_and_tree('.')
+        self.run_bzr(['mkdir', '-p', 'somedir/foo'])
+        self.assertEquals(tree.kind(tree.path2id('somedir/foo')), "directory")
+
+    def test_mkdir_parents_with_unversioned_parent(self):
+        tree = self.make_branch_and_tree('.')
+        os.mkdir('somedir')
+        self.run_bzr(['mkdir', '-p', 'somedir/foo'])
+        self.assertEquals(tree.kind(tree.path2id('somedir/foo')), "directory")

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-12-12 12:09:50 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-12-12 13:05:24 +0000
@@ -20,6 +20,10 @@
 
 .. New commands, options, etc that users may wish to try out.
 
+* "bzr mkdir" now includes -p (--parents) option for recursively adding
+  parent directories.
+  (Jared Hance, Jelmer Vernooij, #253529)
+
 Improvements
 ************
 




More information about the bazaar-commits mailing list