35
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
38
69
class cmd_status(Command):
39
70
"""Display status summary.
88
119
def run(self, all=False, show_ids=False, file_list=None, revision=None):
90
b, relpath = Branch.open_containing(file_list[0])
91
if relpath == '' and len(file_list) == 1:
94
# generate relative paths.
95
# note that if this is a remote branch, we would want
96
# relpath against the transport. RBC 20051018
97
tree = WorkingTree(b.base, b)
98
file_list = [tree.relpath(x) for x in file_list]
100
b = Branch.open_containing('.')[0]
120
b, file_list = branch_files(file_list)
102
122
from bzrlib.status import show_status
103
123
show_status(b, show_unchanged=all, show_ids=show_ids,
267
287
takes_args = ['source$', 'dest']
268
288
def run(self, source_list, dest):
269
b = Branch.open_containing('.')[0]
289
b, source_list = branch_files(source_list)
271
291
# TODO: glob expansion on windows?
272
292
tree = WorkingTree(b.base, b)
273
b.move([tree.relpath(s) for s in source_list], tree.relpath(dest))
293
b.move(source_list, tree.relpath(dest))
276
296
class cmd_rename(Command):
290
310
takes_args = ['from_name', 'to_name']
292
312
def run(self, from_name, to_name):
293
b = Branch.open_containing('.')[0]
294
tree = WorkingTree(b.base, b)
295
b.rename_one(tree.relpath(from_name), tree.relpath(to_name))
313
b, (from_name, to_name) = branch_files((from_name, to_name))
314
b.rename_one(from_name, to_name)
298
317
class cmd_mv(Command):
312
331
def run(self, names_list):
313
332
if len(names_list) < 2:
314
333
raise BzrCommandError("missing file argument")
315
b = Branch.open_containing(names_list[0])[0]
316
tree = WorkingTree(b.base, b)
317
rel_names = [tree.relpath(x) for x in names_list]
334
b, rel_names = branch_files(names_list)
319
336
if os.path.isdir(names_list[-1]):
320
337
# move into existing directory
333
350
class cmd_pull(Command):
334
351
"""Pull any changes from another branch into the current one.
336
If the location is omitted, the last-used location will be used.
337
Both the revision history and the working directory will be
353
If there is no default location set, the first pull will set it. After
354
that, you can omit the location to use the default. To change the
355
default, use --remember.
340
357
This command only works on branches that have not diverged. Branches are
341
358
considered diverged if both branches have had commits without first
342
359
pulling from the other.
344
361
If branches have diverged, you can use 'bzr merge' to pull the text changes
345
from one into the other.
362
from one into the other. Once one branch has merged, the other should
363
be able to pull it again.
365
If you want to forget your local changes and just update your branch to
366
match the remote one, use --overwrite.
347
takes_options = ['remember', 'clobber']
368
takes_options = ['remember', 'overwrite']
348
369
takes_args = ['location?']
350
def run(self, location=None, remember=False, clobber=False):
371
def run(self, location=None, remember=False, overwrite=False):
351
372
from bzrlib.merge import merge
352
373
from shutil import rmtree
362
383
location = stored_loc
363
384
br_from = Branch.open(location)
365
br_to.working_tree().pull(br_from, remember, clobber)
386
br_to.working_tree().pull(br_from, remember, overwrite)
366
387
except DivergedBranches:
367
388
raise BzrCommandError("These branches have diverged."
490
511
def run(self, file_list, verbose=False):
491
b = Branch.open_containing(file_list[0])[0]
492
tree = WorkingTree(b.base, b)
493
tree.remove([tree.relpath(f) for f in file_list], verbose=verbose)
512
b, file_list = branch_files(file_list)
513
tree = b.working_tree()
514
tree.remove(file_list, verbose=verbose)
496
517
class cmd_file_id(Command):
610
631
def run(self, revision=None, file_list=None, diff_options=None):
611
632
from bzrlib.diff import show_diff
614
b = Branch.open_containing(file_list[0])[0]
615
tree = WorkingTree(b.base, b)
616
file_list = [tree.relpath(f) for f in file_list]
617
if file_list == ['']:
618
# just pointing to top-of-tree
621
b = Branch.open_containing('.')[0]
634
b, file_list = branch_files(file_list)
623
635
if revision is not None:
624
636
if len(revision) == 1:
625
637
show_diff(b, revision[0], specific_files=file_list,
1049
1061
from bzrlib.status import show_status
1050
1062
from cStringIO import StringIO
1052
b = Branch.open_containing('.')[0]
1053
tree = WorkingTree(b.base, b)
1055
selected_list = [tree.relpath(s) for s in selected_list]
1064
b, selected_list = branch_files(selected_list)
1056
1065
if message is None and not file:
1057
1066
catcher = StringIO()
1058
1067
show_status(b, specific_files=selected_list,
1372
1381
elif len(revision) != 1:
1373
1382
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1375
b = Branch.open_containing('.')[0]
1384
b, file_list = branch_files(file_list)
1376
1385
revno = revision[0].in_history(b).revno
1377
1386
merge(('.', revno), parse_spec('.'),
1378
1387
check_clean=False,
1429
1438
def run(self, from_branch, to_branch):
1430
1439
from bzrlib.fetch import Fetcher
1431
1440
from bzrlib.branch import Branch
1432
from_b = Branch(from_branch)
1433
to_b = Branch(to_branch)
1434
Fetcher(to_b, from_b)
1441
from_b = Branch.open(from_branch)
1442
to_b = Branch.open(to_branch)
1447
Fetcher(to_b, from_b)
1438
1454
class cmd_missing(Command):