33
from bzrlib.errors import (NotBranchError, NotVersionedError,
33
from bzrlib.errors import (NotBranchError, NotVersionedError,
34
34
UnsupportedOperation)
35
35
from bzrlib.osutils import pathjoin, getcwd
36
36
from bzrlib.tests import TestCase
195
195
('xyz/m', 'm-id'),
198
def test_commit_exclude_pending_merge_fails(self):
199
"""Excludes are a form of partial commit."""
200
wt = self.make_branch_and_tree('.')
201
self.build_tree(['foo'])
203
wt.commit('commit one')
204
wt2 = wt.bzrdir.sprout('to').open_workingtree()
205
wt2.commit('change_right')
206
wt.merge_from_branch(wt2.branch)
207
self.assertRaises(errors.CannotCommitSelectedFileMerge,
208
wt.commit, 'test', exclude=['foo'])
210
def test_commit_exclude_exclude_changed_is_pointless(self):
211
tree = self.make_branch_and_tree('.')
212
self.build_tree(['a'])
213
tree.smart_add(['.'])
214
tree.commit('setup test')
215
self.build_tree_contents([('a', 'new contents for "a"\n')])
216
self.assertRaises(errors.PointlessCommit, tree.commit, 'test',
217
exclude=['a'], allow_pointless=False)
219
def test_commit_exclude_excludes_modified_files(self):
220
tree = self.make_branch_and_tree('.')
221
self.build_tree(['a', 'b', 'c'])
222
tree.smart_add(['.'])
223
tree.commit('test', exclude=['b', 'c'])
224
# If b was excluded it will still be 'added' in status.
226
self.addCleanup(tree.unlock)
227
changes = list(tree.iter_changes(tree.basis_tree()))
228
self.assertEqual(2, len(changes))
229
self.assertEqual((None, 'b'), changes[0][1])
230
self.assertEqual((None, 'c'), changes[1][1])
232
def test_commit_exclude_subtree_of_selected(self):
233
tree = self.make_branch_and_tree('.')
234
self.build_tree(['a/', 'a/b'])
235
tree.smart_add(['.'])
236
tree.commit('test', specific_files=['a'], exclude=['a/b'])
237
# If a/b was excluded it will still be 'added' in status.
239
self.addCleanup(tree.unlock)
240
changes = list(tree.iter_changes(tree.basis_tree()))
241
self.assertEqual(1, len(changes))
242
self.assertEqual((None, 'a/b'), changes[0][1])
198
244
def test_commit_sets_last_revision(self):
199
245
tree = self.make_branch_and_tree('tree')
200
246
committed_id = tree.commit('foo', rev_id='foo')
209
255
self.assertNotEqual(None, committed_id)
211
257
def test_commit_local_unbound(self):
212
# using the library api to do a local commit on unbound branches is
258
# using the library api to do a local commit on unbound branches is
214
260
tree = self.make_branch_and_tree('tree')
215
261
self.assertRaises(errors.LocalRequiresBoundBranch,
398
444
basis.get_reference_revision(basis.path2id('subtree')))
399
445
# the outer tree must have have changed too.
400
446
self.assertNotEqual(None, rev_id)
402
448
def test_nested_commit_second_commit_detects_changes(self):
403
449
"""Commit with a nested tree picks up the correct child revid."""
404
450
tree = self.make_branch_and_tree('.')
450
496
class TestCommitProgress(TestCaseWithWorkingTree):
452
498
def restoreDefaults(self):
453
499
ui.ui_factory = self.old_ui_factory
455
501
def test_commit_progress_steps(self):
456
# during commit we one progress update for every entry in the
502
# during commit we one progress update for every entry in the
457
503
# inventory, and then one for the inventory, and one for the
458
504
# inventory, and one for the revision insertions.
459
# first we need a test commit to do. Lets setup a branch with
505
# first we need a test commit to do. Lets setup a branch with
460
506
# 3 files, and alter one in a selected-file commit. This exercises
461
# a number of cases quickly. We should also test things like
507
# a number of cases quickly. We should also test things like
462
508
# selective commits which excludes newly added files.
463
509
tree = self.make_branch_and_tree('.')
464
510
self.build_tree(['a', 'b', 'c'])
491
537
def test_commit_progress_shows_post_hook_names(self):
492
538
tree = self.make_branch_and_tree('.')
493
# set a progress bar that captures the calls so we can see what is
539
# set a progress bar that captures the calls so we can see what is
495
541
self.old_ui_factory = ui.ui_factory
496
542
self.addCleanup(self.restoreDefaults)
516
562
def test_commit_progress_shows_pre_hook_names(self):
517
563
tree = self.make_branch_and_tree('.')
518
# set a progress bar that captures the calls so we can see what is
564
# set a progress bar that captures the calls so we can see what is
520
566
self.old_ui_factory = ui.ui_factory
521
567
self.addCleanup(self.restoreDefaults)