22
22
from bzrlib.trace import mutter, note, log_error
23
23
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
24
from bzrlib.branch import find_branch
25
from bzrlib import BZRDIR
24
from bzrlib.osutils import quotefn
25
from bzrlib import Branch, Inventory, InventoryEntry, BZRDIR, \
31
def register_command(cmd):
32
def register_plugin_command(cmd):
32
33
"Utility function to help register a command"
304
305
def run(self, all=False, show_ids=False, file_list=None):
306
b = find_branch(file_list[0])
307
b = Branch(file_list[0])
307
308
file_list = [b.relpath(x) for x in file_list]
308
309
# special case: only one path was given and it's the root
310
311
if file_list == ['']:
315
316
status.show_status(b, show_unchanged=all, show_ids=show_ids,
316
317
specific_files=file_list)
360
360
takes_options = ['verbose', 'no-recurse']
362
362
def run(self, file_list, verbose=False, no_recurse=False):
363
from bzrlib.add import smart_add
364
smart_add(file_list, verbose, not no_recurse)
368
class cmd_mkdir(Command):
369
"""Create a new versioned directory.
371
This is equivalent to creating the directory and then adding it.
373
takes_args = ['dir+']
375
def run(self, dir_list):
382
b.add([d], verbose=True)
363
bzrlib.add.smart_add(file_list, verbose, not no_recurse)
385
366
class cmd_relpath(Command):
485
464
print "Using last location: %s" % stored_loc
486
465
location = stored_loc
487
cache_root = tempfile.mkdtemp()
488
from bzrlib.branch import DivergedBranches
466
from branch import find_branch, DivergedBranches
489
467
br_from = find_branch(location)
490
468
location = pull_loc(br_from)
491
469
old_revno = br_to.revno()
493
from branch import find_cached_branch, DivergedBranches
494
br_from = find_cached_branch(location, cache_root)
495
location = pull_loc(br_from)
496
old_revno = br_to.revno()
498
br_to.update_revisions(br_from)
499
except DivergedBranches:
500
raise BzrCommandError("These branches have diverged."
503
merge(('.', -1), ('.', old_revno), check_clean=False)
504
if location != stored_loc:
505
br_to.controlfile("x-pull", "wb").write(location + "\n")
471
br_to.update_revisions(br_from)
472
except DivergedBranches:
473
raise BzrCommandError("These branches have diverged. Try merge.")
475
merge(('.', -1), ('.', old_revno), check_clean=False)
476
if location != stored_loc:
477
br_to.controlfile("x-pull", "wb").write(location + "\n")
523
493
def run(self, from_location, to_location=None, revision=None):
525
495
from bzrlib.merge import merge
526
from bzrlib.branch import DivergedBranches, NoSuchRevision, \
527
find_cached_branch, Branch
496
from branch import find_branch, DivergedBranches, NoSuchRevision
528
497
from shutil import rmtree
529
from meta_store import CachedStore
531
cache_root = tempfile.mkdtemp()
534
br_from = find_cached_branch(from_location, cache_root)
536
if e.errno == errno.ENOENT:
537
raise BzrCommandError('Source location "%s" does not'
538
' exist.' % to_location)
542
if to_location is None:
543
to_location = os.path.basename(from_location.rstrip("/\\"))
546
os.mkdir(to_location)
548
if e.errno == errno.EEXIST:
549
raise BzrCommandError('Target directory "%s" already'
550
' exists.' % to_location)
551
if e.errno == errno.ENOENT:
552
raise BzrCommandError('Parent of "%s" does not exist.' %
556
br_to = Branch(to_location, init=True)
559
br_to.update_revisions(br_from, stop_revision=revision)
560
except NoSuchRevision:
562
msg = "The branch %s has no revision %d." % (from_location,
564
raise BzrCommandError(msg)
565
merge((to_location, -1), (to_location, 0), this_dir=to_location,
566
check_clean=False, ignore_zero=True)
567
from_location = pull_loc(br_from)
568
br_to.controlfile("x-pull", "wb").write(from_location + "\n")
499
br_from = find_branch(from_location)
501
if e.errno == errno.ENOENT:
502
raise BzrCommandError('Source location "%s" does not exist.' %
507
if to_location is None:
508
to_location = os.path.basename(from_location.rstrip("/\\"))
511
os.mkdir(to_location)
513
if e.errno == errno.EEXIST:
514
raise BzrCommandError('Target directory "%s" already exists.' %
516
if e.errno == errno.ENOENT:
517
raise BzrCommandError('Parent of "%s" does not exist.' %
521
br_to = Branch(to_location, init=True)
524
br_to.update_revisions(br_from, stop_revision=revision)
525
except NoSuchRevision:
527
msg = "The branch %s has no revision %d." % (from_location,
529
raise BzrCommandError(msg)
530
merge((to_location, -1), (to_location, 0), this_dir=to_location,
531
check_clean=False, ignore_zero=True)
532
from_location = pull_loc(br_from)
533
br_to.controlfile("x-pull", "wb").write(from_location + "\n")
573
536
def pull_loc(branch):
664
628
"""Display list of revision ids on this branch."""
667
for patchid in find_branch('.').revision_history():
631
for patchid in Branch('.').revision_history():
671
635
class cmd_directories(Command):
672
636
"""Display list of versioned directories in this branch."""
674
for name, ie in find_branch('.').read_working_inventory().directories():
638
for name, ie in Branch('.').read_working_inventory().directories():
819
783
takes_args = ['filename?']
820
784
def run(self, filename=None):
821
785
"""Print the branch root."""
786
from branch import find_branch
822
787
b = find_branch(filename)
823
788
print getattr(b, 'base', None) or getattr(b, 'baseurl')
1094
1053
def run(self, message=None, file=None, verbose=True, selected_list=None):
1095
1054
from bzrlib.commit import commit
1096
from bzrlib.osutils import get_text_message
1098
1056
## Warning: shadows builtin file()
1099
1057
if not message and not file:
1102
catcher = cStringIO.StringIO()
1103
sys.stdout = catcher
1104
cmd_status({"file_list":selected_list}, {})
1105
info = catcher.getvalue()
1107
message = get_text_message(info)
1110
raise BzrCommandError("please specify a commit message",
1111
["use either --message or --file"])
1058
raise BzrCommandError("please specify a commit message",
1059
["use either --message or --file"])
1112
1060
elif message and file:
1113
1061
raise BzrCommandError("please specify either --message or --file")
1253
1201
check_clean=(not force))
1257
1204
class cmd_revert(Command):
1258
"""Restore selected files from a previous revision.
1260
takes_args = ['file+']
1261
def run(self, file_list):
1262
from bzrlib.branch import find_branch
1267
b = find_branch(file_list[0])
1269
b.revert([b.relpath(f) for f in file_list])
1272
class cmd_merge_revert(Command):
1273
1205
"""Reverse all changes since the last commit.
1275
1207
Only versioned files are affected.