21
21
from bzrlib import (
28
25
from bzrlib.branch import Branch
29
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
26
from bzrlib.bzrdir import BzrDirMetaFormat1
30
27
from bzrlib.commit import Commit, NullCommitReporter
31
28
from bzrlib.config import BranchConfig
32
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed,
34
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
35
from bzrlib.workingtree import WorkingTree
29
from bzrlib.errors import (
35
from bzrlib.tests import (
36
TestCaseWithTransport,
39
from bzrlib.tests.features import (
42
from bzrlib.tests.matchers import MatchesAncestry
38
45
# TODO: Test commit with some added, and added-but-missing files
84
91
file('hello', 'w').write('hello world')
86
wt.commit(message='add hello')
93
rev1 = wt.commit(message='add hello')
87
94
file_id = wt.path2id('hello')
89
96
file('hello', 'w').write('version 2')
90
wt.commit(message='commit 2')
97
rev2 = wt.commit(message='commit 2')
92
99
eq = self.assertEquals
94
rh = b.revision_history()
95
rev = b.repository.get_revision(rh[0])
101
rev = b.repository.get_revision(rev1)
96
102
eq(rev.message, 'add hello')
98
tree1 = b.repository.revision_tree(rh[0])
104
tree1 = b.repository.revision_tree(rev1)
100
106
text = tree1.get_file_text(file_id)
102
108
self.assertEqual('hello world', text)
104
tree2 = b.repository.revision_tree(rh[1])
110
tree2 = b.repository.revision_tree(rev2)
105
111
tree2.lock_read()
106
112
text = tree2.get_file_text(file_id)
108
114
self.assertEqual('version 2', text)
116
def test_commit_lossy_native(self):
117
"""Attempt a lossy commit to a native branch."""
118
wt = self.make_branch_and_tree('.')
120
file('hello', 'w').write('hello world')
122
revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
123
self.assertEquals('revid', revid)
125
def test_commit_lossy_foreign(self):
126
"""Attempt a lossy commit to a foreign branch."""
127
test_foreign.register_dummy_foreign_for_test(self)
128
wt = self.make_branch_and_tree('.',
129
format=test_foreign.DummyForeignVcsDirFormat())
131
file('hello', 'w').write('hello world')
133
revid = wt.commit(message='add hello', lossy=True,
134
timestamp=1302659388, timezone=0)
135
self.assertEquals('dummy-v1:1302659388.0-0-UNKNOWN', revid)
137
def test_commit_bound_lossy_foreign(self):
138
"""Attempt a lossy commit to a bzr branch bound to a foreign branch."""
139
test_foreign.register_dummy_foreign_for_test(self)
140
foreign_branch = self.make_branch('foreign',
141
format=test_foreign.DummyForeignVcsDirFormat())
142
wt = foreign_branch.create_checkout("local")
144
file('local/hello', 'w').write('hello world')
146
revid = wt.commit(message='add hello', lossy=True,
147
timestamp=1302659388, timezone=0)
148
self.assertEquals('dummy-v1:1302659388.0-0-0', revid)
149
self.assertEquals('dummy-v1:1302659388.0-0-0',
150
foreign_branch.last_revision())
151
self.assertEquals('dummy-v1:1302659388.0-0-0',
152
wt.branch.last_revision())
110
154
def test_missing_commit(self):
111
155
"""Test a commit with a missing file"""
112
156
wt = self.make_branch_and_tree('.')
116
160
wt.commit(message='add hello')
118
162
os.remove('hello')
119
wt.commit('removed hello', rev_id='rev2')
163
reporter = CapturingReporter()
164
wt.commit('removed hello', rev_id='rev2', reporter=reporter)
166
[('missing', u'hello'), ('deleted', u'hello')],
121
169
tree = b.repository.revision_tree('rev2')
122
170
self.assertFalse(tree.has_id('hello-id'))
224
272
eq(tree1.id2path('hello-id'), 'hello')
225
273
eq(tree1.get_file_text('hello-id'), 'contents of hello\n')
226
274
self.assertFalse(tree1.has_filename('fruity'))
227
self.check_inventory_shape(tree1.inventory, ['hello'])
228
ie = tree1.inventory['hello-id']
229
eq(ie.revision, 'test@rev-1')
275
self.check_tree_shape(tree1, ['hello'])
276
eq(tree1.get_file_revision('hello-id'), 'test@rev-1')
231
278
tree2 = b.repository.revision_tree('test@rev-2')
232
279
tree2.lock_read()
233
280
self.addCleanup(tree2.unlock)
234
281
eq(tree2.id2path('hello-id'), 'fruity')
235
282
eq(tree2.get_file_text('hello-id'), 'contents of hello\n')
236
self.check_inventory_shape(tree2.inventory, ['fruity'])
237
ie = tree2.inventory['hello-id']
238
eq(ie.revision, 'test@rev-2')
283
self.check_tree_shape(tree2, ['fruity'])
284
eq(tree2.get_file_revision('hello-id'), 'test@rev-2')
240
286
def test_reused_rev_id(self):
241
287
"""Test that a revision id cannot be reused in a branch"""
272
317
wt.commit('three', rev_id=r3, allow_pointless=False)
275
self.check_inventory_shape(wt.read_working_inventory(),
320
self.check_tree_shape(wt,
276
321
['a/', 'a/hello', 'a/b/'])
277
self.check_inventory_shape(b.repository.get_inventory(r3),
322
self.check_tree_shape(b.repository.revision_tree(r3),
278
323
['a/', 'a/hello', 'a/b/'])
409
452
wt = self.make_branch_and_tree('.')
410
453
branch = wt.branch
411
454
wt.commit("base", allow_pointless=True, rev_id='A')
412
self.failIf(branch.repository.has_signature_for_revision_id('A'))
455
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
414
from bzrlib.testament import Testament
415
457
# monkey patch gpg signing mechanism
416
458
bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
417
459
config = MustSignConfig(branch)