Пример #1
0
    def branch_iterator(self, target_root=None):
        if len(self.config) == 0:
            # branch not have externals configuration
            return

        self.bound = True
        if not target_root:
            target_root = self.branch.get_bound_location()
            if not target_root:
                self.bound = False
                target_root = self.branch.get_parent()
                if not target_root:
                    # support new braches with no parent yet
                    target_root = self.branch.base

        for arg in self.config: # url directory [revisionspec]
            location = self._relurljoin(target_root, arg[0])
            if target_root.startswith('file:///'):
                # try to pull externals from the parent for the feature branch
                path = pathjoin(local_path_from_url(target_root), arg[1])
                if isdir(path):
                    location = self._relpath(path)
                else:
                    # parent is local master branch
                    if location.startswith('file:///'):
                        location = self._relpath(local_path_from_url(location))

            check_legal_path(arg[1])
            rel_path = self._relpath(pathjoin(self.root, arg[1]))

            revision = None
            if len(arg) > 2:
                revision = arg[2]
            yield location, rel_path, revision
def execute_makecheck(local_branch, master_branch, old_revision_number,
                      old_revision_id, future_revision_number,
                      future_revision_id, tree_delta, future_tree):
    if (master_branch.get_parent().find("ubuntu-ui-toolkit") == -1):
        return

    print "Set work directory to %s" % local_path_from_url(master_branch.base)
    os.chdir(local_path_from_url(master_branch.base))

    print "Execute 'make check'.."
    if (subprocess.call("make check", shell=True) != 0):
        raise errors.BzrError("Tests failed, fix them before commit!")
Пример #3
0
 def setUp(self):
     PullerBranchTestCase.setUp(self)
     self._puller_script = os.path.join(
         config.root, 'cronscripts', 'supermirror-pull.py')
     self.makeCleanDirectory(config.codehosting.mirrored_branches_root)
     self.makeCleanDirectory(
         local_path_from_url(config.launchpad.bzr_imports_root_url))
def execute_makecheck(
        local_branch, master_branch, old_revision_number, old_revision_id,
        future_revision_number, future_revision_id, tree_delta, future_tree):
    if not master_branch.basis_tree().has_filename("qml/Shell.qml"):
        return

    os.chdir(local_path_from_url(master_branch.base))

    print "Executing 'make -C builddir test'.."
    os.environ['CTEST_OUTPUT_ON_FAILURE'] = "1"
    if (subprocess.call("make -C builddir test", shell=True) != 0):

        print("\n\n*** Warning ***\n\n"
              "Basic tests failed. This commit will not pass continuous "
              "integration.")

        branch = local_branch or master_branch
        revision = branch.repository.get_revision(future_revision_id)
        msg_file = open('message.txt', 'w')
        msg_file.write(revision.message)
        msg_file.close()

        print("\n\nSaved commit message to $SRC_DIR/message.txt.")
        print("You can uncommit this revision, fix the tests and reuse your "
              "message running:\n\nbzr commit -F message.txt\n\n")
    elif os.path.isfile("message.txt"):
        os.remove("message.txt")
Пример #5
0
    def test_open_containing(self):
        branch = self.make_branch_and_tree('.').branch
        local_base = urlutils.local_path_from_url(branch.base)

        # Empty opens '.'
        wt, relpath = WorkingTree.open_containing()
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # '.' opens this dir
        wt, relpath = WorkingTree.open_containing(u'.')
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # './foo' finds '.' and a relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # abspath(foo) finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(getcwd() + '/foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # can even be a url: finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(
                    urlutils.local_path_to_url(getcwd() + '/foo'))
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)
Пример #6
0
 def setUp(self):
     PullerBranchTestCase.setUp(self)
     self._puller_script = os.path.join(
         config.root, 'cronscripts', 'supermirror-pull.py')
     self.makeCleanDirectory(config.codehosting.mirrored_branches_root)
     self.makeCleanDirectory(
         local_path_from_url(config.launchpad.bzr_imports_root_url))
Пример #7
0
    def test_open_containing(self):
        branch = self.make_branch_and_tree('.').branch
        local_base = urlutils.local_path_from_url(branch.base)

        # Empty opens '.'
        wt, relpath = WorkingTree.open_containing()
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # '.' opens this dir
        wt, relpath = WorkingTree.open_containing(u'.')
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # './foo' finds '.' and a relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # abspath(foo) finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(getcwd() + '/foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # can even be a url: finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(
            urlutils.local_path_to_url(getcwd() + '/foo'))
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)
Пример #8
0
    def __init__(self, base, userID):
        """Set the base path where files will be stored."""
        self.user = anvillib.acls.UserFS(userID)
        if not base.startswith('file://'):
            symbol_versioning.warn(
                "Instantiating AnvLocalTransport with a filesystem path"
                " is deprecated as of bzr 0.8."
                " Please use bzrlib.transport.get_transport()"
                " or pass in a file:// url.",
                 DeprecationWarning,
                 stacklevel=2
                 )
            base = urlutils.local_path_to_url(base)
        if base[-1] != '/':
            base = base + '/'

        # Special case : windows has no "root", but does have
        # multiple lettered drives inside it. #240910
        if sys.platform == 'win32' and base == 'file:///':
            base = ''
            self._local_base = ''
            super(AnvLocalTransport, self).__init__(base)
            return

        super(AnvLocalTransport, self).__init__(base)
        self._local_base = urlutils.local_path_from_url(base)
Пример #9
0
def execute_makecheck(local_branch, master_branch, old_revision_number,
                      old_revision_id, future_revision_number,
                      future_revision_id, tree_delta, future_tree):
    if not master_branch.basis_tree().has_filename("qml/Shell.qml"):
        return

    os.chdir(local_path_from_url(master_branch.base))

    print "Executing 'make -C builddir test'.."
    os.environ['CTEST_OUTPUT_ON_FAILURE'] = "1"
    if (subprocess.call("make -C builddir test", shell=True) != 0):

        print(
            "\n\n*** Warning ***\n\n"
            "Basic tests failed. This commit will not pass continuous "
            "integration.")

        branch = local_branch or master_branch
        revision = branch.repository.get_revision(future_revision_id)
        msg_file = open('message.txt', 'w')
        msg_file.write(revision.message)
        msg_file.close()

        print("\n\nSaved commit message to $SRC_DIR/message.txt.")
        print(
            "You can uncommit this revision, fix the tests and reuse your "
            "message running:\n\nbzr commit -F message.txt\n\n")
    elif os.path.isfile("message.txt"):
        os.remove("message.txt")
Пример #10
0
    def test_push_remember(self):
        """Push changes from one branch to another and test push location."""
        transport = self.get_transport()
        tree_a = self.make_branch_and_tree('branch_a')
        branch_a = tree_a.branch
        self.build_tree(['branch_a/a'])
        tree_a.add('a')
        tree_a.commit('commit a')
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
        branch_b = tree_b.branch
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
        branch_c = tree_c.branch
        self.build_tree(['branch_a/b'])
        tree_a.add('b')
        tree_a.commit('commit b')
        self.build_tree(['branch_b/c'])
        tree_b.add('c')
        tree_b.commit('commit c')
        # initial push location must be empty
        self.assertEqual(None, branch_b.get_push_location())

        # test push for failure without push location set
        os.chdir('branch_a')
        out = self.run_bzr('push', retcode=3)
        self.assertEquals(out,
                ('','bzr: ERROR: No push location known or specified.\n'))

        # test not remembered if cannot actually push
        self.run_bzr('push ../path/which/doesnt/exist', retcode=3)
        out = self.run_bzr('push', retcode=3)
        self.assertEquals(
                ('', 'bzr: ERROR: No push location known or specified.\n'),
                out)

        # test implicit --remember when no push location set, push fails
        out = self.run_bzr('push ../branch_b', retcode=3)
        self.assertEquals(out,
                ('','bzr: ERROR: These branches have diverged.  '
                    'Try using "merge" and then "push".\n'))
        self.assertEquals(abspath(branch_a.get_push_location()),
                          abspath(branch_b.bzrdir.root_transport.base))

        # test implicit --remember after resolving previous failure
        uncommit(branch=branch_b, tree=tree_b)
        transport.delete('branch_b/c')
        out, err = self.run_bzr('push')
        path = branch_a.get_push_location()
        self.assertEquals(out,
                          'Using saved location: %s\n' 
                          'Pushed up to revision 2.\n'
                          % local_path_from_url(path))
        self.assertEqual(err,
                         'All changes applied successfully.\n')
        self.assertEqual(path,
                         branch_b.bzrdir.root_transport.base)
        # test explicit --remember
        self.run_bzr('push ../branch_c --remember')
        self.assertEquals(branch_a.get_push_location(),
                          branch_c.bzrdir.root_transport.base)
Пример #11
0
 def get_root(self):
     """Return root working directory (or URL for treeless remote branch)."""
     if self.tree:
         return self.tree.basedir
     else:
         url = self.branch.base
         if url.startswith('file://'):
             return urlutils.local_path_from_url(url)
         return url
Пример #12
0
 def add_url(self, label, url):
     """Add a URL to the list, converting it to a path if possible"""
     if url is None:
         return
     try:
         path = urlutils.local_path_from_url(url)
     except errors.InvalidURL:
         self.locs.append((label, url))
     else:
         self.add_path(label, path)
Пример #13
0
 def add_url(self, label, url):
     """Add a URL to the list, converting it to a path if possible"""
     if url is None:
         return
     try:
         path = urlutils.local_path_from_url(url)
     except errors.InvalidURL:
         self.locs.append((label, url))
     else:
         self.add_path(label, path)
Пример #14
0
    def test_push_remember(self):
        """Push changes from one branch to another and test push location."""
        transport = self.get_transport()
        tree_a = self.make_branch_and_tree('branch_a')
        branch_a = tree_a.branch
        self.build_tree(['branch_a/a'])
        tree_a.add('a')
        tree_a.commit('commit a')
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
        branch_b = tree_b.branch
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
        branch_c = tree_c.branch
        self.build_tree(['branch_a/b'])
        tree_a.add('b')
        tree_a.commit('commit b')
        self.build_tree(['branch_b/c'])
        tree_b.add('c')
        tree_b.commit('commit c')
        # initial push location must be empty
        self.assertEqual(None, branch_b.get_push_location())

        # test push for failure without push location set
        os.chdir('branch_a')
        out = self.run_bzr('push', retcode=3)
        self.assertEquals(
            out, ('', 'bzr: ERROR: No push location known or specified.\n'))

        # test not remembered if cannot actually push
        self.run_bzr('push ../path/which/doesnt/exist', retcode=3)
        out = self.run_bzr('push', retcode=3)
        self.assertEquals(
            ('', 'bzr: ERROR: No push location known or specified.\n'), out)

        # test implicit --remember when no push location set, push fails
        out = self.run_bzr('push ../branch_b', retcode=3)
        self.assertEquals(out,
                          ('', 'bzr: ERROR: These branches have diverged.  '
                           'Try using "merge" and then "push".\n'))
        self.assertEquals(abspath(branch_a.get_push_location()),
                          abspath(branch_b.bzrdir.root_transport.base))

        # test implicit --remember after resolving previous failure
        uncommit(branch=branch_b, tree=tree_b)
        transport.delete('branch_b/c')
        out, err = self.run_bzr('push')
        path = branch_a.get_push_location()
        self.assertEquals(
            out, 'Using saved location: %s\n'
            'Pushed up to revision 2.\n' % local_path_from_url(path))
        self.assertEqual(err, 'All changes applied successfully.\n')
        self.assertEqual(path, branch_b.bzrdir.root_transport.base)
        # test explicit --remember
        self.run_bzr('push ../branch_c --remember')
        self.assertEquals(branch_a.get_push_location(),
                          branch_c.bzrdir.root_transport.base)
Пример #15
0
    def test_merge_remember(self):
        """Merge changes from one branch to another, test submit location."""
        tree_a = self.make_branch_and_tree('branch_a')
        branch_a = tree_a.branch
        self.build_tree(['branch_a/a'])
        tree_a.add('a')
        tree_a.commit('commit a')
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
        tree_b = branch_b.bzrdir.open_workingtree()
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
        tree_c = branch_c.bzrdir.open_workingtree()
        self.build_tree(['branch_a/b'])
        tree_a.add('b')
        tree_a.commit('commit b')
        self.build_tree(['branch_c/c'])
        tree_c.add('c')
        tree_c.commit('commit c')
        # reset parent
        parent = branch_b.get_parent()
        branch_b.set_parent(None)
        self.assertEqual(None, branch_b.get_parent())
        # test merge for failure without parent set
        os.chdir('branch_b')
        out = self.run_bzr('merge', retcode=3)
        self.assertEquals(
            out, ('', 'bzr: ERROR: No location specified or remembered\n'))
        # test implicit --remember when no parent set, this merge conflicts
        self.build_tree(['d'])
        tree_b.add('d')
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
                           'merge ../branch_a')
        self.assertEquals(abspath(branch_b.get_submit_branch()),
                          abspath(parent))
        # test implicit --remember after resolving conflict
        tree_b.commit('commit d')
        out, err = self.run_bzr('merge')

        base = urlutils.local_path_from_url(branch_a.base)
        self.assertStartsWith(
            err, 'Merging from remembered location %s\n' % (base, ))
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
        self.assertEquals(abspath(branch_b.get_submit_branch()),
                          abspath(parent))
        # re-open tree as external run_bzr modified it
        tree_b = branch_b.bzrdir.open_workingtree()
        tree_b.commit('merge branch_a')
        # test explicit --remember
        out, err = self.run_bzr('merge ../branch_c --remember')
        self.assertEquals(out, '')
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
        self.assertEquals(abspath(branch_b.get_submit_branch()),
                          abspath(branch_c.bzrdir.root_transport.base))
        # re-open tree as external run_bzr modified it
        tree_b = branch_b.bzrdir.open_workingtree()
        tree_b.commit('merge branch_c')
Пример #16
0
    def test_set_push_location(self):
        conf = config.LocationConfig.from_string('# comment\n', '.', save=True)

        branch = self.make_branch('.', format='knit')
        branch.set_push_location('foo')
        local_path = urlutils.local_path_from_url(branch.base[:-1])
        self.assertFileEqual("# comment\n"
                             "[%s]\n"
                             "push_location = foo\n"
                             "push_location:policy = norecurse\n" % local_path,
                             config.locations_config_filename())
Пример #17
0
 def __init__(self, branch, revid, root=None):
     self.branch = branch
     self.revid = revid
     if root is not None:
         self.root = root
     else:
         self.root = local_path_from_url(branch.base)
     self.cwd = getcwd()
     self.config = []
     self.bound = True
     self.use_snapshot = command_kwargs and 'revision' in command_kwargs
Пример #18
0
    def test_set_push_location(self):
        conf = config.LocationConfig.from_string('# comment\n', '.', save=True)

        branch = self.make_branch('.', format='knit')
        branch.set_push_location('foo')
        local_path = urlutils.local_path_from_url(branch.base[:-1])
        self.assertFileEqual(
            "# comment\n"
            "[%s]\n"
            "push_location = foo\n"
            "push_location:policy = norecurse\n" % local_path,
            config.locations_config_filename())
Пример #19
0
 def test_win32_set_parent_on_another_drive(self):
     if sys.platform != 'win32':
         raise TestSkipped('windows-specific test')
     b = self.make_branch('.')
     base_url = b.bzrdir.transport.abspath('.')
     if not base_url.startswith('file:///'):
         raise TestNotApplicable('this test should be run with local base')
     base = urlutils.local_path_from_url(base_url)
     other = 'file:///D:/path'
     if base[0] != 'C':
         other = 'file:///C:/path'
     b.set_parent(other)
     self.assertEquals(other, b._get_parent_location())
Пример #20
0
 def test_win32_set_parent_on_another_drive(self):
     if sys.platform != 'win32':
         raise TestSkipped('windows-specific test')
     b = self.make_branch('.')
     base_url = b.bzrdir.transport.abspath('.')
     if not base_url.startswith('file:///'):
         raise TestNotApplicable('this test should be run with local base')
     base = urlutils.local_path_from_url(base_url)
     other = 'file:///D:/path'
     if base[0] != 'C':
         other = 'file:///C:/path'
     b.set_parent(other)
     self.assertEqual(other, b._get_parent_location())
Пример #21
0
    def pushBazaarBranch(self, bazaar_branch, remote_branch=None):
        """See `ToBzrImportWorker.pushBazaarBranch`.

        In addition to the superclass' behaviour, we store bzr-git's cache
        directory at .bzr/repository/git in the import data store.
        """
        non_trivial = PullingImportWorker.pushBazaarBranch(self, bazaar_branch)
        repo_base = bazaar_branch.repository._transport.base
        git_db_dir = os.path.join(local_path_from_url(repo_base), 'git')
        local_name = 'git-cache.tar.gz'
        create_tarball(git_db_dir, local_name)
        self.import_data_store.put(local_name)
        return non_trivial
Пример #22
0
    def test_uncommittedchanges_display_url(self):
        """The display_url of UncommittedChanges errors should be serialised"""
        self.requireFeature(compatibility.UnicodeFilenameFeature)
        path = u"\u1234"

        class FakeTree(object):
            def __init__(self, url):
                self.user_url = url

        attrs = self.check_exception_instance(
            errors.UncommittedChanges(
                FakeTree(urlutils.local_path_to_url(path))))
        self.assertIsSameRealPath(
            path, urlutils.local_path_from_url(attrs["display_url"]))
Пример #23
0
    def pushBazaarBranch(self, bazaar_branch):
        """See `ImportWorker.pushBazaarBranch`.

        In addition to the superclass' behaviour, we store bzr-git's cache
        directory at .bzr/repository/git in the import data store.
        """
        non_trivial = PullingImportWorker.pushBazaarBranch(
            self, bazaar_branch)
        repo_base = bazaar_branch.repository._transport.base
        git_db_dir = os.path.join(local_path_from_url(repo_base), 'git')
        local_name = 'git-cache.tar.gz'
        create_tarball(git_db_dir, local_name)
        self.import_data_store.put(local_name)
        return non_trivial
Пример #24
0
 def _get_save_path(self, basename):
     d = gtk.FileChooserDialog('Save As', self,
                               gtk.FILE_CHOOSER_ACTION_SAVE,
                               buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                        gtk.STOCK_CANCEL,
                                        gtk.RESPONSE_CANCEL,))
     d.set_current_name(basename)
     try:
         result = d.run()
         if result != gtk.RESPONSE_OK:
             raise SelectCancelled()
         return urlutils.local_path_from_url(d.get_uri())
     finally:
         d.destroy()
Пример #25
0
 def _get_save_path(self, basename):
     d = Gtk.FileChooserDialog('Save As', self,
                               Gtk.FileChooserAction.SAVE,
                               buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK,
                                        Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,))
     d.set_current_name(basename)
     try:
         result = d.run()
         if result != Gtk.ResponseType.OK:
             raise SelectCancelled()
         return urlutils.local_path_from_url(d.get_uri())
     finally:
         d.destroy()
Пример #26
0
    def run(self, from_location, to_location, revision=None):
        branch = Branch.open_containing('.')[0]
        root = local_path_from_url(branch.base)

        # select what do it
        if isdir(pathjoin(root, to_location, '.bzr')) or isdir(pathjoin(root, to_location, '.svn')):
            if branch.get_bound_location():
                cmd = ['update', to_location]
            else:
                cmd = ['pull', from_location, '--directory', to_location]
        else:
            if branch.get_bound_location():
                cmd = ['checkout', from_location, to_location]
            else:
                cmd = ['branch', from_location, to_location]

            # command branch don't create recursive directory
            dirs = to_location.rpartition('/')
            if dirs[0] != '' and not isdir(dirs[0]):
                os.makedirs(dirs[0].encode(get_user_encoding()))

        # if use revision options but not for 'update'
        if revision is not None:# and cmd[0] != 'update':
            cmd += ['--revision', revision[0].user_spec]

        note('Add external ' + ' '.join(cmd))
        run_bzr_catch_user_errors(cmd)

        bzrmeta = pathjoin(root, '.bzrmeta')
        if not isdir(bzrmeta):
            os.mkdir(bzrmeta)

        # add new branch to config and snapshot files
        line = from_location + ' ' + self._quoted_if_need(to_location)
        if revision:
            line += ' ' + revision[0].user_spec
        self._add_to_file(root, externals.CONFIG_PATH, line)
        self._add_to_file(root, externals.SNAPSHOT_PATH, line)

        # add ignore mask
        from bzrlib import IGNORE_FILENAME
        self._add_to_file(root, IGNORE_FILENAME, './' + to_location)

        # add config files to repository
        cmd = ['add',
            '.bzrignore',
            '.bzrmeta/externals',
            '.bzrmeta/externals-snapshot']
        run_bzr_catch_user_errors(cmd)
Пример #27
0
    def local_abspath(self, relpath):
        """Transform the given relative path URL into the actual path on disk

        This function only exists for the AnvLocalTransport, since it is
        the only one that has direct local access.
        This is mostly for stuff like WorkingTree which needs to know
        the local working directory.  The returned path will always contain
        forward slashes as the path separator, regardless of the platform.

        This function is quite expensive: it calls realpath which resolves
        symlinks.
        """
        absurl = self.abspath(relpath)
        # mutter(u'relpath %s => base: %s, absurl %s', relpath, self.base, absurl)
        return urlutils.local_path_from_url(absurl)
Пример #28
0
 def test_push_quiet(self):
     # test that using -q makes output quiet
     t = self.make_branch_and_tree('tree')
     self.build_tree(['tree/file'])
     t.add('file')
     t.commit('commit 1')
     self.run_bzr('push -d tree pushed-to')
     # Refresh the branch as 'push' modified it and get the push location
     push_loc = t.branch.bzrdir.open_branch().get_push_location()
     out, err = self.run_bzr('push', working_dir="tree")
     self.assertEqual('Using saved push location: %s\n'
                      'No new revisions or tags to push.\n' %
                      urlutils.local_path_from_url(push_loc), err)
     out, err = self.run_bzr('push -q', working_dir="tree")
     self.assertEqual('', out)
     self.assertEqual('', err)
Пример #29
0
 def test_push_quiet(self):
     # test that using -q makes output quiet
     t = self.make_branch_and_tree('tree')
     self.build_tree(['tree/file'])
     t.add('file')
     t.commit('commit 1')
     self.run_bzr('push -d tree pushed-to')
     # Refresh the branch as 'push' modified it and get the push location
     push_loc = t.branch.bzrdir.open_branch().get_push_location()
     out, err = self.run_bzr('push', working_dir="tree")
     self.assertEqual(
         'Using saved push location: %s\n'
         'No new revisions or tags to push.\n' %
         urlutils.local_path_from_url(push_loc), err)
     out, err = self.run_bzr('push -q', working_dir="tree")
     self.assertEqual('', out)
     self.assertEqual('', err)
Пример #30
0
def pre_commit_script(local, master, old_revno, old_revid, future_revno, future_revid, tree_delta, future_tree):
    """This hook will execute precommit script from root path of the bazaar
    branch. Commit will be canceled if precommit fails."""

    import os, subprocess
    from bzrlib import errors

    base = urlutils.local_path_from_url((local if local else master).base)
    script = os.path.join(base, "precommit")
    # this hook only makes sense if a precommit file exist.
    if not os.path.exists(script):
        return
    try:
        subprocess.check_call(script)

    # if precommit fails (process return not zero) cancel commit.
    except subprocess.CalledProcessError:
        raise errors.BzrError("pre commit check failed.")
Пример #31
0
    def test_init_at_repository_root(self):
        # bzr init at the root of a repository should create a branch
        # and working tree even when creation of working trees is disabled.
        t = self.get_transport()
        t.mkdir('repo')
        format = BzrDirMetaFormat1()
        newdir = format.initialize(t.abspath('repo'))
        repo = newdir.create_repository(shared=True)
        repo.set_make_working_trees(False)
        out, err = self.run_bzr('init repo')
        self.assertEqual("""Created a repository tree (format: %s)
Using shared repository: %s
""" % (self._default_label, urlutils.local_path_from_url(
            repo.bzrdir.root_transport.external_url())), out)
        cwd = osutils.getcwd()
        self.assertEndsWith(out, cwd + '/repo/\n')
        self.assertEqual('', err)
        newdir.open_branch()
        newdir.open_workingtree()
Пример #32
0
    def getBazaarBranch(self):
        """See `ToBzrImportWorker.getBazaarBranch`.

        In addition to the superclass' behaviour, we retrieve bzr-git's
        caches, both legacy and modern, from the import data store and put
        them where bzr-git will find them in the Bazaar tree, that is at
        '.bzr/repository/git.db' and '.bzr/repository/git'.
        """
        branch = PullingImportWorker.getBazaarBranch(self)
        # Fetch the legacy cache from the store, if present.
        self.import_data_store.fetch('git.db', branch.repository._transport)
        # The cache dir from newer bzr-gits is stored as a tarball.
        local_name = 'git-cache.tar.gz'
        if self.import_data_store.fetch(local_name):
            repo_transport = branch.repository._transport
            repo_transport.mkdir('git')
            git_db_dir = os.path.join(local_path_from_url(repo_transport.base),
                                      'git')
            extract_tarball(local_name, git_db_dir)
        return branch
Пример #33
0
    def test_init_at_repository_root(self):
        # bzr init at the root of a repository should create a branch
        # and working tree even when creation of working trees is disabled.
        t = self.get_transport()
        t.mkdir('repo')
        format = BzrDirMetaFormat1()
        newdir = format.initialize(t.abspath('repo'))
        repo = newdir.create_repository(shared=True)
        repo.set_make_working_trees(False)
        out, err = self.run_bzr('init repo')
        self.assertEqual(
            """Created a repository tree (format: %s)
Using shared repository: %s
""" % (self._default_label,
        urlutils.local_path_from_url(
           repo.bzrdir.root_transport.external_url())), out)
        cwd = osutils.getcwd()
        self.assertEndsWith(out, cwd + '/repo/\n')
        self.assertEqual('', err)
        newdir.open_branch()
        newdir.open_workingtree()
Пример #34
0
    def getBazaarBranch(self):
        """See `ImportWorker.getBazaarBranch`.

        In addition to the superclass' behaviour, we retrieve bzr-git's
        caches, both legacy and modern, from the import data store and put
        them where bzr-git will find them in the Bazaar tree, that is at
        '.bzr/repository/git.db' and '.bzr/repository/git'.
        """
        branch = PullingImportWorker.getBazaarBranch(self)
        # Fetch the legacy cache from the store, if present.
        self.import_data_store.fetch(
            'git.db', branch.repository._transport)
        # The cache dir from newer bzr-gits is stored as a tarball.
        local_name = 'git-cache.tar.gz'
        if self.import_data_store.fetch(local_name):
            repo_transport = branch.repository._transport
            repo_transport.mkdir('git')
            git_db_dir = os.path.join(
                local_path_from_url(repo_transport.base), 'git')
            extract_tarball(local_name, git_db_dir)
        return branch
Пример #35
0
    def test_set_push_location(self):
        from bzrlib.config import (locations_config_filename,
                                   ensure_config_dir_exists)
        ensure_config_dir_exists()
        fn = locations_config_filename()
        # write correct newlines to locations.conf
        # by default ConfigObj uses native line-endings for new files
        # but uses already existing line-endings if file is not empty
        f = open(fn, 'wb')
        try:
            f.write('# comment\n')
        finally:
            f.close()

        branch = self.make_branch('.', format='knit')
        branch.set_push_location('foo')
        local_path = urlutils.local_path_from_url(branch.base[:-1])
        self.assertFileEqual(
            "# comment\n"
            "[%s]\n"
            "push_location = foo\n"
            "push_location:policy = norecurse\n" % local_path, fn)
Пример #36
0
    def setUp(self):
        super(SSHTestCase, self).setUp()
        self.disable_directory_isolation()
        tac_handler = SSHServerLayer.getTacHandler()
        self.server = SSHCodeHostingServer(self.scheme, tac_handler)
        self.server.start_server()
        self.addCleanup(self.server.stop_server)

        # Prevent creation of in-process sftp:// and bzr+ssh:// transports --
        # such connections tend to leak threads and occasionally create
        # uncollectable garbage.
        ssh_denier = DenyingServer(['bzr+ssh://', 'sftp://'])
        ssh_denier.start_server()
        self.addCleanup(ssh_denier.stop_server)

        # Create a local branch with one revision
        tree = self.make_branch_and_tree('local')
        self.local_branch = tree.branch
        self.local_branch_path = local_path_from_url(self.local_branch.base)
        self.build_tree(['local/foo'])
        tree.add('foo')
        self.revid = tree.commit('Added foo')
Пример #37
0
    def test_set_push_location(self):
        from bzrlib.config import (locations_config_filename,
                                   ensure_config_dir_exists)
        ensure_config_dir_exists()
        fn = locations_config_filename()
        # write correct newlines to locations.conf
        # by default ConfigObj uses native line-endings for new files
        # but uses already existing line-endings if file is not empty
        f = open(fn, 'wb')
        try:
            f.write('# comment\n')
        finally:
            f.close()

        branch = self.make_branch('.', format='knit')
        branch.set_push_location('foo')
        local_path = urlutils.local_path_from_url(branch.base[:-1])
        self.assertFileEqual("# comment\n"
                             "[%s]\n"
                             "push_location = foo\n"
                             "push_location:policy = norecurse\n" % local_path,
                             fn)
Пример #38
0
    def setUp(self):
        super(SSHTestCase, self).setUp()
        self.disable_directory_isolation()
        tac_handler = SSHServerLayer.getTacHandler()
        self.server = SSHCodeHostingServer(self.scheme, tac_handler)
        self.server.start_server()
        self.addCleanup(self.server.stop_server)

        # Prevent creation of in-process sftp:// and bzr+ssh:// transports --
        # such connections tend to leak threads and occasionally create
        # uncollectable garbage.
        ssh_denier = DenyingServer(['bzr+ssh://', 'sftp://'])
        ssh_denier.start_server()
        self.addCleanup(ssh_denier.stop_server)

        # Create a local branch with one revision
        tree = self.make_branch_and_tree('local')
        self.local_branch = tree.branch
        self.local_branch_path = local_path_from_url(self.local_branch.base)
        self.build_tree(['local/foo'])
        tree.add('foo')
        self.revid = tree.commit('Added foo')
Пример #39
0
 def local_path(path):
     if path.startswith("file://"):
         return urlutils.local_path_from_url(path)
     else:
         return urlutils.unescape(path)
Пример #40
0
    def test_merge_remember(self):
        """Merge changes from one branch to another, test submit location."""
        tree_a = self.make_branch_and_tree('branch_a')
        branch_a = tree_a.branch
        self.build_tree(['branch_a/a'])
        tree_a.add('a')
        tree_a.commit('commit a')
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
        tree_b = branch_b.bzrdir.open_workingtree()
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
        tree_c = branch_c.bzrdir.open_workingtree()
        self.build_tree(['branch_a/b'])
        tree_a.add('b')
        tree_a.commit('commit b')
        self.build_tree(['branch_c/c'])
        tree_c.add('c')
        tree_c.commit('commit c')
        # reset parent
        parent = branch_b.get_parent()
        branch_b.set_parent(None)
        self.assertEqual(None, branch_b.get_parent())
        # test merge for failure without parent set
        out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
        self.assertEquals(out,
                ('','bzr: ERROR: No location specified or remembered\n'))

        # test uncommitted changes
        self.build_tree(['branch_b/d'])
        tree_b.add('d')
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
                           'merge', working_dir='branch_b')

        # merge should now pass and implicitly remember merge location
        tree_b.commit('commit d')
        out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')

        base = urlutils.local_path_from_url(branch_a.base)
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
        # re-open branch as external run_bzr modified it
        branch_b = branch_b.bzrdir.open_branch()
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
                          osutils.abspath(parent))
        # test implicit --remember when committing new file
        self.build_tree(['branch_b/e'])
        tree_b.add('e')
        tree_b.commit('commit e')
        out, err = self.run_bzr('merge', working_dir='branch_b')
        self.assertStartsWith(
            err, 'Merging from remembered submit location %s\n' % (base,))
        # re-open tree as external run_bzr modified it
        tree_b = branch_b.bzrdir.open_workingtree()
        tree_b.commit('merge branch_a')
        # test explicit --remember
        out, err = self.run_bzr('merge ../branch_c --remember',
                                working_dir='branch_b')
        self.assertEquals(out, '')
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
        # re-open branch as external run_bzr modified it
        branch_b = branch_b.bzrdir.open_branch()
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
                          osutils.abspath(branch_c.bzrdir.root_transport.base))
        # re-open tree as external run_bzr modified it
        tree_b = branch_b.bzrdir.open_workingtree()
        tree_b.commit('merge branch_c')