~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
2
#
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.
7
#
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.
12
#
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
16
17
"""Tests of the WorkingTree.unversion API."""
18
19
from bzrlib import errors
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
21
22
23
class TestUnversion(TestCaseWithWorkingTree):
24
25
    def test_unversion_requires_write_lock(self):
26
        """WT.unversion([]) in a read lock raises ReadOnlyError."""
27
        tree = self.make_branch_and_tree('.')
28
        tree.lock_read()
29
        self.assertRaises(errors.ReadOnlyError, tree.unversion, [])
30
        tree.unlock()
31
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'])
36
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
43
        tree.lock_write()
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'))
51
        tree.unlock()
1988.2.3 by Robert Collins
Merge in commit test case for deletion-heuristic.
52
        # the changes should have persisted to disk - reopen the workingtree
53
        # to be sure.
54
        tree = tree.bzrdir.open_workingtree()
2255.2.46 by Robert Collins
Dirstate - unversion should set the tree state as dirty.
55
        tree.lock_read()
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
56
        self.assertFalse(tree.has_id('a-id'))
57
        self.assertFalse(tree.has_id('b-id'))
58
        self.assertTrue(tree.has_id('c-id'))
59
        self.assertTrue(tree.has_filename('a'))
60
        self.assertTrue(tree.has_filename('b'))
61
        self.assertTrue(tree.has_filename('c'))
2255.2.46 by Robert Collins
Dirstate - unversion should set the tree state as dirty.
62
        tree.unlock()
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
63
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
64
    def test_unversion_subtree(self):
65
        """Unversioning the root of a subtree unversions the entire subtree."""
66
        tree = self.make_branch_and_tree('.')
67
        self.build_tree(['a/', 'a/b', 'c'])
68
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
69
        # within a lock unversion should take effect
70
        tree.lock_write()
71
        tree.unversion(['a-id'])
72
        self.assertFalse(tree.has_id('a-id'))
73
        self.assertFalse(tree.has_id('b-id'))
74
        self.assertTrue(tree.has_id('c-id'))
75
        self.assertTrue(tree.has_filename('a'))
76
        self.assertTrue(tree.has_filename('a/b'))
77
        self.assertTrue(tree.has_filename('c'))
78
        tree.unlock()
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
79
80
    def test_unversion_subtree_and_children(self):
81
        """Passing a child id will raise NoSuchId.
82
83
        This is because the parent directory will have already been removed.
84
        """
85
        tree = self.make_branch_and_tree('.')
86
        self.build_tree(['a/', 'a/b', 'a/c', 'd'])
87
        tree.add(['a', 'a/b', 'a/c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
88
        tree.lock_write()
89
        try:
90
            tree.unversion(['b-id', 'a-id'])
91
            self.assertFalse(tree.has_id('a-id'))
92
            self.assertFalse(tree.has_id('b-id'))
93
            self.assertFalse(tree.has_id('c-id'))
94
            self.assertTrue(tree.has_id('d-id'))
95
            # The files are still on disk
96
            self.assertTrue(tree.has_filename('a'))
97
            self.assertTrue(tree.has_filename('a/b'))
98
            self.assertTrue(tree.has_filename('a/c'))
99
            self.assertTrue(tree.has_filename('d'))
100
        finally:
101
            tree.unlock()