1 # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc.
2 # Gianluca Montecchi <gian@grys.it>
3 # W. Trevor King <wking@drexel.edu>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 class Init (libbe.command.Command):
27 """Create an on-disk bug repository
30 >>> import libbe.storage.vcs
31 >>> import libbe.storage.vcs.base
32 >>> import libbe.util.utility
33 >>> io = libbe.command.StringInputOutput()
34 >>> io.stdout = sys.stdout
35 >>> ui = libbe.command.UserInterface(io=io)
38 >>> dir = libbe.util.utility.Dir()
39 >>> vcs = libbe.storage.vcs.vcs_by_name('None')
40 >>> vcs.repo = dir.path
43 ... except libbe.storage.ConnectionError:
46 >>> ui.storage_callbacks.set_unconnected_storage(vcs)
48 No revision control detected.
49 BE repository initialized.
50 >>> bd = libbe.bugdir.BugDir(vcs)
55 >>> dir = libbe.util.utility.Dir()
56 >>> vcs = libbe.storage.vcs.installed_vcs()
57 >>> vcs.repo = dir.path
58 >>> vcs._vcs_init(vcs.repo)
59 >>> ui.storage_callbacks.set_unconnected_storage(vcs)
60 >>> if vcs.name in libbe.storage.vcs.base.VCS_ORDER:
61 ... ui.run(cmd) # doctest: +ELLIPSIS
65 ... print 'Using ... for revision control.\\nDirectory initialized.'
66 Using ... for revision control.
67 BE repository initialized.
74 def __init__(self, *args, **kwargs):
75 libbe.command.Command.__init__(self, *args, **kwargs)
77 def _run(self, **params):
78 storage = self._get_unconnected_storage()
79 if not os.path.isdir(storage.repo):
80 raise libbe.command.UserError(
81 'No such directory: %s' % storage.repo)
84 raise libbe.command.UserError(
85 'Directory already initialized: %s' % storage.repo)
86 except libbe.storage.ConnectionError:
90 bd = libbe.bugdir.BugDir(storage, from_storage=False)
92 if bd.storage.name is not 'None':
93 print >> self.stdout, \
94 'Using %s for revision control.' % storage.name
96 print >> self.stdout, 'No revision control detected.'
97 print >> self.stdout, 'BE repository initialized.'
101 This command initializes Bugs Everywhere support for the specified directory
102 and all its subdirectories. It will auto-detect any supported revision control
103 system. You can use "be set vcs_name" to change the vcs being used.
105 The directory defaults to your current working directory, but you can
106 change that by passing the --repo option to be
107 $ be --repo path/to/new/bug/root init
109 When initialized in a version-controlled directory, BE sinks to the
110 version-control root. In that case, the BE repository will be created
111 under that directory, rather than the current directory or the one
112 passed in --repo. Consider the following tree, versioned in Git.
118 ~$ be --repo ./projectX/src init
119 will create the BE repository rooted in projectX: