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
494
511
def run(self, file_list, verbose=False):
495
b = Branch.open_containing(file_list[0])[0]
496
tree = WorkingTree(b.base, b)
497
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)
500
517
class cmd_file_id(Command):
614
631
def run(self, revision=None, file_list=None, diff_options=None):
615
632
from bzrlib.diff import show_diff
618
b = Branch.open_containing(file_list[0])[0]
619
tree = WorkingTree(b.base, b)
620
file_list = [tree.relpath(f) for f in file_list]
621
if file_list == ['']:
622
# just pointing to top-of-tree
625
b = Branch.open_containing('.')[0]
634
b, file_list = branch_files(file_list)
627
635
if revision is not None:
628
636
if len(revision) == 1:
629
637
show_diff(b, revision[0], specific_files=file_list,
1053
1061
from bzrlib.status import show_status
1054
1062
from cStringIO import StringIO
1056
b = Branch.open_containing('.')[0]
1057
tree = WorkingTree(b.base, b)
1059
selected_list = [tree.relpath(s) for s in selected_list]
1064
b, selected_list = branch_files(selected_list)
1060
1065
if message is None and not file:
1061
1066
catcher = StringIO()
1062
1067
show_status(b, specific_files=selected_list,
1376
1381
elif len(revision) != 1:
1377
1382
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1379
b = Branch.open_containing('.')[0]
1384
b, file_list = branch_files(file_list)
1380
1385
revno = revision[0].in_history(b).revno
1381
1386
merge(('.', revno), parse_spec('.'),
1382
1387
check_clean=False,
1433
1438
def run(self, from_branch, to_branch):
1434
1439
from bzrlib.fetch import Fetcher
1435
1440
from bzrlib.branch import Branch
1436
from_b = Branch(from_branch)
1437
to_b = Branch(to_branch)
1438
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)
1442
1454
class cmd_missing(Command):