def run(self, subcommand, args_list, revision=None, output=None): "Handle the bisect command." log_fn = None if subcommand in ('yes', 'no', 'move') and revision: pass elif subcommand in ('replay', ) and args_list and len(args_list) == 1: log_fn = args_list[0] elif subcommand in ('move', ) and not revision: raise BzrCommandError( "The 'bisect move' command requires a revision.") elif args_list or revision: raise BzrCommandError("Improper arguments to bisect " + subcommand) # Dispatch. if subcommand == "start": self.start() elif subcommand == "yes": self.yes(revision) elif subcommand == "no": self.no(revision) elif subcommand == "move": self.move(revision) elif subcommand == "reset": self.reset() elif subcommand == "log": self.log(output) elif subcommand == "replay": self.replay(log_fn) else: raise BzrCommandError("Unknown bisect command: " + subcommand)
def run(self, file_list, all=False): if file_list is None: if not all: raise BzrCommandError( "command 'extmerge' needs one or more FILE, or --all") tree = WorkingTree.open_containing(u'.')[0] file_list = list(tree.abspath(f.path) for f in tree.conflicts()) else: if all: raise BzrCommandError( "If --all is specified, no FILE may be provided") for filename in file_list: if not os.path.exists(filename): print "%s does not exists" % filename else: failures = 0 for suffix in CONFLICT_SUFFIXES: if not os.path.exists(filename + suffix) and not failures: print "%s is not conflicted" % filename failures = 1 if not failures: run_extmerge(filename) if len(file_list) == 0: print "no conflicting files" else: # TODO: ask if the file(s) should get resolved, per file. print "remember to bzr resolve your files"
def run(self, name, location=None, delete=False, branch=False): if branch: provider = LocationBookmarkProvider() else: provider = GlobalBookmarkProvider() ensure_config_dir_exists() if delete: if provider.resolve_bookmark(name) is None: raise BzrCommandError('bookmark "%s" does not exist' % (name, )) provider.unset_bookmark(name) else: if '/' in name: raise BzrCommandError( '"%s" contains a "/" character, bookmarks should not contain"/" characters"' % name) if not location: raise BzrCommandError( 'no location provided for bookmark "%s"' % (name, )) provider.set_bookmark(name, location)
def run(self, public_url=None, project='', product=None, branch_name='', branch_title='', branch_description='', author='', link_bug=None, dry_run=False): from bzrlib.plugins.launchpad.lp_registration import ( BranchRegistrationRequest, BranchBugLinkRequest, DryRunLaunchpadService, LaunchpadService) if public_url is None: try: b = _mod_branch.Branch.open_containing('.')[0] except NotBranchError: raise BzrCommandError( gettext('register-branch requires a public ' 'branch url - see bzr help register-branch.')) public_url = b.get_public_branch() if public_url is None: raise NoPublicBranch(b) if product is not None: project = product trace.note( gettext('--product is deprecated; please use --project.')) rego = BranchRegistrationRequest( branch_url=public_url, branch_name=branch_name, branch_title=branch_title, branch_description=branch_description, product_name=project, author_email=author, ) linko = BranchBugLinkRequest(branch_url=public_url, bug_id=link_bug) if not dry_run: service = LaunchpadService() # This gives back the xmlrpc url that can be used for future # operations on the branch. It's not so useful to print to the # user since they can't do anything with it from a web browser; it # might be nice for the server to tell us about an html url as # well. else: # Run on service entirely in memory service = DryRunLaunchpadService() service.gather_user_credentials() rego.submit(service) if link_bug: linko.submit(service) self.outf.write('Branch registered.\n')
def validate_command(tool): """Validates that 'tool' contains at least one set of 'valid_parameter_sets'""" def check_substrings(string, substrings): """Checks if all 'substrings' occur in 'string'""" for e in substrings: if not e in string: return False return True sets = map(lambda x: check_substrings(tool, x), valid_parameter_sets) # not a single valid-parameter-set present -> BzrCommandError if not True in sets: raise BzrCommandError( "Error in external merge tool definition.\n" + "Definition needs to contain one of the following parameter sets:\n" + "".join( map(lambda x: "\t- %s\n" % x, map(", ".join, valid_parameter_sets))) + "Definition is %s" % tool)
def run(self, revision=None): from bzrlib import ui from bzrlib.plugins.launchpad import lp_api import webbrowser b = _mod_branch.Branch.open_containing('.')[0] pb = ui.ui_factory.nested_progress_bar() b.lock_read() try: if revision is None: revision_id = b.last_revision() else: revision_id = revision[0].as_revision_id(b) merged = self._find_proposals(revision_id, pb) if len(merged) == 0: raise BzrCommandError(gettext('No review found.')) trace.note(gettext('%d proposals(s) found.') % len(merged)) for mp in merged: webbrowser.open(lp_api.canonical_url(mp)) finally: b.unlock() pb.finished()
def run(self, location=None, remember=False, directory=None, no_rebase=False, strict=None): from bzrlib import urlutils from bzrlib.controldir import ControlDir from bzrlib.errors import BzrCommandError, NoWorkingTree from bzrlib.workingtree import WorkingTree if directory is None: directory = "." try: source_wt = WorkingTree.open_containing(directory)[0] source_branch = source_wt.branch except NoWorkingTree: source_branch = Branch.open(directory) source_wt = None if source_wt is not None: source_wt.check_changed_or_out_of_date( strict, 'dpush_strict', more_error='Use --no-strict to force the push.', more_warning='Uncommitted changes will not be pushed.') stored_loc = source_branch.get_push_location() if location is None: if stored_loc is None: raise BzrCommandError( gettext("No push location known or specified.")) else: display_url = urlutils.unescape_for_display( stored_loc, self.outf.encoding) self.outf.write( gettext("Using saved location: %s\n") % display_url) location = stored_loc controldir = ControlDir.open(location) target_branch = controldir.open_branch() target_branch.lock_write() try: try: push_result = source_branch.push(target_branch, lossy=True) except errors.LossyPushToSameVCS: raise BzrCommandError( gettext( "{0!r} and {1!r} are in the same VCS, lossy " "push not necessary. Please use regular push.").format( source_branch, target_branch)) # We successfully created the target, remember it if source_branch.get_push_location() is None or remember: # FIXME: Should be done only if we succeed ? -- vila 2012-01-18 source_branch.set_push_location(target_branch.base) if not no_rebase: old_last_revid = source_branch.last_revision() source_branch.pull(target_branch, overwrite=True) new_last_revid = source_branch.last_revision() if source_wt is not None and old_last_revid != new_last_revid: source_wt.lock_write() try: target = source_wt.branch.repository.revision_tree( new_last_revid) update_workingtree_fileids(source_wt, target) finally: source_wt.unlock() push_result.report(self.outf) finally: target_branch.unlock()
def _check(self): """Check preconditions for most operations to work.""" if not os.path.exists(bisect_info_path): raise BzrCommandError("No bisection in progress.")
def run(self, location=None, remember=False, directory=None, no_rebase=False): from bzrlib import urlutils from bzrlib.bzrdir import BzrDir from bzrlib.errors import BzrCommandError, NoWorkingTree from bzrlib.trace import info from bzrlib.workingtree import WorkingTree from upgrade import update_workingtree_fileids if directory is None: directory = "." try: source_wt = WorkingTree.open_containing(directory)[0] source_branch = source_wt.branch except NoWorkingTree: source_branch = Branch.open_containing(directory)[0] source_wt = None stored_loc = source_branch.get_push_location() if location is None: if stored_loc is None: raise BzrCommandError("No push location known or specified.") else: display_url = urlutils.unescape_for_display( stored_loc, self.outf.encoding) self.outf.write("Using saved location: %s\n" % display_url) location = stored_loc bzrdir = BzrDir.open(location) target_branch = bzrdir.open_branch() target_branch.lock_write() try: if not isinstance(target_branch, ForeignBranch): info( "target branch is not a foreign branch, using regular push." ) target_branch.pull(source_branch) no_rebase = True else: revid_map = target_branch.dpull(source_branch) # We successfully created the target, remember it if source_branch.get_push_location() is None or remember: source_branch.set_push_location(target_branch.base) if not no_rebase: _, old_last_revid = source_branch.last_revision_info() new_last_revid = revid_map[old_last_revid] if source_wt is not None: source_wt.pull(target_branch, overwrite=True, stop_revision=new_last_revid) source_wt.lock_write() try: update_workingtree_fileids( source_wt, source_wt.branch.repository.revision_tree( old_last_revid), source_wt.branch.repository.revision_tree( new_last_revid)) finally: source_wt.unlock() else: source_branch.pull(target_branch, overwrite=True, stop_revision=new_last_revid) finally: target_branch.unlock()
OK_ERRNO = (errno.ENOENT, errno.EACCES) def run_extmerge(filename): global mergetools usertool = get_user_merge_tool() if usertool: mergetools = [usertool] for tool in mergetools: validate_command(tool) try: ret = execute_command(tool, filename) except OSError, e: # ENOENT means no such editor if e.errno in OK_ERRNO: continue raise if ret == 0: return True elif ret == 127: continue else: mergetools = [tool] break if len(mergetools) != 1: raise BzrCommandError("Found no valid merge tool")