예제 #1
0
    def test_mkdir_w_nested_trees(self):
        """'bzr mkdir' with nested trees"""

        self.make_branch_and_tree('.')
        self.make_branch_and_tree('a')
        self.make_branch_and_tree('a/b')

        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
        self.assertTrue(os.path.isdir('dir'))
        self.assertTrue(os.path.isdir('a/dir'))
        self.assertTrue(os.path.isdir('a/b/dir'))

        wt = WorkingTree.open('.')
        wt_a = WorkingTree.open('a')
        wt_b = WorkingTree.open('a/b')

        delta = wt.changes_from(wt.basis_tree())
        self.assertEqual(len(delta.added), 1)
        self.assertEqual(delta.added[0][0], 'dir')
        self.assertFalse(delta.modified)

        delta = wt_a.changes_from(wt_a.basis_tree())
        self.assertEqual(len(delta.added), 1)
        self.assertEqual(delta.added[0][0], 'dir')
        self.assertFalse(delta.modified)

        delta = wt_b.changes_from(wt_b.basis_tree())
        self.assertEqual(len(delta.added), 1)
        self.assertEqual(delta.added[0][0], 'dir')
        self.assertFalse(delta.modified)
예제 #2
0
    def test_mkdir_w_nested_trees(self):
        """'bzr mkdir' with nested trees"""

        self.run_bzr('init')
        os.mkdir('a')
        os.chdir('a')
        self.run_bzr('init')
        os.mkdir('b')
        os.chdir('b')
        self.run_bzr('init')
        os.chdir('../..')

        self.run_bzr('mkdir dir a/dir a/b/dir')
        self.failUnless(os.path.isdir('dir'))
        self.failUnless(os.path.isdir('a/dir'))
        self.failUnless(os.path.isdir('a/b/dir'))

        wt = WorkingTree.open('.')
        wt_a = WorkingTree.open('a')
        wt_b = WorkingTree.open('a/b')

        delta = wt.changes_from(wt.basis_tree())
        self.assertEquals(len(delta.added), 1)
        self.assertEquals(delta.added[0][0], 'dir')
        self.failIf(delta.modified)

        delta = wt_a.changes_from(wt_a.basis_tree())
        self.assertEquals(len(delta.added), 1)
        self.assertEquals(delta.added[0][0], 'dir')
        self.failIf(delta.modified)

        delta = wt_b.changes_from(wt_b.basis_tree())
        self.assertEquals(len(delta.added), 1)
        self.assertEquals(delta.added[0][0], 'dir')
        self.failIf(delta.modified)
예제 #3
0
    def test_mkdir_w_nested_trees(self):
        """'bzr mkdir' with nested trees"""

        self.make_branch_and_tree('.')
        self.make_branch_and_tree('a')
        self.make_branch_and_tree('a/b')

        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
        self.assertTrue(os.path.isdir('dir'))
        self.assertTrue(os.path.isdir('a/dir'))
        self.assertTrue(os.path.isdir('a/b/dir'))

        wt = WorkingTree.open('.')
        wt_a = WorkingTree.open('a')
        wt_b = WorkingTree.open('a/b')

        delta = wt.changes_from(wt.basis_tree())
        self.assertEquals(len(delta.added), 1)
        self.assertEquals(delta.added[0][0], 'dir')
        self.assertFalse(delta.modified)

        delta = wt_a.changes_from(wt_a.basis_tree())
        self.assertEquals(len(delta.added), 1)
        self.assertEquals(delta.added[0][0], 'dir')
        self.assertFalse(delta.modified)

        delta = wt_b.changes_from(wt_b.basis_tree())
        self.assertEquals(len(delta.added), 1)
        self.assertEquals(delta.added[0][0], 'dir')
        self.assertFalse(delta.modified)
예제 #4
0
    def test_init_branch(self):
        out, err = self.run_bzr('init')
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
            self._default_label,), out)
        self.assertEqual('', err)

        # Can it handle subdirectories of branches too ?
        out, err = self.run_bzr('init subdir1')
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
            self._default_label,), out)
        self.assertEqual('', err)
        WorkingTree.open('subdir1')

        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
                            'init subdir2/nothere')
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
        self.assertEqual('', out)

        os.mkdir('subdir2')
        out, err = self.run_bzr('init subdir2')
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
            self._default_label,), out)
        self.assertEqual('', err)
        # init an existing branch.
        out, err = self.run_bzr('init subdir2', retcode=3)
        self.assertEqual('', out)
        self.assertTrue(err.startswith('bzr: ERROR: Already a branch:'))
예제 #5
0
    def test_init_branch(self):
        out, err = self.run_bzr('init')
        self.assertEqual(
            "Created a standalone tree (format: %s)\n" %
            (self._default_label, ), out)
        self.assertEqual('', err)

        # Can it handle subdirectories of branches too ?
        out, err = self.run_bzr('init subdir1')
        self.assertEqual(
            "Created a standalone tree (format: %s)\n" %
            (self._default_label, ), out)
        self.assertEqual('', err)
        WorkingTree.open('subdir1')

        self.run_bzr_error(
            ['Parent directory of subdir2/nothere does not exist'],
            'init subdir2/nothere')
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
        self.assertEqual('', out)

        os.mkdir('subdir2')
        out, err = self.run_bzr('init subdir2')
        self.assertEqual(
            "Created a standalone tree (format: %s)\n" %
            (self._default_label, ), out)
        self.assertEqual('', err)
        # init an existing branch.
        out, err = self.run_bzr('init subdir2', retcode=3)
        self.assertEqual('', out)
        self.assertTrue(err.startswith('bzr: ERROR: Already a branch:'))
예제 #6
0
    def test_init_branch(self):
        out, err = self.run_bzr('init')
        self.assertEqual('', out)
        self.assertEqual('', err)

        # Can it handle subdirectories of branches too ?
        out, err = self.run_bzr('init subdir1')
        self.assertEqual('', out)
        self.assertEqual('', err)
        WorkingTree.open('subdir1')

        self.run_bzr_error(
            ['Parent directory of subdir2/nothere does not exist'],
            'init subdir2/nothere')
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
        self.assertEqual('', out)

        os.mkdir('subdir2')
        out, err = self.run_bzr('init subdir2')
        self.assertEqual('', out)
        self.assertEqual('', err)
        # init an existing branch.
        out, err = self.run_bzr('init subdir2', retcode=3)
        self.assertEqual('', out)
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
예제 #7
0
def update_branches(sourcecode_directory,
                    update_branches,
                    possible_transports=None,
                    tip=False,
                    quiet=False):
    """Update the existing branches in sourcecode."""
    if possible_transports is None:
        possible_transports = []
    # XXX: JonathanLange 2009-11-09: Rather than updating one branch after
    # another, we could instead try to get them in parallel.
    for project, (branch_url, revision,
                  optional) in (update_branches.iteritems()):
        # Update project from branch_url.
        destination = os.path.join(sourcecode_directory, project)
        if not quiet:
            print 'Updating %s to %s' % (project,
                                         _format_revision_name(revision, tip))
        local_tree = WorkingTree.open(destination)
        try:
            remote_branch = Branch.open(
                branch_url, possible_transports=possible_transports)
        except BzrError:
            if optional:
                report_exception(sys.exc_info(), sys.stderr)
                continue
            else:
                raise
        possible_transports.append(remote_branch.bzrdir.root_transport)
        revision_id = get_revision_id(revision, remote_branch, tip)
        try:
            result = local_tree.pull(remote_branch,
                                     stop_revision=revision_id,
                                     overwrite=True,
                                     possible_transports=possible_transports)
        except IncompatibleRepositories:
            # XXX JRV 20100407: Ideally remote_branch.bzrdir._format
            # should be passed into upgrade() to ensure the format is the same
            # locally and remotely. Unfortunately smart server branches
            # have their _format set to RemoteFormat rather than an actual
            # format instance.
            upgrade(destination)
            # Upgraded, repoen working tree
            local_tree = WorkingTree.open(destination)
            result = local_tree.pull(remote_branch,
                                     stop_revision=revision_id,
                                     overwrite=True,
                                     possible_transports=possible_transports)
        if result.old_revid == result.new_revid:
            if not quiet:
                print '  (No change)'
        else:
            if result.old_revno < result.new_revno:
                change = 'Updated'
            else:
                change = 'Reverted'
            if not quiet:
                print '  (%s from %s to %s)' % (change, result.old_revno,
                                                result.new_revno)
예제 #8
0
    def test_new_files(self):
        if sys.platform == 'win32':
            raise TestSkipped('chmod has no effect on win32')

        t = self.make_branch_and_tree('.')
        b = t.branch
        with open('a', 'wb') as f: f.write('foo\n')
        # ensure check_mode_r works with capital-letter file-ids like TREE_ROOT
        t.add('a', 'CAPS-ID')
        t.commit('foo')

        chmod_r('.bzr', 0644, 0755)
        check_mode_r(self, '.bzr', 0644, 0755)

        # although we are modifying the filesystem
        # underneath the objects, they are not locked, and thus it must
        # be safe for most operations. But here we want to observe a
        # mode change in the control bits, which current do not refresh
        # when a new lock is taken out.
        t = WorkingTree.open('.')
        b = t.branch
        self.assertEqualMode(0755, b.control_files._dir_mode)
        self.assertEqualMode(0644, b.control_files._file_mode)
        self.assertEqualMode(0755, b.bzrdir._get_dir_mode())
        self.assertEqualMode(0644, b.bzrdir._get_file_mode())

        # Modifying a file shouldn't break the permissions
        with open('a', 'wb') as f: f.write('foo2\n')
        t.commit('foo2')
        # The mode should be maintained after commit
        check_mode_r(self, '.bzr', 0644, 0755)

        # Adding a new file should maintain the permissions
        with open('b', 'wb') as f: f.write('new b\n')
        t.add('b')
        t.commit('new b')
        check_mode_r(self, '.bzr', 0644, 0755)

        # Recursively update the modes of all files
        chmod_r('.bzr', 0664, 0775)
        check_mode_r(self, '.bzr', 0664, 0775)
        t = WorkingTree.open('.')
        b = t.branch
        self.assertEqualMode(0775, b.control_files._dir_mode)
        self.assertEqualMode(0664, b.control_files._file_mode)
        self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())

        with open('a', 'wb') as f: f.write('foo3\n')
        t.commit('foo3')
        check_mode_r(self, '.bzr', 0664, 0775)

        with open('c', 'wb') as f: f.write('new c\n')
        t.add('c')
        t.commit('new c')
        check_mode_r(self, '.bzr', 0664, 0775)
예제 #9
0
 def test_conflicts(self):
     self.create_conflicts()
     self.run_bzr('merge ../other', retcode=1)
     wt = WorkingTree.open('.')
     self.assertEqual(2, len(wt.conflicts()))
     self.run_bzr('remerge', retcode=1)
     wt = WorkingTree.open('.')
     self.assertEqual(2, len(wt.conflicts()))
     self.run_bzr('remerge hello', retcode=1)
     self.assertEqual(2, len(wt.conflicts()))
예제 #10
0
def update_branches(sourcecode_directory, update_branches,
                    possible_transports=None, tip=False, quiet=False):
    """Update the existing branches in sourcecode."""
    if possible_transports is None:
        possible_transports = []
    # XXX: JonathanLange 2009-11-09: Rather than updating one branch after
    # another, we could instead try to get them in parallel.
    for project, (branch_url, revision, optional) in (
        update_branches.iteritems()):
        # Update project from branch_url.
        destination = os.path.join(sourcecode_directory, project)
        if not quiet:
            print 'Updating %s to %s' % (
                    project, _format_revision_name(revision, tip))
        local_tree = WorkingTree.open(destination)
        try:
            remote_branch = Branch.open(
                branch_url, possible_transports=possible_transports)
        except BzrError:
            if optional:
                report_exception(sys.exc_info(), sys.stderr)
                continue
            else:
                raise
        possible_transports.append(
            remote_branch.bzrdir.root_transport)
        revision_id = get_revision_id(revision, remote_branch, tip)
        try:
            result = local_tree.pull(
                remote_branch, stop_revision=revision_id, overwrite=True,
                possible_transports=possible_transports)
        except IncompatibleRepositories:
            # XXX JRV 20100407: Ideally remote_branch.bzrdir._format
            # should be passed into upgrade() to ensure the format is the same
            # locally and remotely. Unfortunately smart server branches
            # have their _format set to RemoteFormat rather than an actual
            # format instance.
            upgrade(destination)
            # Upgraded, repoen working tree
            local_tree = WorkingTree.open(destination)
            result = local_tree.pull(
                remote_branch, stop_revision=revision_id, overwrite=True,
                possible_transports=possible_transports)
        if result.old_revid == result.new_revid:
            if not quiet:
                print '  (No change)'
        else:
            if result.old_revno < result.new_revno:
                change = 'Updated'
            else:
                change = 'Reverted'
            if not quiet:
                print '  (%s from %s to %s)' % (
                    change, result.old_revno, result.new_revno)
예제 #11
0
    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"
예제 #12
0
def runUpdate(filename):
    branch = "versioning.git"
    REMOTE_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch)
    PUSHTO_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch)
    LOCAL_BRANCH=path.join(gettempdir(),branch)

    # Location of branch on Launchpad
    remote_branch = Branch.open(REMOTE_URL)

    # Location of branch on local system
    local_branch = remote_branch.bzrdir.sprout(LOCAL_BRANCH).open_branch()

    # Change a file in the local branch
    try:
        wf = open(LOCAL_BRANCH + "/src/Build/Version.h", 'w')
        rf = open(filename, 'r')
    except IOError as error:
        raise error
    else:
        wf.write(rf.read())
        wf.close()

    # Commit the change
    tree = WorkingTree.open(LOCAL_BRANCH)
    tree.commit("Update version number")
예제 #13
0
 def test_branch_push_pull_merge_copies_tags(self):
     t = self.make_branch_and_tree('branch1')
     t.commit(allow_pointless=True,
              message='initial commit',
              rev_id='first-revid')
     b1 = t.branch
     b1.tags.set_tag('tag1', 'first-revid')
     # branching copies the tag across
     self.run_bzr('branch branch1 branch2')
     b2 = Branch.open('branch2')
     self.assertEqual(b2.tags.lookup_tag('tag1'), 'first-revid')
     # make a new tag and pull it
     b1.tags.set_tag('tag2', 'twa')
     self.run_bzr('pull -d branch2 branch1')
     self.assertEqual(b2.tags.lookup_tag('tag2'), 'twa')
     # make a new tag and push it
     b1.tags.set_tag('tag3', 'san')
     self.run_bzr('push -d branch1 branch2')
     self.assertEqual(b2.tags.lookup_tag('tag3'), 'san')
     # make a new tag and merge it
     t.commit(allow_pointless=True,
              message='second commit',
              rev_id='second-revid')
     t2 = WorkingTree.open('branch2')
     t2.commit(allow_pointless=True, message='commit in second')
     b1.tags.set_tag('tag4', 'second-revid')
     self.run_bzr('merge -d branch2 branch1')
     self.assertEqual(b2.tags.lookup_tag('tag4'), 'second-revid')
     # pushing to a new location copies the tag across
     self.run_bzr('push -d branch1 branch3')
     b3 = Branch.open('branch3')
     self.assertEqual(b3.tags.lookup_tag('tag1'), 'first-revid')
예제 #14
0
 def test_create_branch(self):
     branch = self.make_branch('branch')
     tree = branch.create_checkout('tree', lightweight=True)
     tree.commit('one', rev_id='rev-1')
     self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
     tree = WorkingTree.open('tree')
     self.assertEndsWith(tree.branch.base, '/branch2/')
예제 #15
0
 def test_merge_pull(self):
     self.pullable_branch()
     os.chdir('a')
     (out, err) = self.run_bzr('merge --pull ../b')
     self.assertContainsRe(out, 'Now on revision 2\\.')
     tree_a = WorkingTree.open('.')
     self.assertEqual([self.id2], tree_a.get_parent_ids())
예제 #16
0
파일: branch.py 프로젝트: Roadmaster/tarmac
    def create_tree(self):
        '''Create the dir and working tree.'''
        try:
            self.logger.debug(
                'Using tree in %(tree_dir)s' % {
                    'tree_dir': self.config.tree_dir})
            if os.path.exists(self.config.tree_dir):
                self.tree = WorkingTree.open(self.config.tree_dir)

                if self.tree.branch.user_url != self.bzr_branch.user_url:
                    self.logger.debug('Tree URLs do not match: %s - %s' % (
                        self.bzr_branch.user_url, self.tree.branch.user_url))
                    raise InvalidWorkingTree(
                        'The `tree_dir` option for the target branch is not a '
                        'lightweight checkout. Please ask a project '
                        'administrator to resolve the issue, and try again.')
            else:
                self.logger.debug('Tree does not exist.  Creating dir')
                # Create the path up to but not including tree_dir if it does
                # not exist.
                parent_dir = os.path.dirname(self.config.tree_dir)
                if not os.path.exists(parent_dir):
                    os.makedirs(parent_dir)
                self.tree = self.bzr_branch.create_checkout(
                    self.config.tree_dir, lightweight=True)
        except AttributeError:
            # Store this so we can rmtree later
            self.temp_tree_dir = tempfile.mkdtemp()
            self.logger.debug(
                'Using temp dir at %(tree_dir)s' % {
                    'tree_dir': self.temp_tree_dir})
            self.tree = self.bzr_branch.create_checkout(self.temp_tree_dir)

        self.cleanup()
예제 #17
0
 def test_branch_stacked_branch_stacked(self):
     """Asking to stack on a stacked branch does work"""
     # We have a mainline
     trunk_tree = self.make_branch_and_tree('target',
         format='1.9')
     trunk_revid = trunk_tree.commit('mainline')
     # and a branch from it which is stacked
     branch_tree = self.make_branch_and_tree('branch',
         format='1.9')
     branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
     # with some work on it
     work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
     branch_revid = work_tree.commit('moar work plz')
     work_tree.branch.push(branch_tree.branch)
     # you can chain branches on from there
     out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
     self.assertEqual('', out)
     self.assertEqual('Created new stacked branch referring to %s.\n' %
         branch_tree.branch.base, err)
     self.assertEqual(branch_tree.branch.base,
         branch.Branch.open('branch2').get_stacked_on_url())
     branch2_tree = WorkingTree.open('branch2')
     branch2_revid = work_tree.commit('work on second stacked branch')
     work_tree.branch.push(branch2_tree.branch)
     self.assertRevisionInRepository('branch2', branch2_revid)
     self.assertRevisionsInBranchRepository(
         [trunk_revid, branch_revid, branch2_revid],
         'branch2')
예제 #18
0
 def test_set_and_get_view_info(self):
     wt = self.make_branch_and_tree('wt')
     view_current = 'view-name'
     view_dict = {
         view_current: ['dir-1'],
         'other-name': ['dir-2']}
     wt.views.set_view_info(view_current, view_dict)
     current, views = wt.views.get_view_info()
     self.assertEquals(view_current, current)
     self.assertEquals(view_dict, views)
     # then reopen the tree and see they're still there
     wt = WorkingTree.open('wt')
     current, views = wt.views.get_view_info()
     self.assertEquals(view_current, current)
     self.assertEquals(view_dict, views)
     # test setting a current view which does not exist
     self.assertRaises(errors.NoSuchView,
         wt.views.set_view_info, 'yet-another', view_dict)
     current, views = wt.views.get_view_info()
     self.assertEquals(view_current, current)
     self.assertEquals(view_dict, views)
     # test clearing the current view
     wt.views.set_view_info(None, view_dict)
     current, views = wt.views.get_view_info()
     self.assertEquals(None, current)
     self.assertEquals(view_dict, views)
예제 #19
0
 def __init__(self, path=None):
     WorkingCopy.__init__(self)
     self.path = path or os.getcwd()
     self.workingtree = WorkingTree.open(self.path)
     self.repository = BazaarRepository(self.workingtree.branch.user_url)
     #self.repository.working_copy = self
     self._current_version = self.repository._repository.revno()
예제 #20
0
    def test_new_files_group_sticky_bit(self):
        if sys.platform == 'win32':
            raise TestSkipped('chmod has no effect on win32')
        elif sys.platform == 'darwin' or 'freebsd' in sys.platform:
            # FreeBSD-based platforms create temp dirs with the 'wheel' group,
            # which users are not likely to be in, and this prevents us from
            # setting the sgid bit
            os.chown(self.test_dir, os.getuid(), os.getgid())

        t = self.make_branch_and_tree('.')
        b = t.branch

        # Test the group sticky bit
        # Recursively update the modes of all files
        chmod_r('.bzr', 0664, 02775)
        check_mode_r(self, '.bzr', 0664, 02775)
        t = WorkingTree.open('.')
        b = t.branch
        self.assertEqualMode(02775, b.control_files._dir_mode)
        self.assertEqualMode(0664, b.control_files._file_mode)
        self.assertEqualMode(02775, b.bzrdir._get_dir_mode())
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())

        with open('a', 'wb') as f: f.write('foo4\n')
        t.commit('foo4')
        check_mode_r(self, '.bzr', 0664, 02775)

        with open('d', 'wb') as f: f.write('new d\n')
        t.add('d')
        t.commit('new d')
        check_mode_r(self, '.bzr', 0664, 02775)
예제 #21
0
    def test_merge_rename_to_temp_before_delete(self):
        """rename to temp before delete, source children before parents

        This case requires that you must not do deletes before
        move-out-of-the-way, and that you must not do children
        after parents:
        
        $ mkdir foo
        $ touch foo/bar
        $ bzr add foo/bar
        $ bzr commit
        $ bzr mv foo/bar bar
        $ rmdir foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree('a')
        os.mkdir('a/foo')
        file('a/foo/bar', 'wb').write('A/FOO/BAR')
        a_wt.add('foo')
        a_wt.add('foo/bar')
        a_wt.commit('added foo/bar')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        b_wt.rename_one('foo/bar', 'bar')
        os.rmdir('b/foo')
        b_wt.remove('foo')
        b_wt.commit('moved foo/bar to bar, deleted foo')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #22
0
 def test_trivial_star_merge(self):
     """Test that merges in a star shape Just Work."""
     # John starts a branch
     self.build_tree(("original/", "original/file1", "original/file2"))
     tree = self.make_branch_and_tree("original")
     branch = tree.branch
     tree.smart_add(["original"])
     tree.commit("start branch.", verbose=False)
     # Mary branches it.
     self.build_tree(("mary/",))
     branch.bzrdir.clone("mary")
     # Now John commits a change
     file = open("original/file1", "wt")
     file.write("John\n")
     file.close()
     tree.commit("change file1")
     # Mary does too
     mary_tree = WorkingTree.open("mary")
     mary_branch = mary_tree.branch
     file = open("mary/file2", "wt")
     file.write("Mary\n")
     file.close()
     mary_tree.commit("change file2")
     # john should be able to merge with no conflicts.
     base = [None, None]
     other = ("mary", -1)
     tree.merge_from_branch(mary_tree.branch)
     self.assertEqual("John\n", open("original/file1", "rt").read())
     self.assertEqual("Mary\n", open("original/file2", "rt").read())
예제 #23
0
 def test_branch_stacked_branch_stacked(self):
     """Asking to stack on a stacked branch does work"""
     # We have a mainline
     trunk_tree = self.make_branch_and_tree('target',
         format='development')
     trunk_revid = trunk_tree.commit('mainline')
     # and a branch from it which is stacked
     branch_tree = self.make_branch_and_tree('branch',
         format='development')
     branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
     # with some work on it
     branch_revid = branch_tree.commit('moar work plz')
     # you can chain branches on from there
     out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
     self.assertEqual('', out)
     self.assertEqual('Created new stacked branch referring to %s.\n' %
         branch_tree.branch.base, err)
     self.assertEqual(branch_tree.branch.base,
         branch.Branch.open('branch2').get_stacked_on_url())
     branch2_tree = WorkingTree.open('branch2')
     branch2_revid = branch2_tree.commit('work on second stacked branch')
     self.assertRevisionInRepository('branch2', branch2_revid)
     self.assertRevisionsInBranchRepository(
         [trunk_revid, branch_revid, branch2_revid],
         'branch2')
예제 #24
0
    def commit(self, mutable_tree):
        # BUG: not run recursively if in above branch not have changes
        if disable_hooks or not self.read_config():
            return

        from bzrlib.workingtree import WorkingTree
        snapshot = []
        for arg in self.config: # url directory [revisionspec]
            wt = WorkingTree.open(pathjoin(self.root, arg[1]))
            if wt.has_changes(wt.basis_tree()):
                cmd = ['ci']
                os.chdir(wt.basedir)
                try:
                    run_bzr_catch_user_errors(cmd)
                finally:
                    os.chdir(self.cwd)

            if len(arg) < 3:
                arg.append('')
            arg[2] = 'revid:' + wt.last_revision()
            arg[1] = self._quoted_if_need(arg[1])
            snapshot.append(' '.join(arg).encode('utf-8'))

        path = pathjoin(self.root, SNAPSHOT_PATH)
        f = open(path, 'w')
        try:
            f.write('\n'.join(snapshot))
        finally:
            f.close()
예제 #25
0
    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()
예제 #26
0
    def test_merge_rename_to_temp_before_delete(self):
        """rename to temp before delete, source children before parents

        This case requires that you must not do deletes before
        move-out-of-the-way, and that you must not do children
        after parents:

        $ mkdir foo
        $ touch foo/bar
        $ bzr add foo/bar
        $ bzr commit
        $ bzr mv foo/bar bar
        $ rmdir foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree("a")
        os.mkdir("a/foo")
        with file("a/foo/bar", "wb") as f:
            f.write("A/FOO/BAR")
        a_wt.add("foo")
        a_wt.add("foo/bar")
        a_wt.commit("added foo/bar")
        self.run_bzr("branch a b")
        b_wt = WorkingTree.open("b")
        b_wt.rename_one("foo/bar", "bar")
        os.rmdir("b/foo")
        b_wt.remove("foo")
        b_wt.commit("moved foo/bar to bar, deleted foo")
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1))
예제 #27
0
    def test_merge_delete_before_rename_to_temp(self):
        """delete before rename to temp

        This case requires that you must not do
        move-out-of-the-way before deletes:
        
        $ touch foo
        $ touch bar
        $ bzr add foo bar
        $ bzr commit
        $ rm foo
        $ bzr rm foo
        $ bzr mv bar foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree('a')
        file('a/foo', 'wb').write('A/FOO')
        file('a/bar', 'wb').write('A/BAR')
        a_wt.add('foo')
        a_wt.add('bar')
        a_wt.commit('added foo and bar')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        os.unlink('b/foo')
        b_wt.remove('foo')
        b_wt.rename_one('bar', 'foo')
        b_wt.commit('deleted foo, renamed bar to foo')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #28
0
    def run(self, merge_type=None, directory="."):
        from bzrlib.plugins.rewrite.rebase import RebaseState1, WorkingTreeRevisionRewriter
        from bzrlib.workingtree import WorkingTree

        wt = WorkingTree.open_containing(directory)[0]
        wt.lock_write()
        try:
            state = RebaseState1(wt)
            replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type)
            # Abort if there are any conflicts
            if len(wt.conflicts()) != 0:
                raise BzrCommandError(
                    gettext(
                        "There are still conflicts present. "
                        "Resolve the conflicts and then run "
                        "'bzr resolve' and try again."
                    )
                )
            # Read plan file
            try:
                replace_map = state.read_plan()[1]
            except NoSuchFile:
                raise BzrCommandError(gettext("No rebase to continue"))
            oldrevid = state.read_active_revid()
            if oldrevid is not None:
                oldrev = wt.branch.repository.get_revision(oldrevid)
                replayer.commit_rebase(oldrev, replace_map[oldrevid][0])
            finish_rebase(state, wt, replace_map, replayer)
        finally:
            wt.unlock()
예제 #29
0
    def test_merge_delete_before_rename_to_temp(self):
        """delete before rename to temp

        This case requires that you must not do
        move-out-of-the-way before deletes:

        $ touch foo
        $ touch bar
        $ bzr add foo bar
        $ bzr commit
        $ rm foo
        $ bzr rm foo
        $ bzr mv bar foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree("a")
        with file("a/foo", "wb") as f:
            f.write("A/FOO")
        with file("a/bar", "wb") as f:
            f.write("A/BAR")
        a_wt.add("foo")
        a_wt.add("bar")
        a_wt.commit("added foo and bar")
        self.run_bzr("branch a b")
        b_wt = WorkingTree.open("b")
        os.unlink("b/foo")
        b_wt.remove("foo")
        b_wt.rename_one("bar", "foo")
        b_wt.commit("deleted foo, renamed bar to foo")
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1))
예제 #30
0
파일: test_tags.py 프로젝트: Distrotech/bzr
 def test_branch_push_pull_merge_copies_tags(self):
     t = self.make_branch_and_tree('branch1')
     t.commit(allow_pointless=True, message='initial commit',
         rev_id='first-revid')
     b1 = t.branch
     b1.tags.set_tag('tag1', 'first-revid')
     # branching copies the tag across
     self.run_bzr('branch branch1 branch2')
     b2 = Branch.open('branch2')
     self.assertEquals(b2.tags.lookup_tag('tag1'), 'first-revid')
     # make a new tag and pull it
     b1.tags.set_tag('tag2', 'twa')
     self.run_bzr('pull -d branch2 branch1')
     self.assertEquals(b2.tags.lookup_tag('tag2'), 'twa')
     # make a new tag and push it
     b1.tags.set_tag('tag3', 'san')
     self.run_bzr('push -d branch1 branch2')
     self.assertEquals(b2.tags.lookup_tag('tag3'), 'san')
     # make a new tag and merge it
     t.commit(allow_pointless=True, message='second commit',
         rev_id='second-revid')
     t2 = WorkingTree.open('branch2')
     t2.commit(allow_pointless=True, message='commit in second')
     b1.tags.set_tag('tag4', 'second-revid')
     self.run_bzr('merge -d branch2 branch1')
     self.assertEquals(b2.tags.lookup_tag('tag4'), 'second-revid')
     # pushing to a new location copies the tag across
     self.run_bzr('push -d branch1 branch3')
     b3 = Branch.open('branch3')
     self.assertEquals(b3.tags.lookup_tag('tag1'), 'first-revid')
예제 #31
0
 def test_create_branch(self):
     branch = self.make_branch('branch')
     tree = branch.create_checkout('tree', lightweight=True)
     tree.commit('one', rev_id='rev-1')
     self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
     tree = WorkingTree.open('tree')
     self.assertEndsWith(tree.branch.base, '/branch2/')
예제 #32
0
    def test_merge_delete_before_rename_to_temp(self):
        """delete before rename to temp

        This case requires that you must not do
        move-out-of-the-way before deletes:

        $ touch foo
        $ touch bar
        $ bzr add foo bar
        $ bzr commit
        $ rm foo
        $ bzr rm foo
        $ bzr mv bar foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree('a')
        with file('a/foo', 'wb') as f:
            f.write('A/FOO')
        with file('a/bar', 'wb') as f:
            f.write('A/BAR')
        a_wt.add('foo')
        a_wt.add('bar')
        a_wt.commit('added foo and bar')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        os.unlink('b/foo')
        b_wt.remove('foo')
        b_wt.rename_one('bar', 'foo')
        b_wt.commit('deleted foo, renamed bar to foo')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #33
0
    def test_merge_create_before_rename(self):
        """create before rename, target parents before children

        This case requires that you must not do move-into-place
        before creates, and that you must not do children after
        parents:

        $ touch foo
        $ bzr add foo
        $ bzr commit
        $ bzr mkdir bar
        $ bzr add bar
        $ bzr mv foo bar/foo
        $ bzr commit
        """
        os.mkdir("a")
        a_wt = self.make_branch_and_tree("a")
        with file("a/foo", "wb") as f:
            f.write("A/FOO")
        a_wt.add("foo")
        a_wt.commit("added foo")
        self.run_bzr("branch a b")
        b_wt = WorkingTree.open("b")
        os.mkdir("b/bar")
        b_wt.add("bar")
        b_wt.rename_one("foo", "bar/foo")
        b_wt.commit("created bar dir, moved foo into bar")
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1))
예제 #34
0
    def test_merge_create_before_rename(self):
        """create before rename, target parents before children

        This case requires that you must not do move-into-place
        before creates, and that you must not do children after
        parents:

        $ touch foo
        $ bzr add foo
        $ bzr commit
        $ bzr mkdir bar
        $ bzr add bar
        $ bzr mv foo bar/foo
        $ bzr commit
        """
        os.mkdir('a')
        a_wt = self.make_branch_and_tree('a')
        with file('a/foo', 'wb') as f:
            f.write('A/FOO')
        a_wt.add('foo')
        a_wt.commit('added foo')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        os.mkdir('b/bar')
        b_wt.add('bar')
        b_wt.rename_one('foo', 'bar/foo')
        b_wt.commit('created bar dir, moved foo into bar')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #35
0
    def test_merge_rename_to_temp_before_delete(self):
        """rename to temp before delete, source children before parents

        This case requires that you must not do deletes before
        move-out-of-the-way, and that you must not do children
        after parents:

        $ mkdir foo
        $ touch foo/bar
        $ bzr add foo/bar
        $ bzr commit
        $ bzr mv foo/bar bar
        $ rmdir foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree('a')
        os.mkdir('a/foo')
        with file('a/foo/bar', 'wb') as f:
            f.write('A/FOO/BAR')
        a_wt.add('foo')
        a_wt.add('foo/bar')
        a_wt.commit('added foo/bar')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        b_wt.rename_one('foo/bar', 'bar')
        os.rmdir('b/foo')
        b_wt.remove('foo')
        b_wt.commit('moved foo/bar to bar, deleted foo')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #36
0
 def test_trivial_star_merge(self):
     """Test that merges in a star shape Just Work."""
     # John starts a branch
     self.build_tree(("original/", "original/file1", "original/file2"))
     tree = self.make_branch_and_tree('original')
     branch = tree.branch
     tree.smart_add(["original"])
     tree.commit("start branch.", verbose=False)
     # Mary branches it.
     self.build_tree(("mary/", ))
     branch.bzrdir.clone("mary")
     # Now John commits a change
     file = open("original/file1", "wt")
     file.write("John\n")
     file.close()
     tree.commit("change file1")
     # Mary does too
     mary_tree = WorkingTree.open('mary')
     mary_branch = mary_tree.branch
     file = open("mary/file2", "wt")
     file.write("Mary\n")
     file.close()
     mary_tree.commit("change file2")
     # john should be able to merge with no conflicts.
     base = [None, None]
     other = ("mary", -1)
     tree.merge_from_branch(mary_tree.branch)
     self.assertEqual("John\n", open("original/file1", "rt").read())
     self.assertEqual("Mary\n", open("original/file2", "rt").read())
예제 #37
0
    def test_merge_rename_before_create(self):
        """rename before create

        This case requires that you must not do creates
        before move-into-place:

        $ touch foo
        $ bzr add foo
        $ bzr commit
        $ bzr mv foo bar
        $ touch foo
        $ bzr add foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree('a')
        with file('a/foo', 'wb') as f:
            f.write('A/FOO')
        a_wt.add('foo')
        a_wt.commit('added foo')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        b_wt.rename_one('foo', 'bar')
        with file('b/foo', 'wb') as f:
            f.write('B/FOO')
        b_wt.add('foo')
        b_wt.commit('moved foo to bar, added new foo')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #38
0
 def test_walkdirs_kernel_like_tree_unknown(self):
     """Walking a kernel sized tree is fast!(150ms)."""
     self.make_kernel_like_tree()
     tree = WorkingTree.open('.')
     # on roberts machine: this originally took:  157ms/4177ms
     # plain os.walk takes 213ms on this tree
     self.time(list, tree.walkdirs())
예제 #39
0
    def test_merge_rename_before_create(self):
        """rename before create
        
        This case requires that you must not do creates
        before move-into-place:

        $ touch foo
        $ bzr add foo
        $ bzr commit
        $ bzr mv foo bar
        $ touch foo
        $ bzr add foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree('a')
        file('a/foo', 'wb').write('A/FOO')
        a_wt.add('foo')
        a_wt.commit('added foo')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        b_wt.rename_one('foo', 'bar')
        file('b/foo', 'wb').write('B/FOO')
        b_wt.add('foo')
        b_wt.commit('moved foo to bar, added new foo')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #40
0
    def test_content_filtering_applied_on_merge(self):
        # Create a source branch with two revisions
        source, fileid_1, fileid_2, fileid_3, fileid_4 = \
            self.create_cf_tree_with_two_revisions(txt_reader=None,
            txt_writer=None, dir='source')
        if not source.supports_content_filtering():
            return
        self.assert_basis_content("Foo ROCKS!", source, fileid_1)
        self.assertFileEqual("Foo ROCKS!", 'source/file1.txt')
        self.assert_basis_content("Foo Bin", source, fileid_2)
        self.assert_basis_content("Hello World", source, fileid_4)
        self.assertFileEqual("Hello World", 'source/file4.txt')

        # Now patch in content filtering and branch from revision 1
        self.patch_in_content_filter()
        self.run_bzr('branch -r1 source target')
        target = WorkingTree.open('target')
        self.assert_basis_content("Foo Txt", target, fileid_1)
        self.assertFileEqual("fOO tXT", 'target/file1.txt')
        self.assertFileEqual("Foo Bin", 'target/file2.bin')
        self.assertFileEqual("bAR tXT", 'target/file3.txt')

        # Merge the latter change and check the target tree is updated
        self.run_bzr('merge -d target source')
        self.assertFileEqual("fOO rocks!", 'target/file1.txt')
        self.assertFileEqual("hELLO wORLD", 'target/file4.txt')

        # Commit the merge and check the right content is stored
        target.commit("merge file1.txt changes from source")
        self.assert_basis_content("Foo ROCKS!", target, fileid_1)
        self.assert_basis_content("Hello World", target, fileid_4)
예제 #41
0
    def test_merge_create_before_rename(self):
        """create before rename, target parents before children

        This case requires that you must not do move-into-place
        before creates, and that you must not do children after
        parents:

        $ touch foo
        $ bzr add foo
        $ bzr commit
        $ bzr mkdir bar
        $ bzr add bar
        $ bzr mv foo bar/foo
        $ bzr commit
        """
        os.mkdir('a')
        a_wt = self.make_branch_and_tree('a')
        file('a/foo', 'wb').write('A/FOO')
        a_wt.add('foo')
        a_wt.commit('added foo')
        self.run_bzr('branch a b')
        b_wt = WorkingTree.open('b')
        os.mkdir('b/bar')
        b_wt.add('bar')
        b_wt.rename_one('foo', 'bar/foo')
        b_wt.commit('created bar dir, moved foo into bar')
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
                               b_wt.branch.get_rev_id(1))
예제 #42
0
    def test_merge_rename_before_create(self):
        """rename before create

        This case requires that you must not do creates
        before move-into-place:

        $ touch foo
        $ bzr add foo
        $ bzr commit
        $ bzr mv foo bar
        $ touch foo
        $ bzr add foo
        $ bzr commit
        """
        a_wt = self.make_branch_and_tree("a")
        with file("a/foo", "wb") as f:
            f.write("A/FOO")
        a_wt.add("foo")
        a_wt.commit("added foo")
        self.run_bzr("branch a b")
        b_wt = WorkingTree.open("b")
        b_wt.rename_one("foo", "bar")
        with file("b/foo", "wb") as f:
            f.write("B/FOO")
        b_wt.add("foo")
        b_wt.commit("moved foo to bar, added new foo")
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1))
예제 #43
0
파일: repo.py 프로젝트: brtsz/zato
    def _update(self, top_level_elem, elems, location, before_commit_msg, commit_msg,
                after_commit_msg):
        """ A common utility method for updating a YAML file in the server's
        Bazaar repo.
        """

        # TODO: Commit message could be a tad smarter and might include some
        # hints as to what gets committed to repo.

        # TODO: Move it elsewhere, to a separate 'init' method (or investigage
        # why creating the 'tree' object in 'ensure_repo_consistency is not
        # enough - possibly because we're using subprocesses and our own process
        # is not the same that ensure_repo_consistency has been called in).
        if not hasattr(self, "tree"):
            self.tree = WorkingTree.open(self.repo_location)

        data = {}
        data[top_level_elem] = elems

        data_pprinted = pprint(data)
        output = dump(data, Dumper=Dumper, default_flow_style=False)

        logger.debug(before_commit_msg)
        logger.debug("data_pprinted=[%s], output=[%s], location=[%s]" % (data_pprinted, output, location))

        open(location, "w").write(output)
        self.tree.commit(commit_msg)

        logger.debug(after_commit_msg)
예제 #44
0
 def test_initialize(self):
     # initialize should create a working tree and branch in an existing dir
     t = self.make_branch_and_tree('.')
     b = branch.Branch.open('.')
     self.assertEqual(t.branch.base, b.base)
     t2 = WorkingTree.open('.')
     self.assertEqual(t.basedir, t2.basedir)
     self.assertEqual(b.base, t2.branch.base)
예제 #45
0
 def test_remove_with_new_in_dir1(self):
     tree = self._make_add_and_assert_tree(files)
     self.run_bzr('remove --new --keep b b/c',
                  error_regexes=["removed b", "removed b/c"])
     tree = WorkingTree.open('.')
     self.assertInWorkingTree(a)
     self.assertEqual(tree.path2id(a), a + _id)
     self.assertFilesUnversioned([b,c])
예제 #46
0
 def run(self, file_list):
     wt = WorkingTree.open_containing('.')
     # Create the files if they don't exist.
     for filename in file_list:
         filepath = os.path.join(os.getcwd(), filename)
         fd = os.open(filepath, FLAGS, 0666)
         os.close(fd)
     wt[0].smart_add(file_list, recurse=False)
예제 #47
0
 def test_remove_with_new_in_dir1(self):
     tree = self._make_tree_and_add(files)
     self.run_bzr('remove --new --keep b b/c',
                  error_regexes=["removed b", "removed b/c"])
     tree = WorkingTree.open('.')
     self.assertInWorkingTree(a)
     self.assertEqual(tree.path2id(a), a + _id)
     self.assertFilesUnversioned([b, c])
예제 #48
0
 def test_initialize(self):
     # initialize should create a working tree and branch in an existing dir
     t = self.make_branch_and_tree('.')
     b = branch.Branch.open('.')
     self.assertEqual(t.branch.base, b.base)
     t2 = WorkingTree.open('.')
     self.assertEqual(t.basedir, t2.basedir)
     self.assertEqual(b.base, t2.branch.base)
예제 #49
0
    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()
예제 #50
0
    def test_smoke_update_checkout_bound_branch_local_commits(self):
        # smoke test for doing an update of a checkout of a bound
        # branch with local commits.
        master = self.make_branch_and_tree('master')
        # make a bound branch
        self.run_bzr('checkout master child')
        # get an object form of child
        child = WorkingTree.open('child')
        # check that out
        self.run_bzr('checkout --lightweight child checkout')
        # get an object form of the checkout to manipulate
        wt = WorkingTree.open('checkout')
        # change master
        a_file = file('master/file', 'wt')
        a_file.write('Foo')
        a_file.close()
        master.add(['file'])
        master_tip = master.commit('add file')
        # change child
        a_file = file('child/file_b', 'wt')
        a_file.write('Foo')
        a_file.close()
        child.add(['file_b'])
        child_tip = child.commit('add file_b', local=True)
        # check checkout
        a_file = file('checkout/file_c', 'wt')
        a_file.write('Foo')
        a_file.close()
        wt.add(['file_c'])

        # now, update checkout ->
        # get all three files and a pending merge.
        out, err = self.run_bzr('update checkout')
        self.assertEqual('', out)
        self.assertContainsRe(err, '\+N  file')
        self.assertContainsRe(err, '\+N  file_b')
        self.assertContainsRe(
            err, 'Updated to revision 1.\n'
            'Your local commits will now show as'
            ' pending merges')
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
        self.failUnlessExists('checkout/file')
        self.failUnlessExists('checkout/file_b')
        self.failUnlessExists('checkout/file_c')
        self.assertTrue(wt.has_filename('file_c'))
예제 #51
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)
예제 #52
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)
예제 #53
0
 def test_create_branch_short_name(self):
     branch = self.make_branch('branch')
     tree = branch.create_checkout('tree', lightweight=True)
     tree.commit('one', rev_id='rev-1')
     self.run_bzr('switch -b branch2', working_dir='tree')
     tree = WorkingTree.open('tree')
     # The new branch should have been created at the same level as
     # 'branch', because we did not have a '/' segment
     self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
예제 #54
0
 def run(self, text=False):
     from bzrlib.workingtree import WorkingTree
     wt = WorkingTree.open_containing(u'.')[0]
     for conflict in wt.conflicts():
         if text:
             if conflict.typestring != 'text conflict':
                 continue
             self.outf.write(conflict.path + '\n')
         else:
             self.outf.write(str(conflict) + '\n')
예제 #55
0
 def run(self, threshold=55, dry_run=False):
     from bzrlib.workingtree import WorkingTree
     tree = WorkingTree.open_containing('.')[0]
     tree.lock_write()
     try:
         self.tree = tree
         self.basis_tree = tree.basis_tree()
         self._detect_moves(threshold / 100.0, dry_run)
     finally:
         tree.unlock()
예제 #56
0
    def test_cant_write_to_readonly_branch(self):
        # We can't write to a read-only branch.
        self.createBazaarBranch('mark', '+junk', 'ro-branch')

        # Create a new revision on the local branch.
        tree = WorkingTree.open(self.local_branch.base)
        tree.commit('Empty commit', rev_id='rev2')

        # Push the local branch to the remote url
        remote_url = self.getTransportURL('~mark/+junk/ro-branch')
        self.assertCantPush(self.local_branch_path, remote_url)
예제 #57
0
    def test_push_create_prefix(self):
        """'bzr push --create-prefix' will create leading directories."""
        tree = self.create_simple_tree()

        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
                           'push ../new/tree',
                           working_dir='tree')
        self.run_bzr('push ../new/tree --create-prefix', working_dir='tree')
        new_tree = WorkingTree.open('new/tree')
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
        self.failUnlessExists('new/tree/a')
예제 #58
0
 def __init__(self, path=None):
     WorkingCopy.__init__(self, path)
     try:
         self.workingtree = WorkingTree.open(self.path)
     except NotBranchError:
         pass
     else:
         self.repository = BazaarRepository(
             self.workingtree.branch.user_url)
         #self.repository.working_copy = self
         self._current_version = self.repository._repository.revno()