18
18
"""Tests of simple versioning operations"""
21
from bzrlib.selftest import InTempDir
20
# TODO: test adding a file whose directory is not versioned
21
# TODO: test trying to commit within a directory that is not yet added
25
from bzrlib.selftest import InTempDir, BzrTestBase
26
from bzrlib.branch import Branch
23
29
class Mkdir(InTempDir):
25
31
"""Basic 'bzr mkdir' operation"""
26
32
from bzrlib.commands import run_bzr
29
run_bzr(['bzr', 'init'])
30
run_bzr(['bzr', 'mkdir', 'foo'])
35
run_bzr(['mkdir', 'foo'])
31
36
self.assert_(os.path.isdir('foo'))
33
self.assertRaises(OSError, run_bzr, ['bzr', 'mkdir', 'foo'])
38
self.assertRaises(OSError, run_bzr, ['mkdir', 'foo'])
35
from bzrlib.diff import compare_trees, TreeDelta
40
from bzrlib.diff import compare_trees
36
41
from bzrlib.branch import Branch
39
44
delta = compare_trees(b.basis_tree(), b.working_tree())
46
self.log('delta.added = %r' % delta.added)
41
48
self.assertEquals(len(delta.added), 1)
42
49
self.assertEquals(delta.added[0][0], 'foo')
43
50
self.failIf(delta.modified)
74
class SubdirCommit(BzrTestBase):
76
"""Test committing a subdirectory, and committing within a directory."""
77
run_bzr = self.run_bzr
80
self.build_tree(['a/', 'b/'])
85
for fn in ('a/one', 'b/two', 'top'):
86
file(fn, 'w').write('old contents')
89
run_bzr('commit', '-m', 'first revision')
91
for fn in ('a/one', 'b/two', 'top'):
92
file(fn, 'w').write('new contents')
94
run_bzr('commit', 'a', '-m', 'commit a only')
96
old = b.revision_tree(b.lookup_revision(1))
97
new = b.revision_tree(b.lookup_revision(2))
99
eq(new.get_file_by_path('b/two').read(), 'old contents')
100
eq(new.get_file_by_path('top').read(), 'old contents')
101
eq(new.get_file_by_path('a/one').read(), 'new contents')
104
# commit from here should do nothing
105
run_bzr('commit', '.', '-m', 'commit subdir only', '--unchanged')
106
v3 = b.revision_tree(b.lookup_revision(3))
107
eq(v3.get_file_by_path('b/two').read(), 'old contents')
108
eq(v3.get_file_by_path('top').read(), 'old contents')
109
eq(v3.get_file_by_path('a/one').read(), 'new contents')
111
# commit in subdirectory commits whole tree
112
run_bzr('commit', '-m', 'commit whole tree from subdir')
113
v4 = b.revision_tree(b.lookup_revision(4))
114
eq(v4.get_file_by_path('b/two').read(), 'new contents')
115
eq(v4.get_file_by_path('top').read(), 'new contents')
117
# TODO: factor out some kind of assert_tree_state() method
121
class SubdirAdd(InTempDir):
123
"""Add in subdirectory should add only things from there down"""
125
from bzrlib.branch import Branch
126
from bzrlib.commands import run_bzr
128
eq = self.assertEqual
132
b = Branch('.', init=True)
133
self.build_tree(['src/', 'README'])
135
eq(sorted(b.unknowns()),
138
eq(run_bzr(['add', 'src']), 0)
140
self.build_tree(['src/foo.c'])
143
eq(run_bzr(['add']), 0)
145
eq(sorted(b.unknowns()),
147
eq(len(b.inventory), 3)
150
eq(run_bzr(['add']), 0)
151
eq(list(b.unknowns()), [])