27
27
from bzrlib.commands import Command, display_command
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
30
from bzrlib.errors import DivergedBranches
30
from bzrlib.errors import DivergedBranches, NoSuchFile, NoWorkingTree
31
31
from bzrlib.option import Option
32
32
from bzrlib.revisionspec import RevisionSpec
33
33
import bzrlib.trace
383
381
location = stored_loc
384
382
br_from = Branch.open(location)
386
br_to.working_tree().pull(br_from, remember, overwrite)
384
br_to.working_tree().pull(br_from, overwrite)
387
385
except DivergedBranches:
388
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)
392
473
class cmd_branch(Command):
595
677
bzr commit -m 'imported project'
598
Branch.initialize('.')
679
takes_args = ['location?']
680
def run(self, location=None):
681
from bzrlib.branch import Branch
685
# The path has to exist to initialize a
686
# branch inside of it.
687
# Just using os.mkdir, since I don't
688
# believe that we want to create a bunch of
689
# locations if the user supplies an extended path
690
if not os.path.exists(location):
692
Branch.initialize(location)
601
695
class cmd_diff(Command):
634
728
b, file_list = branch_files(file_list)
635
729
if revision is not None:
636
730
if len(revision) == 1:
637
show_diff(b, revision[0], specific_files=file_list,
638
external_diff_options=diff_options)
731
return show_diff(b, revision[0], specific_files=file_list,
732
external_diff_options=diff_options)
639
733
elif len(revision) == 2:
640
show_diff(b, revision[0], specific_files=file_list,
641
external_diff_options=diff_options,
642
revision2=revision[1])
734
return show_diff(b, revision[0], specific_files=file_list,
735
external_diff_options=diff_options,
736
revision2=revision[1])
644
738
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
646
show_diff(b, None, specific_files=file_list,
647
external_diff_options=diff_options)
740
return show_diff(b, None, specific_files=file_list,
741
external_diff_options=diff_options)
652
744
class cmd_deleted(Command):
830
926
# TODO: Take a revision or remote path and list that tree instead.
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'),
833
def run(self, revision=None, verbose=False):
834
b, relpath = Branch.open_containing('.')[0]
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('.')
835
956
if revision == None:
836
957
tree = b.working_tree()
838
tree = b.revision_tree(revision.in_history(b).rev_id)
959
tree = b.revision_tree(revision[0].in_history(b).rev_id)
839
960
for fp, fc, kind, fid, entry in tree.list_files():
841
kindch = entry.kind_character()
842
print '%-8s %s%s' % (fc, fp, kindch)
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')