1 # Copyright (C) 2005-2011 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Gianluca Montecchi <gian@grys.it>
3 # W. Trevor King <wking@drexel.edu>
5 # This file is part of Bugs Everywhere.
7 # Bugs Everywhere is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation, either version 2 of the License, or (at your
10 # option) any later version.
12 # Bugs Everywhere is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
27 class Init (libbe.command.Command):
28 """Create an on-disk bug repository
31 >>> import libbe.storage.vcs
32 >>> import libbe.storage.vcs.base
33 >>> import libbe.util.utility
34 >>> io = libbe.command.StringInputOutput()
35 >>> io.stdout = sys.stdout
36 >>> ui = libbe.command.UserInterface(io=io)
39 >>> dir = libbe.util.utility.Dir()
40 >>> vcs = libbe.storage.vcs.vcs_by_name('None')
41 >>> vcs.repo = dir.path
44 ... except libbe.storage.ConnectionError:
47 >>> ui.storage_callbacks.set_unconnected_storage(vcs)
49 No revision control detected.
50 BE repository initialized.
51 >>> bd = libbe.bugdir.BugDir(vcs)
54 >>> bugdir = libbe.bugdir.BugDir(vcs, from_storage=True)
59 >>> dir = libbe.util.utility.Dir()
60 >>> vcs = libbe.storage.vcs.installed_vcs()
61 >>> vcs.repo = dir.path
62 >>> vcs._vcs_init(vcs.repo)
63 >>> ui.storage_callbacks.set_unconnected_storage(vcs)
64 >>> if vcs.name in libbe.storage.vcs.base.VCS_ORDER:
65 ... ui.run(cmd) # doctest: +ELLIPSIS
69 ... print 'Using ... for revision control.\\nDirectory initialized.'
70 Using ... for revision control.
71 BE repository initialized.
74 >>> bugdir = libbe.bugdir.BugDir(vcs, from_storage=True)
81 def __init__(self, *args, **kwargs):
82 libbe.command.Command.__init__(self, *args, **kwargs)
84 def _run(self, **params):
85 storage = self._get_unconnected_storage()
86 if not os.path.isdir(storage.repo):
87 raise libbe.command.UserError(
88 'No such directory: %s' % storage.repo)
91 raise libbe.command.UserError(
92 'Directory already initialized: %s' % storage.repo)
93 except libbe.storage.ConnectionError:
97 self.ui.storage_callbacks.set_storage(storage)
98 bd = libbe.bugdir.BugDir(storage, from_storage=False)
99 self.ui.storage_callbacks.set_bugdir(bd)
100 if bd.storage.name is not 'None':
101 print >> self.stdout, \
102 'Using %s for revision control.' % storage.name
104 print >> self.stdout, 'No revision control detected.'
105 print >> self.stdout, 'BE repository initialized.'
107 def _long_help(self):
109 This command initializes Bugs Everywhere support for the specified directory
110 and all its subdirectories. It will auto-detect any supported revision control
111 system. You can use "be set vcs_name" to change the vcs being used.
113 The directory defaults to your current working directory, but you can
114 change that by passing the --repo option to be
115 $ be --repo path/to/new/bug/root init
117 When initialized in a version-controlled directory, BE sinks to the
118 version-control root. In that case, the BE repository will be created
119 under that directory, rather than the current directory or the one
120 passed in --repo. Consider the following tree, versioned in Git.
126 ~$ be --repo ./projectX/src init
127 will create the BE repository rooted in projectX: