115
113
## TODO: Perhaps make UUIDs predictable in test mode to make it easier
116
114
## to compare output?
121
######################################################################
116
## TODO: Some kind of global code to generate the right Branch object
117
## to work on. Almost, but not quite all, commands need one, and it
118
## can be taken either from their parameters or their working
121
## TODO: rename command, needed soon: check destination doesn't exist
122
## either in working copy or tree; move working copy; update
123
## inventory; write out
125
## TODO: move command; check destination is a directory and will not
128
## TODO: command to show renames, one per line, as to->from
125
133
def cmd_status(all=False):
141
149
Branch('.').get_revision(revision_id).write_xml(sys.stdout)
144
def cmd_get_inventory(inventory_id):
145
"""Return inventory in XML by hash"""
146
Branch('.').get_inventory(inventory_hash).write_xml(sys.stdout)
149
def cmd_get_revision_inventory(revision_id):
150
"""Output inventory for a revision."""
152
b.get_revision_inventory(revision_id).write_xml(sys.stdout)
155
152
def cmd_get_file_text(text_id):
156
153
"""Get contents of a file by hash."""
157
154
sf = Branch('.').text_store[text_id]
168
165
print Branch('.').revno()
171
169
def cmd_add(file_list, verbose=False):
172
"""Add specified files.
170
"""Add specified files or directories.
172
In non-recursive mode, all the named items are added, regardless
173
of whether they were previously ignored. A warning is given if
174
any of the named files are already versioned.
176
In recursive mode (the default), files are treated the same way
177
but the behaviour for directories is different. Directories that
178
are already versioned do not give a warning. All directories,
179
whether already versioned or not, are searched for files or
180
subdirectories that are neither versioned or ignored, and these
181
are added. This search proceeds recursively into versioned
184
Therefore simply saying 'bzr add .' will version all files that
185
are currently unknown.
188
bzrlib.add.smart_add(file_list, verbose)
192
b = Branch(file_list[0], find_root=True)
193
b.add([b.relpath(f) for f in file_list], verbose=verbose)
174
Fails if the files are already added.
176
Branch('.').add(file_list, verbose=verbose)
197
def cmd_relpath(filename):
198
print Branch(filename).relpath(filename)
179
201
def cmd_inventory(revision=None):
196
218
print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
197
print 'revision number:', b.revno()
220
def plural(n, base='', pl=None):
199
228
count_version_dirs = 0
212
241
('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
214
243
print ' %5d %s' % (count_status[fs], name)
215
print ' %5d versioned subdirectories' % count_version_dirs
244
print ' %5d versioned subdirector%s' % (count_version_dirs,
245
plural(count_version_dirs, 'y', 'ies'))
248
print 'branch history:'
249
history = b.revision_history()
251
print ' %5d revision%s' % (revno, plural(revno))
254
committers.add(b.get_revision(rev).committer)
255
print ' %5d committer%s' % (len(committers), plural(len(committers)))
257
firstrev = b.get_revision(history[0])
258
age = int((time.time() - firstrev.timestamp) / 3600 / 24)
259
print ' %5d day%s old' % (age, plural(age))
260
print ' first revision: %s' % format_date(firstrev.timestamp,
263
lastrev = b.get_revision(history[-1])
264
print ' latest revision: %s' % format_date(lastrev.timestamp,
219
270
def cmd_remove(file_list, verbose=False):
220
Branch('.').remove(file_list, verbose=verbose)
271
b = Branch(file_list[0])
272
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
224
276
def cmd_file_id(filename):
225
i = Branch('.').read_working_inventory().path2id(filename)
278
i = b.inventory.path2id(b.relpath(filename))
227
280
bailout("%s is not a versioned file" % filename)
398
def cmd_root(filename=None):
399
"""Print the branch root."""
400
print bzrlib.branch.find_branch_root(filename)
345
403
def cmd_log(timezone='original'):
346
404
"""Show log of this branch.
420
def cmd_commit(message, verbose=False):
478
def cmd_commit(message=None, verbose=False):
480
bailout("please specify a commit message")
421
481
Branch('.').commit(message, verbose=verbose)
454
514
print bzrlib.branch._gen_revision_id(time.time())
458
"""Run internal doctest suite"""
517
def cmd_selftest(verbose=False):
518
"""Run internal test suite"""
459
519
## -v, if present, is seen by doctest; the argument is just here
460
520
## so our parser doesn't complain
462
522
## TODO: --verbose option
524
failures, tests = 0, 0
464
import bzr, doctest, bzrlib.store
526
import doctest, bzrlib.store, bzrlib.tests
465
527
bzrlib.trace.verbose = False
467
doctest.testmod(bzrlib.store)
468
doctest.testmod(bzrlib.inventory)
469
doctest.testmod(bzrlib.branch)
470
doctest.testmod(bzrlib.osutils)
471
doctest.testmod(bzrlib.tree)
473
# more strenuous tests;
475
doctest.testmod(bzrlib.tests)
529
for m in bzrlib.store, bzrlib.inventory, bzrlib.branch, bzrlib.osutils, \
530
bzrlib.tree, bzrlib.tests, bzrlib.commands, bzrlib.add:
531
mf, mt = doctest.testmod(m)
534
print '%-40s %3d tests' % (m.__name__, mt),
536
print '%3d FAILED!' % mf
540
print '%-40s %3d tests' % ('total', tests),
542
print '%3d FAILED!' % failures
549
cmd_doctest = cmd_selftest
478
552
######################################################################
565
641
lookup table, something about the available options, what optargs
566
642
they take, and which commands will accept them.
568
>>> parse_args('bzr --help'.split())
644
>>> parse_args('--help'.split())
569
645
([], {'help': True})
570
>>> parse_args('bzr --version'.split())
646
>>> parse_args('--version'.split())
571
647
([], {'version': True})
572
>>> parse_args('bzr status --all'.split())
648
>>> parse_args('status --all'.split())
573
649
(['status'], {'all': True})
574
>>> parse_args('bzr commit --message=biter'.split())
650
>>> parse_args('commit --message=biter'.split())
575
651
(['commit'], {'message': u'biter'})
676
754
logging and error handling.
679
args, opts = parse_args(argv)
757
args, opts = parse_args(argv[1:])
680
758
if 'help' in opts:
681
759
# TODO: pass down other arguments in case they asked for
682
760
# help on a command name?
719
797
## TODO: If the arguments are wrong, give a usage message rather
720
798
## than just a backtrace.
800
bzrlib.trace.create_tracefile(argv)
723
t = bzrlib.trace._tracefile
724
t.write('-' * 60 + '\n')
725
t.write('bzr invoked at %s\n' % format_date(time.time()))
726
t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.gethostname()))
727
t.write(' arguments: %r\n' % argv)
729
starttime = os.times()[4]
732
t.write(' platform: %s\n' % platform.platform())
733
t.write(' python: %s\n' % platform.python_version())
735
803
ret = run_bzr(argv)
738
mutter("finished, %.3fu/%.3fs cpu, %.3fu/%.3fs cum"
740
mutter(" %.3f elapsed" % (times[4] - starttime))
743
805
except BzrError, e:
744
806
log_error('bzr: error: ' + e.args[0] + '\n')