35
36
def test_mkdir(self):
36
37
"""Basic 'bzr mkdir' operation"""
38
from bzrlib.commands import run_bzr
39
self.run_bzr('mkdir', 'foo')
41
run_bzr(['mkdir', 'foo'])
40
42
self.assert_(os.path.isdir('foo'))
42
self.run_bzr('mkdir', 'foo', retcode=2)
44
self.assertRaises(OSError, run_bzr, ['mkdir', 'foo'])
44
46
from bzrlib.diff import compare_trees
45
47
from bzrlib.branch import Branch
48
50
delta = compare_trees(b.basis_tree(), b.working_tree())
53
55
self.assertEquals(delta.added[0][0], 'foo')
54
56
self.failIf(delta.modified)
56
def test_branch_add_in_unversioned(self):
58
def test_add_in_unversioned(self):
57
59
"""Try to add a file in an unversioned directory.
59
"bzr add" adds the parent as necessary, but simple branch add
61
smart_add may eventually add the parent as necessary, but simple
62
branch add doesn't do that.
62
64
from bzrlib.branch import Branch
63
65
from bzrlib.errors import NotVersionedError
65
b = Branch.initialize('.')
67
b = Branch('.', init=True)
67
69
self.build_tree(['foo/',
76
def test_add_in_unversioned(self):
77
"""Try to add a file in an unversioned directory.
79
"bzr add" should add the parent(s) as necessary.
81
from bzrlib.branch import Branch
84
b = Branch.initialize('.')
86
self.build_tree(['inertiatic/', 'inertiatic/esp'])
87
eq(list(b.unknowns()), ['inertiatic'])
88
self.run_bzr('add', 'inertiatic/esp')
89
eq(list(b.unknowns()), [])
91
# Multiple unversioned parents
92
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
93
eq(list(b.unknowns()), ['veil'])
94
self.run_bzr('add', 'veil/cerpin/taxt')
95
eq(list(b.unknowns()), [])
97
# Check whacky paths work
98
self.build_tree(['cicatriz/', 'cicatriz/esp'])
99
eq(list(b.unknowns()), ['cicatriz'])
100
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
101
eq(list(b.unknowns()), [])
103
def test_add_in_versioned(self):
104
"""Try to add a file in a versioned directory.
106
"bzr add" should do this happily.
108
from bzrlib.branch import Branch
109
eq = self.assertEqual
111
b = Branch.initialize('.')
113
self.build_tree(['inertiatic/', 'inertiatic/esp'])
114
eq(list(b.unknowns()), ['inertiatic'])
115
self.run_bzr('add', '--no-recurse', 'inertiatic')
116
eq(list(b.unknowns()), ['inertiatic'+os.sep+'esp'])
117
self.run_bzr('add', 'inertiatic/esp')
118
eq(list(b.unknowns()), [])
76
self.check_and_upgrade()
120
79
def test_subdir_add(self):
121
80
"""Add in subdirectory should add only things from there down"""
123
82
from bzrlib.branch import Branch
83
from bzrlib.commands import run_bzr
125
85
eq = self.assertEqual
126
86
ass = self.assert_
129
b = Branch.initialize('.')
89
b = Branch('.', init=True)
130
90
self.build_tree(['src/', 'README'])
132
92
eq(sorted(b.unknowns()),
133
93
['README', 'src'])
135
self.run_bzr('add', 'src')
95
eq(run_bzr(['add', 'src']), 0)
137
97
self.build_tree(['src/foo.c'])
100
eq(run_bzr(['add']), 0)
142
102
eq(sorted(b.unknowns()),
144
104
eq(len(b.inventory), 3)
107
eq(run_bzr(['add']), 0)
148
108
eq(list(b.unknowns()), [])
152
def check_branch(self):
110
self.check_and_upgrade()
113
def check_and_upgrade(self):
153
114
"""After all the above changes, run the check and upgrade commands.
155
116
The upgrade should be a no-op."""
157
118
debug('branch has %d revisions', b.revno())
159
120
debug('check branch...')
160
121
from bzrlib.check import check
124
debug('upgrade branch...')
125
from bzrlib.upgrade import upgrade
128
debug('check branch...')
129
from bzrlib.check import check
165
135
class SubdirCommit(TestCaseInTempDir):
167
137
def test_subdir_commit(self):
186
156
debug('start selective subdir commit')
187
157
run_bzr('commit', 'a', '-m', 'commit a only')
189
old = b.revision_tree(b.get_rev_id(1))
190
new = b.revision_tree(b.get_rev_id(2))
159
old = b.revision_tree(b.lookup_revision(1))
160
new = b.revision_tree(b.lookup_revision(2))
192
162
eq(new.get_file_by_path('b/two').read(), 'old contents')
193
163
eq(new.get_file_by_path('top').read(), 'old contents')
197
167
# commit from here should do nothing
198
168
run_bzr('commit', '.', '-m', 'commit subdir only', '--unchanged')
199
v3 = b.revision_tree(b.get_rev_id(3))
169
v3 = b.revision_tree(b.lookup_revision(3))
200
170
eq(v3.get_file_by_path('b/two').read(), 'old contents')
201
171
eq(v3.get_file_by_path('top').read(), 'old contents')
202
172
eq(v3.get_file_by_path('a/one').read(), 'new contents')
204
174
# commit in subdirectory commits whole tree
205
175
run_bzr('commit', '-m', 'commit whole tree from subdir')
206
v4 = b.revision_tree(b.get_rev_id(4))
176
v4 = b.revision_tree(b.lookup_revision(4))
207
177
eq(v4.get_file_by_path('b/two').read(), 'new contents')
208
178
eq(v4.get_file_by_path('top').read(), 'new contents')