6
from bzrlib.selftest import TestCaseInTempDir, TestCase
6
from bzrlib.selftest import InTempDir, TestBase
7
7
from bzrlib.branch import ScratchBranch, Branch
8
8
from bzrlib.errors import NotBranchError, NotVersionedError
11
class TestBranch(TestCaseInTempDir):
13
def test_unknowns(self):
11
class Unknowns(InTempDir):
14
13
b = Branch('.', init=True)
16
15
self.build_tree(['hello.txt',
56
class TestRevisionId(TestCase):
58
def test_validate_revision_id(self):
58
class ValidateRevisionId(TestBase):
59
60
from bzrlib.revision import validate_revision_id
60
61
validate_revision_id('mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
61
63
self.assertRaises(ValueError,
62
64
validate_revision_id,
64
68
self.assertRaises(ValueError,
65
69
validate_revision_id,
66
70
'mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe\n')
67
73
self.assertRaises(ValueError,
68
74
validate_revision_id,
69
75
' mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
70
77
self.assertRaises(ValueError,
71
78
validate_revision_id,
72
79
'Martin Pool <mbp@sourcefrog.net>-20050311061123-96a255005c7c9dbe')
75
class PendingMerges(TestCaseInTempDir):
77
def test_pending_merges(self):
78
"""Tracking pending-merged revisions."""
83
class PendingMerges(InTempDir):
84
"""Tracking pending-merged revisions."""
79
86
b = Branch('.', init=True)
81
88
self.assertEquals(b.pending_merges(), [])
82
b.add_pending_merge('foo@azkhazan-123123-abcabc')
83
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
84
b.add_pending_merge('foo@azkhazan-123123-abcabc')
85
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
90
b.add_pending_merge('foo@azkhazan-123123-abcabc')
92
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
94
b.add_pending_merge('foo@azkhazan-123123-abcabc')
96
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
86
98
b.add_pending_merge('wibble@fofof--20050401--1928390812')
87
99
self.assertEquals(b.pending_merges(),
88
100
['foo@azkhazan-123123-abcabc',
89
101
'wibble@fofof--20050401--1928390812'])
90
103
b.commit("commit from base with two merges")
91
105
rev = b.get_revision(b.revision_history()[0])
92
106
self.assertEquals(len(rev.parents), 2)
93
107
self.assertEquals(rev.parents[0].revision_id,
94
108
'foo@azkhazan-123123-abcabc')
95
109
self.assertEquals(rev.parents[1].revision_id,
96
110
'wibble@fofof--20050401--1928390812')
97
112
# list should be cleared when we do a commit
98
113
self.assertEquals(b.pending_merges(), [])
100
def test_revert(self):
101
"""Test selected-file revert"""
118
class Revert(InTempDir):
119
"""Test selected-file revert"""
102
121
b = Branch('.', init=True)
104
123
self.build_tree(['hello.txt'])
124
143
self.check_file_contents('hello.txt', 'initial hello')
125
144
self.check_file_contents('hello.txt~', 'initial hello')
127
def test_rename_dirs(self):
128
"""Test renaming directories and the files within them."""
148
class RenameDirs(InTempDir):
149
"""Test renaming directories and the files within them."""
129
151
b = Branch('.', init=True)
130
152
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
131
153
b.add(['dir', 'dir/sub', 'dir/sub/file'])
154
176
['newdir', 'newdir/newsub',
155
177
'newdir/newsub/file'])
157
def test_relpath(self):
158
"""test for branch path lookups
160
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
161
job: given a path (either relative to cwd or absolute), work out
162
if it is inside a branch and return the path relative to the base.
182
class BranchPathTestCase(TestBase):
183
"""test for branch path lookups
185
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
186
job: given a path (either relative to cwd or absolute), work out
187
if it is inside a branch and return the path relative to the base.
164
191
from bzrlib.branch import _relpath
165
192
import tempfile, shutil