1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# Copyright (C) 2006 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests of the WorkingTree.unversion API."""
from bzrlib import errors
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
class TestUnversion(TestCaseWithWorkingTree):
def test_unversion_requires_write_lock(self):
"""WT.unversion([]) in a read lock raises ReadOnlyError."""
tree = self.make_branch_and_tree('.')
tree.lock_read()
self.assertRaises(errors.ReadOnlyError, tree.unversion, [])
tree.unlock()
def test_unversion_missing_file(self):
"""WT.unversion(['missing-id']) raises NoSuchId."""
tree = self.make_branch_and_tree('.')
self.assertRaises(errors.NoSuchId, tree.unversion, ['missing-id'])
def test_unversion_several_files(self):
"""After unversioning several files, they should not be versioned."""
tree = self.make_branch_and_tree('.')
self.build_tree(['a', 'b', 'c'])
tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
# within a lock unversion should take effect
tree.lock_write()
tree.unversion(['a-id', 'b-id'])
self.assertFalse(tree.has_id('a-id'))
self.assertFalse(tree.has_id('b-id'))
self.assertTrue(tree.has_id('c-id'))
self.assertTrue(tree.has_filename('a'))
self.assertTrue(tree.has_filename('b'))
self.assertTrue(tree.has_filename('c'))
tree.unlock()
# the changes should have persisted to disk - reopen the workingtree
# to be sure.
tree = tree.bzrdir.open_workingtree()
tree.lock_read()
self.assertFalse(tree.has_id('a-id'))
self.assertFalse(tree.has_id('b-id'))
self.assertTrue(tree.has_id('c-id'))
self.assertTrue(tree.has_filename('a'))
self.assertTrue(tree.has_filename('b'))
self.assertTrue(tree.has_filename('c'))
tree.unlock()
def test_unversion_subtree(self):
"""Unversioning the root of a subtree unversions the entire subtree."""
tree = self.make_branch_and_tree('.')
self.build_tree(['a/', 'a/b', 'c'])
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
# within a lock unversion should take effect
tree.lock_write()
tree.unversion(['a-id'])
self.assertFalse(tree.has_id('a-id'))
self.assertFalse(tree.has_id('b-id'))
self.assertTrue(tree.has_id('c-id'))
self.assertTrue(tree.has_filename('a'))
self.assertTrue(tree.has_filename('a/b'))
self.assertTrue(tree.has_filename('c'))
tree.unlock()
def test_unversion_subtree_and_children(self):
"""Passing a child id will raise NoSuchId.
This is because the parent directory will have already been removed.
"""
tree = self.make_branch_and_tree('.')
self.build_tree(['a/', 'a/b', 'a/c', 'd'])
tree.add(['a', 'a/b', 'a/c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
tree.lock_write()
try:
tree.unversion(['b-id', 'a-id'])
self.assertFalse(tree.has_id('a-id'))
self.assertFalse(tree.has_id('b-id'))
self.assertFalse(tree.has_id('c-id'))
self.assertTrue(tree.has_id('d-id'))
# The files are still on disk
self.assertTrue(tree.has_filename('a'))
self.assertTrue(tree.has_filename('a/b'))
self.assertTrue(tree.has_filename('a/c'))
self.assertTrue(tree.has_filename('d'))
finally:
tree.unlock()
|