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
21
from . import TestCaseWithTransport
21
from bzrlib.tests import TestCaseWithTransport
24
24
class TestExtract(TestCaseWithTransport):
26
26
def test_extract(self):
27
27
self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d'])
28
28
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'])
29
wt.add(['b', 'b/c', 'd'], ['b-id', 'c-id', 'd-id'])
30
30
wt.commit('added files')
31
b_wt = wt.extract('b', b'b-id')
32
self.assertEqual(b'b-id', b_wt.get_root_id())
33
self.assertEqual(b'c-id', b_wt.path2id('c'))
34
self.assertEqual('c', b_wt.id2path(b'c-id'))
35
self.assertRaises(errors.BzrError, wt.id2path, b'b-id')
31
b_wt = wt.extract('b-id')
32
self.assertEqual('b-id', b_wt.get_root_id())
33
self.assertEqual('c-id', b_wt.path2id('c'))
34
self.assertEqual('c', b_wt.id2path('c-id'))
35
self.assertRaises(errors.BzrError, wt.id2path, 'b-id')
36
36
self.assertEqual(b_wt.basedir, wt.abspath('b'))
37
37
self.assertEqual(wt.get_parent_ids(), b_wt.get_parent_ids())
38
38
self.assertEqual(wt.branch.last_revision(),
41
41
def extract_in_checkout(self, a_branch):
42
42
self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d'])
43
43
wt = a_branch.create_checkout('a', lightweight=True)
44
wt.add(['b', 'b/c', 'b/c/d'], [b'b-id', b'c-id', b'd-id'])
44
wt.add(['b', 'b/c', 'b/c/d'], ['b-id', 'c-id', 'd-id'])
45
45
wt.commit('added files')
46
return wt.extract('b', 'b-id')
46
return wt.extract('b-id')
48
48
def test_extract_in_checkout(self):
49
49
a_branch = self.make_branch('branch', format='rich-root-pack')
56
56
a_branch = self.make_branch('branch', format='rich-root-pack')
57
57
self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d/', 'a/b/c/d/e'])
58
58
wt = a_branch.create_checkout('a', lightweight=True)
59
wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], [b'b-id', b'c-id', b'd-id',
59
wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], ['b-id', 'c-id', 'd-id',
61
61
wt.commit('added files')
62
b_wt = wt.extract('b/c/d', b'd-id')
62
b_wt = wt.extract('d-id')
63
63
b_branch = branch.Branch.open('branch/b/c/d')
64
64
b_branch_ref = branch.Branch.open('a/b/c/d')
65
65
self.assertEqual(b_branch.base, b_branch_ref.base)
67
67
def test_bad_repo_format(self):
68
68
repo = self.make_repository('branch', shared=True,
70
a_branch = repo.controldir.create_branch()
70
a_branch = repo.bzrdir.create_branch()
71
71
self.assertRaises(errors.RootNotRich, self.extract_in_checkout,
74
74
def test_good_repo_format(self):
75
75
repo = self.make_repository('branch', shared=True,
76
76
format='dirstate-with-subtree')
77
a_branch = repo.controldir.create_branch()
77
a_branch = repo.bzrdir.create_branch()
78
78
wt_b = self.extract_in_checkout(a_branch)
79
self.assertEqual(wt_b.branch.repository.controldir.transport.base,
80
repo.controldir.transport.base)
79
self.assertEqual(wt_b.branch.repository.bzrdir.transport.base,
80
repo.bzrdir.transport.base)