1
# Copyright (C) 2006 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests of the WorkingTree.unversion API."""
19
from bzrlib import errors
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
23
class TestUnversion(TestCaseWithWorkingTree):
25
def test_unversion_requires_write_lock(self):
26
"""WT.unversion([]) in a read lock raises ReadOnlyError."""
27
tree = self.make_branch_and_tree('.')
29
self.assertRaises(errors.ReadOnlyError, tree.unversion, [])
32
def test_unversion_missing_file(self):
33
"""WT.unversion(['missing-id']) raises NoSuchId."""
34
tree = self.make_branch_and_tree('.')
35
self.assertRaises(errors.NoSuchId, tree.unversion, ['missing-id'])
37
def test_unversion_several_files(self):
38
"""After unversioning several files, they should not be versioned."""
39
tree = self.make_branch_and_tree('.')
40
self.build_tree(['a', 'b', 'c'])
41
tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
42
# within a lock unversion should take effect
44
tree.unversion(['a-id', 'b-id'])
45
self.assertFalse(tree.has_id('a-id'))
46
self.assertFalse(tree.has_id('b-id'))
47
self.assertTrue(tree.has_id('c-id'))
48
self.assertTrue(tree.has_filename('a'))
49
self.assertTrue(tree.has_filename('b'))
50
self.assertTrue(tree.has_filename('c'))
52
# the changes should have persisted to disk - reopen the workingtree
54
tree = tree.bzrdir.open_workingtree()
55
self.assertFalse(tree.has_id('a-id'))
56
self.assertFalse(tree.has_id('b-id'))
57
self.assertTrue(tree.has_id('c-id'))
58
self.assertTrue(tree.has_filename('a'))
59
self.assertTrue(tree.has_filename('b'))
60
self.assertTrue(tree.has_filename('c'))
62
def test_unversion_subtree(self):
63
"""Unversioning the root of a subtree unversions the entire subtree."""
64
tree = self.make_branch_and_tree('.')
65
self.build_tree(['a/', 'a/b', 'c'])
66
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
67
# within a lock unversion should take effect
69
tree.unversion(['a-id'])
70
self.assertFalse(tree.has_id('a-id'))
71
self.assertFalse(tree.has_id('b-id'))
72
self.assertTrue(tree.has_id('c-id'))
73
self.assertTrue(tree.has_filename('a'))
74
self.assertTrue(tree.has_filename('a/b'))
75
self.assertTrue(tree.has_filename('c'))