1
# Copyright (C) 2006, 2007, 2009, 2011 Canonical Ltd
1
# Copyright (C) 2006 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
21
from . import TestCaseWithTransport
22
from bzrlib.tests import TestCaseWithTransport
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')
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',
60
wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], ['b-id', 'c-id', 'd-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,
72
a_branch = repo.controldir.create_branch()
71
a_branch = repo.bzrdir.create_branch()
73
72
self.assertRaises(errors.RootNotRich, self.extract_in_checkout,
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)