1
# Copyright (C) 2006 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2009, 2011 Canonical Ltd
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
22
from bzrlib.tests import TestCaseWithTransport
21
from . import TestCaseWithTransport
25
24
class TestExtract(TestCaseWithTransport):
27
26
def test_extract(self):
28
27
self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d'])
29
28
wt = self.make_branch_and_tree('a', format='rich-root-pack')
30
wt.add(['b', 'b/c', 'd'], ['b-id', 'c-id', 'd-id'])
29
wt.add(['b', 'b/c', 'd'], [b'b-id', b'c-id', b'd-id'])
31
30
wt.commit('added files')
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')
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')
37
38
self.assertEqual(b_wt.basedir, wt.abspath('b'))
38
39
self.assertEqual(wt.get_parent_ids(), b_wt.get_parent_ids())
39
40
self.assertEqual(wt.branch.last_revision(),
42
43
def extract_in_checkout(self, a_branch):
43
44
self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d'])
44
45
wt = a_branch.create_checkout('a', lightweight=True)
45
wt.add(['b', 'b/c', 'b/c/d'], ['b-id', 'c-id', 'd-id'])
46
wt.add(['b', 'b/c', 'b/c/d'], [b'b-id', b'c-id', b'd-id'])
46
47
wt.commit('added files')
47
return wt.extract('b-id')
48
return wt.extract('b')
49
50
def test_extract_in_checkout(self):
50
51
a_branch = self.make_branch('branch', format='rich-root-pack')
57
58
a_branch = self.make_branch('branch', format='rich-root-pack')
58
59
self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d/', 'a/b/c/d/e'])
59
60
wt = a_branch.create_checkout('a', lightweight=True)
60
wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], ['b-id', 'c-id', 'd-id',
61
wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], [b'b-id', b'c-id', b'd-id',
62
63
wt.commit('added files')
63
b_wt = wt.extract('d-id')
64
b_wt = wt.extract('b/c/d')
64
65
b_branch = branch.Branch.open('branch/b/c/d')
65
66
b_branch_ref = branch.Branch.open('a/b/c/d')
66
67
self.assertEqual(b_branch.base, b_branch_ref.base)
68
69
def test_bad_repo_format(self):
69
70
repo = self.make_repository('branch', shared=True,
71
a_branch = repo.bzrdir.create_branch()
72
a_branch = repo.controldir.create_branch()
72
73
self.assertRaises(errors.RootNotRich, self.extract_in_checkout,
75
76
def test_good_repo_format(self):
76
77
repo = self.make_repository('branch', shared=True,
77
format='dirstate-with-subtree')
78
a_branch = repo.bzrdir.create_branch()
78
format='dirstate-with-subtree')
79
a_branch = repo.controldir.create_branch()
79
80
wt_b = self.extract_in_checkout(a_branch)
80
self.assertEqual(wt_b.branch.repository.bzrdir.transport.base,
81
repo.bzrdir.transport.base)
81
self.assertEqual(wt_b.branch.repository.controldir.transport.base,
82
repo.controldir.transport.base)