Exemple #1
0
    def _default_to_location(self, from_location):
        """Work out a good To location give a From location.

        :return: the To location or None if unsure
        """
        # We want to avoid opening the from location here so
        # we 'guess' the basename using some simple heuristics
        from_location = from_location.replace('\\', '/').rstrip('/')
        if from_location.find('/') >= 0:
            basename = osutils.basename(from_location)
        else:
            # Handle 'directory services' like lp:
            ds_sep = from_location.find(':')
            if ds_sep >= 0:
                basename = from_location[ds_sep + 1:]
            else:
                return None

        # Calculate the To location and check it's not the same as the
        # From location.
        to_location = osutils.pathjoin(self.parent_dir, basename)
        if to_location == from_location:
            return None
        else:
            return to_location
Exemple #2
0
 def validate_tree_is_controlfilename(self, tree):
     """check that 'tree' obeys the contract for is_control_filename."""
     bzrdirname = basename(tree.controldir.transport.base[:-1])
     self.assertTrue(tree.is_control_filename(bzrdirname))
     self.assertTrue(tree.is_control_filename(bzrdirname + '/subdir'))
     self.assertFalse(tree.is_control_filename('dir/' + bzrdirname))
     self.assertFalse(tree.is_control_filename(
         'dir/' + bzrdirname + '/sub'))
Exemple #3
0
 def _get_file_ie(self, path, parent_id, flags):
     file_id = self.path2id(path)
     name = osutils.basename(path)
     if 'l' in flags:
         ie = HgTreeLink(file_id, name, parent_id)
         ie.symlink_target = self.get_symlink_target(path)
     else:
         ie = HgTreeFile(file_id, name, parent_id)
         ie.text_sha1 = self.get_file_sha1(path)
         ie.executable = ('x' in flags)
     return ie
Exemple #4
0
def run_main(args):
    import os
    from breezy import osutils
    from breezy.plugins.propose import propose as _mod_propose
    from breezy.trace import note, show_error
    from ..proposal import (
        propose_or_push, )
    from ..run import (
        ScriptBranchChanger,
        ScriptMadeNoChanges,
    )
    from . import (
        open_packaging_branch, )
    main_branch = open_packaging_branch(args.package)
    if args.name is None:
        name = os.path.splitext(osutils.basename(args.script.split(' ')[0]))[0]
    else:
        name = args.name

    # TODO(jelmer): Check that ScriptBranchChanger updates upstream version if
    # it touches anything outside of debian/.

    try:
        result = propose_or_push(main_branch,
                                 name,
                                 ScriptBranchChanger(args.script),
                                 refresh=args.refresh,
                                 labels=args.label,
                                 dry_run=args.dry_run,
                                 mode=args.mode)
    except _mod_propose.UnsupportedHoster as e:
        show_error('No known supported hoster for %s. Run \'svp login\'?',
                   e.branch.user_url)
        return 1
    except _mod_propose.HosterLoginRequired as e:
        show_error(
            'Credentials for hosting site at %r missing. Run \'svp login\'?',
            e.hoster.base_url)
        return 1
    except ScriptMadeNoChanges:
        show_error('Script did not make any changes.')
        return 1

    if result.merge_proposal:
        if result.is_new:
            note('Merge proposal created.')
        else:
            note('Merge proposal updated.')
        if result.merge_proposal.url:
            note('URL: %s', result.merge_proposal.url)
        note('Description: %s', result.merge_proposal.get_description())

    if args.diff:
        result.show_base_diff(sys.stdout.buffer)
Exemple #5
0
 def test_create_anonymous_heavyweight_checkout(self):
     """A regular checkout from a readonly branch should succeed."""
     tree_a = self.make_branch_and_tree('a')
     rev_id = tree_a.commit('put some content in the branch')
     # open the branch via a readonly transport
     url = self.get_readonly_url(
         osutils.basename(tree_a.branch.base.rstrip('/')))
     t = transport.get_transport_from_url(url)
     if not tree_a.branch.controldir._format.supports_transport(t):
         raise tests.TestNotApplicable("format does not support transport")
     source_branch = _mod_branch.Branch.open(url)
     # sanity check that the test will be valid
     self.assertRaises((errors.LockError, errors.TransportNotPossible),
                       source_branch.lock_write)
     checkout = source_branch.create_checkout('c')
     self.assertEqual(rev_id, checkout.last_revision())
Exemple #6
0
def main(args):
    main_branch = _mod_branch.Branch.open(args.url)
    if args.name is None:
        name = os.path.splitext(osutils.basename(args.script.split(' ')[0]))[0]
    else:
        name = args.name
    commit_pending = {
        'auto': None,
        'yes': True,
        'no': False
    }[args.commit_pending]
    try:
        result = propose_or_push(main_branch,
                                 name,
                                 ScriptBranchChanger(args.script,
                                                     commit_pending),
                                 refresh=args.refresh,
                                 labels=args.label,
                                 mode=args.mode,
                                 dry_run=args.dry_run)
    except _mod_propose.UnsupportedHoster as e:
        show_error('No known supported hoster for %s. Run \'svp login\'?',
                   e.branch.user_url)
        return 1
    except _mod_propose.HosterLoginRequired as e:
        show_error(
            'Credentials for hosting site at %r missing. Run \'svp login\'?',
            e.hoster.base_url)
        return 1
    except ScriptMadeNoChanges:
        show_error('Script did not make any changes.')
        return 1

    if result.merge_proposal:
        if result.is_new:
            note('Merge proposal created.')
        else:
            note('Merge proposal updated.')
        if result.merge_proposal.url:
            note('URL: %s', result.merge_proposal.url)
        note('Description: %s', result.merge_proposal.get_description())

    if args.diff:
        result.show_base_diff(sys.stdout.buffer)
Exemple #7
0
 def _entries_to_incorporate(self):
     """Yields pairs of (inventory_entry, new_parent)."""
     other_inv = self.other_tree.inventory
     subdir_id = other_inv.path2id(self._source_subpath)
     if subdir_id is None:
         # XXX: The error would be clearer if it gave the URL of the source
         # branch, but we don't have a reference to that here.
         raise PathNotInTree(self._source_subpath, "Source tree")
     subdir = other_inv[subdir_id]
     parent_in_target = osutils.dirname(self._target_subdir)
     target_id = self.this_tree.inventory.path2id(parent_in_target)
     if target_id is None:
         raise PathNotInTree(self._target_subdir, "Target tree")
     name_in_target = osutils.basename(self._target_subdir)
     merge_into_root = subdir.copy()
     merge_into_root.name = name_in_target
     if merge_into_root.file_id in self.this_tree.inventory:
         # Give the root a new file-id.
         # This can happen fairly easily if the directory we are
         # incorporating is the root, and both trees have 'TREE_ROOT' as
         # their root_id.  Users will expect this to Just Work, so we
         # change the file-id here.
         # Non-root file-ids could potentially conflict too.  That's really
         # an edge case, so we don't do anything special for those.  We let
         # them cause conflicts.
         merge_into_root.file_id = generate_ids.gen_file_id(name_in_target)
     yield (merge_into_root, target_id)
     if subdir.kind != 'directory':
         # No children, so we are done.
         return
     for ignored_path, entry in other_inv.iter_entries_by_dir(subdir_id):
         parent_id = entry.parent_id
         if parent_id == subdir.file_id:
             # The root's parent ID has changed, so make sure children of
             # the root refer to the new ID.
             parent_id = merge_into_root.file_id
         yield (entry, parent_id)
Exemple #8
0
def derived_branch_name(script: str) -> str:
    return os.path.splitext(osutils.basename(script.split(" ")[0]))[0]