113
115
## TODO: Perhaps make UUIDs predictable in test mode to make it easier
114
116
## to compare output?
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
121
######################################################################
133
125
def cmd_status(all=False):
149
141
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)
152
155
def cmd_get_file_text(text_id):
153
156
"""Get contents of a file by hash."""
154
157
sf = Branch('.').text_store[text_id]
165
168
print Branch('.').revno()
169
171
def cmd_add(file_list, verbose=False):
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.
172
"""Add specified files.
174
Fails if the files are already added.
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)
197
def cmd_relpath(filename):
198
print Branch(filename).relpath(filename)
176
Branch('.').add(file_list, verbose=verbose)
201
179
def cmd_inventory(revision=None):
257
235
firstrev = b.get_revision(history[0])
258
236
age = int((time.time() - firstrev.timestamp) / 3600 / 24)
259
237
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,
270
241
def cmd_remove(file_list, verbose=False):
271
b = Branch(file_list[0])
272
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
242
Branch('.').remove(file_list, verbose=verbose)
276
246
def cmd_file_id(filename):
278
i = b.inventory.path2id(b.relpath(filename))
247
i = Branch('.').read_working_inventory().path2id(filename)
280
249
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)
403
367
def cmd_log(timezone='original'):
404
368
"""Show log of this branch.
478
def cmd_commit(message=None, verbose=False):
480
bailout("please specify a commit message")
442
def cmd_commit(message, verbose=False):
481
443
Branch('.').commit(message, verbose=verbose)
514
476
print bzrlib.branch._gen_revision_id(time.time())
517
def cmd_selftest(verbose=False):
518
"""Run internal test suite"""
480
"""Run internal doctest suite"""
519
481
## -v, if present, is seen by doctest; the argument is just here
520
482
## so our parser doesn't complain
522
484
## TODO: --verbose option
524
failures, tests = 0, 0
526
import doctest, bzrlib.store, bzrlib.tests
486
import bzr, doctest, bzrlib.store
527
487
bzrlib.trace.verbose = False
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
489
doctest.testmod(bzrlib.store)
490
doctest.testmod(bzrlib.inventory)
491
doctest.testmod(bzrlib.branch)
492
doctest.testmod(bzrlib.osutils)
493
doctest.testmod(bzrlib.tree)
495
# more strenuous tests;
497
doctest.testmod(bzrlib.tests)
552
500
######################################################################
641
587
lookup table, something about the available options, what optargs
642
588
they take, and which commands will accept them.
644
>>> parse_args('--help'.split())
590
>>> parse_args('bzr --help'.split())
645
591
([], {'help': True})
646
>>> parse_args('--version'.split())
592
>>> parse_args('bzr --version'.split())
647
593
([], {'version': True})
648
>>> parse_args('status --all'.split())
594
>>> parse_args('bzr status --all'.split())
649
595
(['status'], {'all': True})
650
>>> parse_args('commit --message=biter'.split())
596
>>> parse_args('bzr commit --message=biter'.split())
651
597
(['commit'], {'message': u'biter'})
754
698
logging and error handling.
757
args, opts = parse_args(argv[1:])
701
args, opts = parse_args(argv)
758
702
if 'help' in opts:
759
703
# TODO: pass down other arguments in case they asked for
760
704
# help on a command name?
797
741
## TODO: If the arguments are wrong, give a usage message rather
798
742
## than just a backtrace.
800
bzrlib.trace.create_tracefile(argv)
745
t = bzrlib.trace._tracefile
746
t.write('-' * 60 + '\n')
747
t.write('bzr invoked at %s\n' % format_date(time.time()))
748
t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.gethostname()))
749
t.write(' arguments: %r\n' % argv)
751
starttime = os.times()[4]
754
t.write(' platform: %s\n' % platform.platform())
755
t.write(' python: %s\n' % platform.python_version())
803
757
ret = run_bzr(argv)
760
mutter("finished, %.3fu/%.3fs cpu, %.3fu/%.3fs cum"
762
mutter(" %.3f elapsed" % (times[4] - starttime))
805
765
except BzrError, e:
806
766
log_error('bzr: error: ' + e.args[0] + '\n')