14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
# DO NOT change this to cStringIO - it results in control files
19
# FIXIT! (Only deal with byte streams OR unicode at any one layer.)
21
from StringIO import StringIO
26
from bzrlib import BZRDIR
27
from bzrlib.commands import Command, display_command
28
from bzrlib.branch import Branch
29
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
30
from bzrlib.errors import DivergedBranches, NoSuchFile, NoWorkingTree
31
from bzrlib.option import Option
32
from bzrlib.revisionspec import RevisionSpec
22
33
import bzrlib.trace
23
34
from bzrlib.trace import mutter, note, log_error, warning
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
25
from bzrlib.branch import find_branch
26
from bzrlib import BZRDIR
27
from bzrlib.commands import Command
35
from bzrlib.workingtree import WorkingTree
38
def branch_files(file_list, default_branch='.'):
40
Return a branch and list of branch-relative paths.
41
If supplied file_list is empty or None, the branch default will be used,
42
and returned file_list will match the original.
44
if file_list is None or len(file_list) == 0:
45
return Branch.open_containing(default_branch)[0], file_list
46
b = Branch.open_containing(file_list[0])[0]
48
# note that if this is a remote branch, we would want
49
# relpath against the transport. RBC 20051018
50
# Most branch ops can't meaningfully operate on files in remote branches;
51
# the above comment was in cmd_status. ADHB 20051026
52
tree = WorkingTree(b.base, b)
54
for filename in file_list:
56
new_list.append(tree.relpath(filename))
57
except NotBranchError:
58
raise BzrCommandError("%s is not in the same branch as %s" %
59
(filename, file_list[0]))
63
# TODO: Make sure no commands unconditionally use the working directory as a
64
# branch. If a filename argument is used, the first of them should be used to
65
# specify the branch. (Perhaps this can be factored out into some kind of
66
# Argument class, representing a file in a branch, where the first occurrence
30
69
class cmd_status(Command):
31
70
"""Display status summary.
62
101
directory is shown. Otherwise, only the status of the specified
63
102
files or directories is reported. If a directory is given, status
64
103
is reported for everything inside that directory.
105
If a revision argument is given, the status is calculated against
106
that revision, or between two revisions if two are provided.
66
109
# XXX: FIXME: bzr status should accept a -r option to show changes
67
110
# relative to a revision, or between revisions
112
# TODO: --no-recurse, --recurse options
69
114
takes_args = ['file*']
70
115
takes_options = ['all', 'show-ids']
71
116
aliases = ['st', 'stat']
73
def run(self, all=False, show_ids=False, file_list=None):
75
b = find_branch(file_list[0])
76
file_list = [b.relpath(x) for x in file_list]
77
# special case: only one path was given and it's the root
119
def run(self, all=False, show_ids=False, file_list=None, revision=None):
120
b, file_list = branch_files(file_list)
84
122
from bzrlib.status import show_status
85
123
show_status(b, show_unchanged=all, show_ids=show_ids,
86
specific_files=file_list)
124
specific_files=file_list, revision=revision)
89
127
class cmd_cat_revision(Command):
90
"""Write out metadata for a revision."""
128
"""Write out metadata for a revision.
130
The revision to print can either be specified by a specific
131
revision identifier, or you can use --revision.
93
takes_args = ['revision_id']
135
takes_args = ['revision_id?']
136
takes_options = ['revision']
95
def run(self, revision_id):
97
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
139
def run(self, revision_id=None, revision=None):
141
if revision_id is not None and revision is not None:
142
raise BzrCommandError('You can only supply one of revision_id or --revision')
143
if revision_id is None and revision is None:
144
raise BzrCommandError('You must supply either --revision or a revision_id')
145
b = Branch.open_containing('.')[0]
146
if revision_id is not None:
147
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
148
elif revision is not None:
151
raise BzrCommandError('You cannot specify a NULL revision.')
152
revno, rev_id = rev.in_history(b)
153
sys.stdout.write(b.get_revision_xml_file(rev_id).read())
100
156
class cmd_revno(Command):
101
157
"""Show current revision number.
103
159
This is equal to the number of revisions on this branch."""
105
print find_branch('.').revno()
162
print Branch.open_containing('.')[0].revno()
108
165
class cmd_revision_info(Command):
112
169
takes_args = ['revision_info*']
113
170
takes_options = ['revision']
114
def run(self, revision=None, revision_info_list=None):
115
from bzrlib.branch import find_branch
172
def run(self, revision=None, revision_info_list=[]):
118
175
if revision is not None:
119
176
revs.extend(revision)
120
177
if revision_info_list is not None:
121
revs.extend(revision_info_list)
178
for rev in revision_info_list:
179
revs.append(RevisionSpec(rev))
122
180
if len(revs) == 0:
123
181
raise BzrCommandError('You must supply a revision identifier')
183
b = Branch.open_containing('.')[0]
128
print '%4d %s' % b.get_revision_info(rev)
186
revinfo = rev.in_history(b)
187
if revinfo.revno is None:
188
print ' %s' % revinfo.rev_id
190
print '%4d %s' % (revinfo.revno, revinfo.rev_id)
131
193
class cmd_add(Command):
152
214
get added when you add a file in the directory.
154
216
takes_args = ['file*']
155
takes_options = ['verbose', 'no-recurse']
217
takes_options = ['no-recurse', 'quiet']
157
def run(self, file_list, verbose=False, no_recurse=False):
158
# verbose currently has no effect
159
from bzrlib.add import smart_add, add_reporter_print
160
smart_add(file_list, not no_recurse, add_reporter_print)
219
def run(self, file_list, no_recurse=False, quiet=False):
220
from bzrlib.add import smart_add, add_reporter_print, add_reporter_null
222
reporter = add_reporter_null
224
reporter = add_reporter_print
225
smart_add(file_list, not no_recurse, reporter)
164
228
class cmd_mkdir(Command):
184
248
takes_args = ['filename']
187
252
def run(self, filename):
188
print find_branch(filename).relpath(filename)
253
branch, relpath = Branch.open_containing(filename)
192
257
class cmd_inventory(Command):
193
258
"""Show inventory of the current working copy or a revision."""
194
259
takes_options = ['revision', 'show-ids']
196
262
def run(self, revision=None, show_ids=False):
199
inv = b.read_working_inventory()
263
b = Branch.open_containing('.')[0]
265
inv = b.working_tree().read_working_inventory()
201
267
if len(revision) > 1:
202
268
raise BzrCommandError('bzr inventory --revision takes'
203
269
' exactly one revision identifier')
204
inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
270
inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
206
272
for path, entry in inv.entries():
281
345
print "%s => %s" % (rel_names[0], rel_names[1])
286
348
class cmd_pull(Command):
287
349
"""Pull any changes from another branch into the current one.
289
If the location is omitted, the last-used location will be used.
290
Both the revision history and the working directory will be
351
If there is no default location set, the first pull will set it. After
352
that, you can omit the location to use the default. To change the
353
default, use --remember.
293
355
This command only works on branches that have not diverged. Branches are
294
356
considered diverged if both branches have had commits without first
295
357
pulling from the other.
297
359
If branches have diverged, you can use 'bzr merge' to pull the text changes
298
from one into the other.
360
from one into the other. Once one branch has merged, the other should
361
be able to pull it again.
363
If you want to forget your local changes and just update your branch to
364
match the remote one, use --overwrite.
366
takes_options = ['remember', 'overwrite']
300
367
takes_args = ['location?']
302
def run(self, location=None):
369
def run(self, location=None, remember=False, overwrite=False):
303
370
from bzrlib.merge import merge
305
371
from shutil import rmtree
308
br_to = find_branch('.')
374
br_to = Branch.open_containing('.')[0]
309
375
stored_loc = br_to.get_parent()
310
376
if location is None:
311
377
if stored_loc is None:
312
378
raise BzrCommandError("No pull location known or specified.")
314
print "Using last location: %s" % stored_loc
315
location = stored_loc
316
cache_root = tempfile.mkdtemp()
317
from bzrlib.branch import DivergedBranches
318
br_from = find_branch(location)
319
location = br_from.base
320
old_revno = br_to.revno()
322
from branch import find_cached_branch, DivergedBranches
323
br_from = find_cached_branch(location, cache_root)
324
location = br_from.base
325
old_revno = br_to.revno()
327
br_to.update_revisions(br_from)
328
except DivergedBranches:
329
raise BzrCommandError("These branches have diverged."
332
merge(('.', -1), ('.', old_revno), check_clean=False)
333
if location != stored_loc:
334
br_to.set_parent(location)
380
print "Using saved location: %s" % stored_loc
381
location = stored_loc
382
br_from = Branch.open(location)
384
br_to.working_tree().pull(br_from, overwrite)
385
except DivergedBranches:
386
raise BzrCommandError("These branches have diverged."
388
if br_to.get_parent() is None or remember:
389
br_to.set_parent(location)
392
class cmd_push(Command):
393
"""Push this branch into another branch.
395
The remote branch will not have its working tree populated because this
396
is both expensive, and may not be supported on the remote file system.
398
Some smart servers or protocols *may* put the working tree in place.
400
If there is no default push location set, the first push will set it.
401
After that, you can omit the location to use the default. To change the
402
default, use --remember.
404
This command only works on branches that have not diverged. Branches are
405
considered diverged if the branch being pushed to is not an older version
408
If branches have diverged, you can use 'bzr push --overwrite' to replace
409
the other branch completely.
411
If you want to ensure you have the different changes in the other branch,
412
do a merge (see bzr help merge) from the other branch, and commit that
413
before doing a 'push --overwrite'.
415
takes_options = ['remember', 'overwrite',
416
Option('create-prefix',
417
help='Create the path leading up to the branch '
418
'if it does not already exist')]
419
takes_args = ['location?']
421
def run(self, location=None, remember=False, overwrite=False,
422
create_prefix=False):
424
from shutil import rmtree
425
from bzrlib.transport import get_transport
427
br_from = Branch.open_containing('.')[0]
428
stored_loc = br_from.get_push_location()
430
if stored_loc is None:
431
raise BzrCommandError("No push location known or specified.")
433
print "Using saved location: %s" % stored_loc
434
location = stored_loc
436
br_to = Branch.open(location)
437
except NotBranchError:
439
transport = get_transport(location).clone('..')
440
if not create_prefix:
442
transport.mkdir(transport.relpath(location))
444
raise BzrCommandError("Parent directory of %s "
445
"does not exist." % location)
447
current = transport.base
448
needed = [(transport, transport.relpath(location))]
451
transport, relpath = needed[-1]
452
transport.mkdir(relpath)
455
new_transport = transport.clone('..')
456
needed.append((new_transport,
457
new_transport.relpath(transport.base)))
458
if new_transport.base == transport.base:
459
raise BzrCommandError("Could not creeate "
463
br_to = Branch.initialize(location)
465
br_to.pull(br_from, overwrite)
466
except DivergedBranches:
467
raise BzrCommandError("These branches have diverged."
468
" Try a merge then push with overwrite.")
469
if br_from.get_push_location() is None or remember:
470
br_from.set_push_location(location)
340
473
class cmd_branch(Command):
346
479
To retrieve the branch as of a particular revision, supply the --revision
347
480
parameter, as in "branch foo/bar -r 5".
482
--basis is to speed up branching from remote branches. When specified, it
483
copies all the file-contents, inventory and revision data from the basis
484
branch before copying anything from the remote branch.
349
486
takes_args = ['from_location', 'to_location?']
350
takes_options = ['revision']
487
takes_options = ['revision', 'basis']
351
488
aliases = ['get', 'clone']
353
def run(self, from_location, to_location=None, revision=None):
354
from bzrlib.branch import copy_branch, find_cached_branch
490
def run(self, from_location, to_location=None, revision=None, basis=None):
491
from bzrlib.clone import copy_branch
357
493
from shutil import rmtree
358
cache_root = tempfile.mkdtemp()
362
elif len(revision) > 1:
363
raise BzrCommandError(
364
'bzr branch --revision takes exactly 1 revision value')
366
br_from = find_cached_branch(from_location, cache_root)
368
if e.errno == errno.ENOENT:
369
raise BzrCommandError('Source location "%s" does not'
370
' exist.' % to_location)
496
elif len(revision) > 1:
497
raise BzrCommandError(
498
'bzr branch --revision takes exactly 1 revision value')
500
br_from = Branch.open(from_location)
502
if e.errno == errno.ENOENT:
503
raise BzrCommandError('Source location "%s" does not'
504
' exist.' % to_location)
509
if basis is not None:
510
basis_branch = Branch.open_containing(basis)[0]
513
if len(revision) == 1 and revision[0] is not None:
514
revision_id = revision[0].in_history(br_from)[1]
373
517
if to_location is None:
374
518
to_location = os.path.basename(from_location.rstrip("/\\"))
521
name = os.path.basename(to_location) + '\n'
376
523
os.mkdir(to_location)
377
524
except OSError, e:
387
copy_branch(br_from, to_location, revision[0])
534
copy_branch(br_from, to_location, revision_id, basis_branch)
388
535
except bzrlib.errors.NoSuchRevision:
389
536
rmtree(to_location)
390
msg = "The branch %s has no revision %d." % (from_location, revision[0])
391
raise BzrCommandError(msg)
537
msg = "The branch %s has no revision %s." % (from_location, revision[0])
538
raise BzrCommandError(msg)
539
except bzrlib.errors.UnlistableBranch:
541
msg = "The branch %s cannot be used as a --basis"
542
raise BzrCommandError(msg)
544
branch = Branch.open(to_location)
545
name = StringIO(name)
546
branch.put_controlfile('branch-name', name)
396
551
class cmd_renames(Command):
397
552
"""Show list of renamed files.
399
TODO: Option to show renames between two historical versions.
401
TODO: Only show renames under dir, rather than in the whole branch.
554
# TODO: Option to show renames between two historical versions.
556
# TODO: Only show renames under dir, rather than in the whole branch.
403
557
takes_args = ['dir?']
405
560
def run(self, dir='.'):
561
b = Branch.open_containing(dir)[0]
407
562
old_inv = b.basis_tree().inventory
408
new_inv = b.read_working_inventory()
563
new_inv = b.working_tree().read_working_inventory()
410
565
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
515
698
If files are listed, only the changes in those files are listed.
516
699
Otherwise, all changes for the tree are listed.
518
TODO: Allow diff across branches.
520
TODO: Option to use external diff command; could be GNU diff, wdiff,
523
TODO: Python difflib is not exactly the same as unidiff; should
524
either fix it up or prefer to use an external diff.
526
TODO: If a directory is given, diff everything under that.
528
TODO: Selected-file diff is inefficient and doesn't show you
531
TODO: This probably handles non-Unix newlines poorly.
706
# TODO: Allow diff across branches.
707
# TODO: Option to use external diff command; could be GNU diff, wdiff,
708
# or a graphical diff.
710
# TODO: Python difflib is not exactly the same as unidiff; should
711
# either fix it up or prefer to use an external diff.
713
# TODO: If a directory is given, diff everything under that.
715
# TODO: Selected-file diff is inefficient and doesn't show you
718
# TODO: This probably handles non-Unix newlines poorly.
539
720
takes_args = ['file*']
540
721
takes_options = ['revision', 'diff-options']
541
722
aliases = ['di', 'dif']
543
725
def run(self, revision=None, file_list=None, diff_options=None):
544
726
from bzrlib.diff import show_diff
547
b = find_branch(file_list[0])
548
file_list = [b.relpath(f) for f in file_list]
549
if file_list == ['']:
550
# just pointing to top-of-tree
728
b, file_list = branch_files(file_list)
555
729
if revision is not None:
556
730
if len(revision) == 1:
557
show_diff(b, revision[0], specific_files=file_list,
558
external_diff_options=diff_options)
731
return show_diff(b, revision[0], specific_files=file_list,
732
external_diff_options=diff_options)
559
733
elif len(revision) == 2:
560
show_diff(b, revision[0], specific_files=file_list,
561
external_diff_options=diff_options,
562
revision2=revision[1])
734
return show_diff(b, revision[0], specific_files=file_list,
735
external_diff_options=diff_options,
736
revision2=revision[1])
564
738
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
566
show_diff(b, None, specific_files=file_list,
567
external_diff_options=diff_options)
740
return show_diff(b, None, specific_files=file_list,
741
external_diff_options=diff_options)
572
744
class cmd_deleted(Command):
573
745
"""List files deleted in the working tree.
575
TODO: Show files deleted since a previous revision, or between two revisions.
747
# TODO: Show files deleted since a previous revision, or
748
# between two revisions.
749
# TODO: Much more efficient way to do this: read in new
750
# directories with readdir, rather than stating each one. Same
751
# level of effort but possibly much less IO. (Or possibly not,
752
# if the directories are very large...)
577
754
def run(self, show_ids=False):
755
b = Branch.open_containing('.')[0]
579
756
old = b.basis_tree()
580
757
new = b.working_tree()
582
## TODO: Much more efficient way to do this: read in new
583
## directories with readdir, rather than stating each one. Same
584
## level of effort but possibly much less IO. (Or possibly not,
585
## if the directories are very large...)
587
758
for path, ie in old.inventory.iter_entries():
588
759
if not new.has_id(ie.file_id):
642
816
To request a range of logs, you can use the command -r begin:end
643
817
-r revision requests a specific revision, -r :end or -r begin: are
646
--message allows you to give a regular expression, which will be evaluated
647
so that only matching entries will be displayed.
649
TODO: Make --revision support uuid: and hash: [future tag:] notation.
821
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
653
823
takes_args = ['filename?']
654
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
655
'long', 'message', 'short',]
824
takes_options = [Option('forward',
825
help='show from oldest to newest'),
826
'timezone', 'verbose',
827
'show-ids', 'revision',
828
Option('line', help='format with one line per revision'),
831
help='show revisions whose message matches this regexp',
833
Option('short', help='use moderately short format'),
657
836
def run(self, filename=None, timezone='original',
665
845
from bzrlib.log import log_formatter, show_log
847
assert message is None or isinstance(message, basestring), \
848
"invalid message argument %r" % message
668
849
direction = (forward and 'forward') or 'reverse'
671
b = find_branch(filename)
672
fp = b.relpath(filename)
674
file_id = b.read_working_inventory().path2id(fp)
852
b, fp = Branch.open_containing(filename)
855
inv = b.working_tree().read_working_inventory()
856
except NoWorkingTree:
857
inv = b.get_inventory(b.last_revision())
858
file_id = inv.path2id(fp)
676
860
file_id = None # points to branch root
862
b, relpath = Branch.open_containing('.')
681
865
if revision is None:
684
868
elif len(revision) == 1:
685
rev1 = rev2 = b.get_revision_info(revision[0])[0]
869
rev1 = rev2 = revision[0].in_history(b).revno
686
870
elif len(revision) == 2:
687
rev1 = b.get_revision_info(revision[0])[0]
688
rev2 = b.get_revision_info(revision[1])[0]
871
rev1 = revision[0].in_history(b).revno
872
rev2 = revision[1].in_history(b).revno
690
874
raise BzrCommandError('bzr log --revision takes one or two values.')
726
911
A more user-friendly interface is "bzr log FILE"."""
728
913
takes_args = ["filename"]
729
915
def run(self, filename):
730
b = find_branch(filename)
731
inv = b.read_working_inventory()
732
file_id = inv.path2id(b.relpath(filename))
916
b, relpath = Branch.open_containing(filename)[0]
917
inv = b.working_tree().read_working_inventory()
918
file_id = inv.path2id(relpath)
733
919
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
734
920
print "%6d %s" % (revno, what)
737
923
class cmd_ls(Command):
738
924
"""List files in a tree.
740
TODO: Take a revision or remote path and list that tree instead.
926
# TODO: Take a revision or remote path and list that tree instead.
743
def run(self, revision=None, verbose=False):
928
takes_options = ['verbose', 'revision',
929
Option('non-recursive',
930
help='don\'t recurse into sub-directories'),
932
help='Print all paths from the root of the branch.'),
933
Option('unknown', help='Print unknown files'),
934
Option('versioned', help='Print versioned files'),
935
Option('ignored', help='Print ignored files'),
937
Option('null', help='Null separate the files'),
940
def run(self, revision=None, verbose=False,
941
non_recursive=False, from_root=False,
942
unknown=False, versioned=False, ignored=False,
946
raise BzrCommandError('Cannot set both --verbose and --null')
947
all = not (unknown or versioned or ignored)
949
selection = {'I':ignored, '?':unknown, 'V':versioned}
951
b, relpath = Branch.open_containing('.')
745
956
if revision == None:
746
957
tree = b.working_tree()
748
tree = b.revision_tree(b.lookup_revision(revision))
750
for fp, fc, kind, fid in tree.list_files():
752
if kind == 'directory':
959
tree = b.revision_tree(revision[0].in_history(b).rev_id)
960
for fp, fc, kind, fid, entry in tree.list_files():
961
if fp.startswith(relpath):
962
fp = fp[len(relpath):]
963
if non_recursive and '/' in fp:
965
if not all and not selection[fc]:
968
kindch = entry.kind_character()
969
print '%-8s %s%s' % (fc, fp, kindch)
972
sys.stdout.write('\0')
759
print '%-8s %s%s' % (fc, fp, kindch)
765
979
class cmd_unknowns(Command):
766
980
"""List unknown files."""
768
983
from bzrlib.osutils import quotefn
769
for f in find_branch('.').unknowns():
984
for f in Branch.open_containing('.')[0].unknowns():
877
1096
takes_options = ['revision', 'format', 'root']
878
1097
def run(self, dest, revision=None, format=None, root=None):
1099
b = Branch.open_containing('.')[0]
881
1100
if revision is None:
882
rev_id = b.last_patch()
1101
rev_id = b.last_revision()
884
1103
if len(revision) != 1:
885
1104
raise BzrError('bzr export --revision takes exactly 1 argument')
886
revno, rev_id = b.get_revision_info(revision[0])
1105
rev_id = revision[0].in_history(b).rev_id
887
1106
t = b.revision_tree(rev_id)
888
root, ext = os.path.splitext(dest)
1107
arg_root, ext = os.path.splitext(os.path.basename(dest))
1108
if ext in ('.gz', '.bz2'):
1109
new_root, new_ext = os.path.splitext(arg_root)
1110
if new_ext == '.tar':
890
1116
if ext in (".tar",):
892
elif ext in (".gz", ".tgz"):
1118
elif ext in (".tar.gz", ".tgz"):
894
elif ext in (".bz2", ".tbz2"):
1120
elif ext in (".tar.bz2", ".tbz2"):
933
1161
A selected-file commit may fail in some cases where the committed
934
1162
tree would be invalid, such as trying to commit a file in a
935
1163
newly-added directory that is not itself committed.
937
TODO: Run hooks on tree to-be-committed, and after commit.
939
TODO: Strict commit that fails if there are unknown or deleted files.
1165
# TODO: Run hooks on tree to-be-committed, and after commit.
1167
# TODO: Strict commit that fails if there are deleted files.
1168
# (what does "deleted files" mean ??)
1170
# TODO: Give better message for -s, --summary, used by tla people
1172
# XXX: verbose currently does nothing
941
1174
takes_args = ['selected*']
942
takes_options = ['message', 'file', 'verbose', 'unchanged']
1175
takes_options = ['message', 'verbose',
1177
help='commit even if nothing has changed'),
1178
Option('file', type=str,
1180
help='file containing commit message'),
1182
help="refuse to commit if there are unknown "
1183
"files in the working tree."),
943
1185
aliases = ['ci', 'checkin']
945
# TODO: Give better message for -s, --summary, used by tla people
947
1187
def run(self, message=None, file=None, verbose=True, selected_list=None,
949
from bzrlib.errors import PointlessCommit
1188
unchanged=False, strict=False):
1189
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
950
1191
from bzrlib.msgeditor import edit_commit_message
951
1192
from bzrlib.status import show_status
952
1193
from cStringIO import StringIO
956
selected_list = [b.relpath(s) for s in selected_list]
958
if not message and not file:
1195
b, selected_list = branch_files(selected_list)
1196
if message is None and not file:
959
1197
catcher = StringIO()
960
1198
show_status(b, specific_files=selected_list,
961
1199
to_file=catcher)
962
1200
message = edit_commit_message(catcher.getvalue())
964
1202
if message is None:
965
1203
raise BzrCommandError("please specify a commit message"
966
1204
" with either --message or --file")
972
1210
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1213
raise BzrCommandError("empty commit message specified")
975
b.commit(message, verbose=verbose,
976
specific_files=selected_list,
977
allow_pointless=unchanged)
1216
b.commit(message, specific_files=selected_list,
1217
allow_pointless=unchanged, strict=strict)
978
1218
except PointlessCommit:
979
1219
# FIXME: This should really happen before the file is read in;
980
1220
# perhaps prepare the commit; get the message; then actually commit
981
1221
raise BzrCommandError("no changes to commit",
982
1222
["use --unchanged to commit anyhow"])
1223
except ConflictsInTree:
1224
raise BzrCommandError("Conflicts detected in working tree. "
1225
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1226
except StrictCommitFailed:
1227
raise BzrCommandError("Commit refused because there are unknown "
1228
"files in the working tree.")
985
1231
class cmd_check(Command):
1022
1268
The check command or bzr developers may sometimes advise you to run
1271
This version of this command upgrades from the full-text storage
1272
used by bzr 0.0.8 and earlier to the weave format (v5).
1025
1274
takes_args = ['dir?']
1027
1276
def run(self, dir='.'):
1028
1277
from bzrlib.upgrade import upgrade
1029
upgrade(find_branch(dir))
1033
1281
class cmd_whoami(Command):
1034
1282
"""Show bzr user id."""
1035
1283
takes_options = ['email']
1037
1286
def run(self, email=False):
1039
b = bzrlib.branch.find_branch('.')
1288
b = bzrlib.branch.Branch.open_containing('.')[0]
1289
config = bzrlib.config.BranchConfig(b)
1290
except NotBranchError:
1291
config = bzrlib.config.GlobalConfig()
1044
print bzrlib.osutils.user_email(b)
1294
print config.user_email()
1046
print bzrlib.osutils.username(b)
1296
print config.username()
1049
1299
class cmd_selftest(Command):
1050
"""Run internal test suite"""
1300
"""Run internal test suite.
1302
This creates temporary test directories in the working directory,
1303
but not existing data is affected. These directories are deleted
1304
if the tests pass, or left behind to help in debugging if they
1307
If arguments are given, they are regular expressions that say
1308
which tests should run.
1310
# TODO: --list should give a list of all available tests
1052
takes_options = ['verbose', 'pattern']
1053
def run(self, verbose=False, pattern=".*"):
1312
takes_args = ['testspecs*']
1313
takes_options = ['verbose',
1314
Option('one', help='stop when one test fails'),
1317
def run(self, testspecs_list=None, verbose=False, one=False):
1054
1318
import bzrlib.ui
1055
1319
from bzrlib.selftest import selftest
1056
1320
# we don't want progress meters from the tests to go to the
1087
1357
class cmd_version(Command):
1088
1358
"""Show version of bzr."""
1092
1363
class cmd_rocks(Command):
1093
1364
"""Statement of optimism."""
1096
1368
print "it sure does!"
1099
1371
class cmd_find_merge_base(Command):
1100
1372
"""Find and print a base revision for merging two branches.
1102
TODO: Options to specify revisions on either side, as if
1103
merging only part of the history.
1374
# TODO: Options to specify revisions on either side, as if
1375
# merging only part of the history.
1105
1376
takes_args = ['branch', 'other']
1108
1380
def run(self, branch, other):
1109
1381
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1111
branch1 = find_branch(branch)
1112
branch2 = find_branch(other)
1383
branch1 = Branch.open_containing(branch)[0]
1384
branch2 = Branch.open_containing(other)[0]
1114
1386
history_1 = branch1.revision_history()
1115
1387
history_2 = branch2.revision_history()
1117
last1 = branch1.last_patch()
1118
last2 = branch2.last_patch()
1389
last1 = branch1.last_revision()
1390
last2 = branch2.last_revision()
1120
1392
source = MultipleRevisionSources(branch1, branch2)
1164
1436
--force is given.
1166
1438
takes_args = ['branch?']
1167
takes_options = ['revision', 'force', 'merge-type']
1439
takes_options = ['revision', 'force', 'merge-type', 'reprocess',
1440
Option('show-base', help="Show base revision text in "
1169
def run(self, branch='.', revision=None, force=False,
1443
def run(self, branch=None, revision=None, force=False, merge_type=None,
1444
show_base=False, reprocess=False):
1171
1445
from bzrlib.merge import merge
1172
1446
from bzrlib.merge_core import ApplyMerge3
1173
1447
if merge_type is None:
1174
1448
merge_type = ApplyMerge3
1450
branch = Branch.open_containing('.')[0].get_parent()
1452
raise BzrCommandError("No merge location known or specified.")
1454
print "Using saved location: %s" % branch
1176
1455
if revision is None or len(revision) < 1:
1177
1456
base = [None, None]
1178
1457
other = [branch, -1]
1180
1459
if len(revision) == 1:
1181
other = [branch, revision[0]]
1182
1460
base = [None, None]
1461
other_branch = Branch.open_containing(branch)[0]
1462
revno = revision[0].in_history(other_branch).revno
1463
other = [branch, revno]
1184
1465
assert len(revision) == 2
1185
1466
if None in revision:
1186
1467
raise BzrCommandError(
1187
1468
"Merge doesn't permit that revision specifier.")
1188
base = [branch, revision[0]]
1189
other = [branch, revision[1]]
1469
b = Branch.open_containing(branch)[0]
1471
base = [branch, revision[0].in_history(b).revno]
1472
other = [branch, revision[1].in_history(b).revno]
1192
merge(other, base, check_clean=(not force), merge_type=merge_type)
1475
conflict_count = merge(other, base, check_clean=(not force),
1476
merge_type=merge_type, reprocess=reprocess,
1477
show_base=show_base)
1478
if conflict_count != 0:
1193
1482
except bzrlib.errors.AmbiguousBase, e:
1194
1483
m = ("sorry, bzr can't determine the right merge base yet\n"
1195
1484
"candidates are:\n "
1214
1503
def run(self, revision=None, no_backup=False, file_list=None):
1215
1504
from bzrlib.merge import merge
1216
from bzrlib.branch import Branch
1217
1505
from bzrlib.commands import parse_spec
1219
1507
if file_list is not None:
1220
1508
if len(file_list) == 0:
1221
1509
raise BzrCommandError("No files specified")
1222
1510
if revision is None:
1224
1512
elif len(revision) != 1:
1225
1513
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1226
merge(('.', revision[0]), parse_spec('.'),
1515
b, file_list = branch_files(file_list)
1516
revno = revision[0].in_history(b).revno
1517
merge(('.', revno), parse_spec('.'),
1227
1518
check_clean=False,
1228
1519
ignore_zero=True,
1229
1520
backup_files=not no_backup,
1230
1521
file_list=file_list)
1231
1522
if not file_list:
1232
Branch('.').set_pending_merges([])
1523
Branch.open_containing('.')[0].set_pending_merges([])
1235
1526
class cmd_assert_fail(Command):
1262
1554
aliases = ['s-c']
1265
1558
def run(self, context=None):
1266
1559
import shellcomplete
1267
1560
shellcomplete.shellcomplete(context)
1563
class cmd_fetch(Command):
1564
"""Copy in history from another branch but don't merge it.
1566
This is an internal method used for pull and merge."""
1568
takes_args = ['from_branch', 'to_branch']
1569
def run(self, from_branch, to_branch):
1570
from bzrlib.fetch import Fetcher
1571
from bzrlib.branch import Branch
1572
from_b = Branch.open(from_branch)
1573
to_b = Branch.open(to_branch)
1578
Fetcher(to_b, from_b)
1270
1585
class cmd_missing(Command):
1271
1586
"""What is missing in this branch relative to other branch.
1588
# TODO: rewrite this in terms of ancestry so that it shows only
1273
1591
takes_args = ['remote?']
1274
1592
aliases = ['mis', 'miss']
1275
1593
# We don't have to add quiet to the list, because
1276
1594
# unknown options are parsed as booleans
1277
1595
takes_options = ['verbose', 'quiet']
1279
1598
def run(self, remote=None, verbose=False, quiet=False):
1280
1599
from bzrlib.errors import BzrCommandError
1281
1600
from bzrlib.missing import show_missing
1320
1639
print '\t', d.split('\n')[0]
1642
class cmd_testament(Command):
1643
"""Show testament (signing-form) of a revision."""
1644
takes_options = ['revision', 'long']
1645
takes_args = ['branch?']
1647
def run(self, branch='.', revision=None, long=False):
1648
from bzrlib.testament import Testament
1649
b = Branch.open_containing(branch)[0]
1652
if revision is None:
1653
rev_id = b.last_revision()
1655
rev_id = revision[0].in_history(b).rev_id
1656
t = Testament.from_revision(b, rev_id)
1658
sys.stdout.writelines(t.as_text_lines())
1660
sys.stdout.write(t.as_short_text())
1665
class cmd_annotate(Command):
1666
"""Show the origin of each line in a file.
1668
This prints out the given file with an annotation on the left side
1669
indicating which revision, author and date introduced the change.
1671
If the origin is the same for a run of consecutive lines, it is
1672
shown only at the top, unless the --all option is given.
1674
# TODO: annotate directories; showing when each file was last changed
1675
# TODO: annotate a previous version of a file
1676
# TODO: if the working copy is modified, show annotations on that
1677
# with new uncommitted lines marked
1678
aliases = ['blame', 'praise']
1679
takes_args = ['filename']
1680
takes_options = [Option('all', help='show annotations on all lines'),
1681
Option('long', help='show date in annotations'),
1685
def run(self, filename, all=False, long=False):
1686
from bzrlib.annotate import annotate_file
1687
b, relpath = Branch.open_containing(filename)
1690
tree = WorkingTree(b.base, b)
1691
tree = b.revision_tree(b.last_revision())
1692
file_id = tree.inventory.path2id(relpath)
1693
file_version = tree.inventory[file_id].revision
1694
annotate_file(b, file_version, file_id, long, all, sys.stdout)
1699
class cmd_re_sign(Command):
1700
"""Create a digital signature for an existing revision."""
1701
# TODO be able to replace existing ones.
1703
hidden = True # is this right ?
1704
takes_args = ['revision_id?']
1705
takes_options = ['revision']
1707
def run(self, revision_id=None, revision=None):
1708
import bzrlib.config as config
1709
import bzrlib.gpg as gpg
1710
if revision_id is not None and revision is not None:
1711
raise BzrCommandError('You can only supply one of revision_id or --revision')
1712
if revision_id is None and revision is None:
1713
raise BzrCommandError('You must supply either --revision or a revision_id')
1714
b = Branch.open_containing('.')[0]
1715
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1716
if revision_id is not None:
1717
b.sign_revision(revision_id, gpg_strategy)
1718
elif revision is not None:
1719
if len(revision) == 1:
1720
revno, rev_id = revision[0].in_history(b)
1721
b.sign_revision(rev_id, gpg_strategy)
1722
elif len(revision) == 2:
1723
# are they both on rh- if so we can walk between them
1724
# might be nice to have a range helper for arbitrary
1725
# revision paths. hmm.
1726
from_revno, from_revid = revision[0].in_history(b)
1727
to_revno, to_revid = revision[1].in_history(b)
1728
if to_revid is None:
1729
to_revno = b.revno()
1730
if from_revno is None or to_revno is None:
1731
raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
1732
for revno in range(from_revno, to_revno + 1):
1733
b.sign_revision(b.get_rev_id(revno), gpg_strategy)
1735
raise BzrCommandError('Please supply either one revision, or a range.')
1738
# these get imported and then picked up by the scan for cmd_*
1739
# TODO: Some more consistent way to split command definitions across files;
1740
# we do need to load at least some information about them to know of
1742
from bzrlib.conflicts import cmd_resolve, cmd_conflicts