21
21
from bzrlib import (
25
28
from bzrlib.branch import Branch
26
from bzrlib.bzrdir import BzrDirMetaFormat1
29
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
27
30
from bzrlib.commit import Commit, NullCommitReporter
28
31
from bzrlib.config import BranchConfig
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
32
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed,
34
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
35
from bzrlib.workingtree import WorkingTree
45
38
# TODO: Test commit with some added, and added-but-missing files
91
84
file('hello', 'w').write('hello world')
93
rev1 = wt.commit(message='add hello')
86
wt.commit(message='add hello')
94
87
file_id = wt.path2id('hello')
96
89
file('hello', 'w').write('version 2')
97
rev2 = wt.commit(message='commit 2')
90
wt.commit(message='commit 2')
99
92
eq = self.assertEquals
101
rev = b.repository.get_revision(rev1)
94
rh = b.revision_history()
95
rev = b.repository.get_revision(rh[0])
102
96
eq(rev.message, 'add hello')
104
tree1 = b.repository.revision_tree(rev1)
98
tree1 = b.repository.revision_tree(rh[0])
106
100
text = tree1.get_file_text(file_id)
108
102
self.assertEqual('hello world', text)
110
tree2 = b.repository.revision_tree(rev2)
104
tree2 = b.repository.revision_tree(rh[1])
111
105
tree2.lock_read()
112
106
text = tree2.get_file_text(file_id)
114
108
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())
154
110
def test_missing_commit(self):
155
111
"""Test a commit with a missing file"""
156
112
wt = self.make_branch_and_tree('.')
160
116
wt.commit(message='add hello')
162
118
os.remove('hello')
163
reporter = CapturingReporter()
164
wt.commit('removed hello', rev_id='rev2', reporter=reporter)
166
[('missing', u'hello'), ('deleted', u'hello')],
119
wt.commit('removed hello', rev_id='rev2')
169
121
tree = b.repository.revision_tree('rev2')
170
122
self.assertFalse(tree.has_id('hello-id'))
272
224
eq(tree1.id2path('hello-id'), 'hello')
273
225
eq(tree1.get_file_text('hello-id'), 'contents of hello\n')
274
226
self.assertFalse(tree1.has_filename('fruity'))
275
self.check_tree_shape(tree1, ['hello'])
276
eq(tree1.get_file_revision('hello-id'), 'test@rev-1')
227
self.check_inventory_shape(tree1.inventory, ['hello'])
228
ie = tree1.inventory['hello-id']
229
eq(ie.revision, 'test@rev-1')
278
231
tree2 = b.repository.revision_tree('test@rev-2')
279
232
tree2.lock_read()
280
233
self.addCleanup(tree2.unlock)
281
234
eq(tree2.id2path('hello-id'), 'fruity')
282
235
eq(tree2.get_file_text('hello-id'), 'contents of hello\n')
283
self.check_tree_shape(tree2, ['fruity'])
284
eq(tree2.get_file_revision('hello-id'), 'test@rev-2')
236
self.check_inventory_shape(tree2.inventory, ['fruity'])
237
ie = tree2.inventory['hello-id']
238
eq(ie.revision, 'test@rev-2')
286
240
def test_reused_rev_id(self):
287
241
"""Test that a revision id cannot be reused in a branch"""
317
272
wt.commit('three', rev_id=r3, allow_pointless=False)
320
self.check_tree_shape(wt,
275
self.check_inventory_shape(wt.read_working_inventory(),
321
276
['a/', 'a/hello', 'a/b/'])
322
self.check_tree_shape(b.repository.revision_tree(r3),
277
self.check_inventory_shape(b.repository.get_revision_inventory(r3),
323
278
['a/', 'a/hello', 'a/b/'])
329
284
wt.commit('four', rev_id=r4, allow_pointless=False)
332
self.check_tree_shape(wt, ['a/', 'a/b/hello', 'a/b/'])
287
self.check_inventory_shape(wt.read_working_inventory(),
288
['a/', 'a/b/hello', 'a/b/'])
336
inv = b.repository.get_inventory(r4)
292
inv = b.repository.get_revision_inventory(r4)
337
293
eq(inv['hello-id'].revision, r4)
338
294
eq(inv['a-id'].revision, r1)
339
295
eq(inv['b-id'].revision, r3)
364
320
rev_ids.append(rev_id)
365
321
wt.commit(message='rev %d' % (i+1),
323
eq = self.assertEquals
324
eq(b.revision_history(), rev_ids)
367
325
for i in range(4):
368
self.assertThat(rev_ids[:i+1],
369
MatchesAncestry(b.repository, rev_ids[i]))
326
anc = b.repository.get_ancestry(rev_ids[i])
327
eq(anc, [None] + rev_ids[:i+1])
371
329
def test_commit_new_subdir_child_selective(self):
372
330
wt = self.make_branch_and_tree('.')
450
409
wt = self.make_branch_and_tree('.')
451
410
branch = wt.branch
452
411
wt.commit("base", allow_pointless=True, rev_id='A')
453
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
412
self.failIf(branch.repository.has_signature_for_revision_id('A'))
414
from bzrlib.testament import Testament
455
415
# monkey patch gpg signing mechanism
456
416
bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
457
417
config = MustSignConfig(branch)