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