/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_extract.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from .. import (
 
17
from bzrlib import (
18
18
    branch,
 
19
    bzrdir,
19
20
    errors,
20
21
    )
21
 
from . import TestCaseWithTransport
 
22
from bzrlib.tests import TestCaseWithTransport
22
23
 
23
24
 
24
25
class TestExtract(TestCaseWithTransport):
26
27
    def test_extract(self):
27
28
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d'])
28
29
        wt = self.make_branch_and_tree('a', format='rich-root-pack')
29
 
        wt.add(['b', 'b/c', 'd'], [b'b-id', b'c-id', b'd-id'])
 
30
        wt.add(['b', 'b/c', 'd'], ['b-id', 'c-id', 'd-id'])
30
31
        wt.commit('added files')
31
 
        b_wt = wt.extract('b')
32
 
        self.assertTrue(b_wt.is_versioned(''))
33
 
        if b_wt.supports_setting_file_ids():
34
 
            self.assertEqual(b'b-id', b_wt.path2id(''))
35
 
            self.assertEqual(b'c-id', b_wt.path2id('c'))
36
 
            self.assertEqual('c', b_wt.id2path(b'c-id'))
37
 
            self.assertRaises(errors.BzrError, wt.id2path, b'b-id')
 
32
        b_wt = wt.extract('b-id')
 
33
        self.assertEqual('b-id', b_wt.get_root_id())
 
34
        self.assertEqual('c-id', b_wt.path2id('c'))
 
35
        self.assertEqual('c', b_wt.id2path('c-id'))
 
36
        self.assertRaises(errors.BzrError, wt.id2path, 'b-id')
38
37
        self.assertEqual(b_wt.basedir, wt.abspath('b'))
39
38
        self.assertEqual(wt.get_parent_ids(), b_wt.get_parent_ids())
40
39
        self.assertEqual(wt.branch.last_revision(),
43
42
    def extract_in_checkout(self, a_branch):
44
43
        self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d'])
45
44
        wt = a_branch.create_checkout('a', lightweight=True)
46
 
        wt.add(['b', 'b/c', 'b/c/d'], [b'b-id', b'c-id', b'd-id'])
 
45
        wt.add(['b', 'b/c', 'b/c/d'], ['b-id', 'c-id', 'd-id'])
47
46
        wt.commit('added files')
48
 
        return wt.extract('b')
 
47
        return wt.extract('b-id')
49
48
 
50
49
    def test_extract_in_checkout(self):
51
50
        a_branch = self.make_branch('branch', format='rich-root-pack')
58
57
        a_branch = self.make_branch('branch', format='rich-root-pack')
59
58
        self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d/', 'a/b/c/d/e'])
60
59
        wt = a_branch.create_checkout('a', lightweight=True)
61
 
        wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], [b'b-id', b'c-id', b'd-id',
62
 
                                                   b'e-id'])
 
60
        wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], ['b-id', 'c-id', 'd-id',
 
61
                'e-id'])
63
62
        wt.commit('added files')
64
 
        b_wt = wt.extract('b/c/d')
 
63
        b_wt = wt.extract('d-id')
65
64
        b_branch = branch.Branch.open('branch/b/c/d')
66
65
        b_branch_ref = branch.Branch.open('a/b/c/d')
67
66
        self.assertEqual(b_branch.base, b_branch_ref.base)
69
68
    def test_bad_repo_format(self):
70
69
        repo = self.make_repository('branch', shared=True,
71
70
                                    format='knit')
72
 
        a_branch = repo.controldir.create_branch()
 
71
        a_branch = repo.bzrdir.create_branch()
73
72
        self.assertRaises(errors.RootNotRich, self.extract_in_checkout,
74
73
                          a_branch)
75
74
 
76
75
    def test_good_repo_format(self):
77
76
        repo = self.make_repository('branch', shared=True,
78
 
                                    format='dirstate-with-subtree')
79
 
        a_branch = repo.controldir.create_branch()
 
77
            format='dirstate-with-subtree')
 
78
        a_branch = repo.bzrdir.create_branch()
80
79
        wt_b = self.extract_in_checkout(a_branch)
81
 
        self.assertEqual(wt_b.branch.repository.controldir.transport.base,
82
 
                         repo.controldir.transport.base)
 
80
        self.assertEqual(wt_b.branch.repository.bzrdir.transport.base,
 
81
        repo.bzrdir.transport.base)