/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_executable.py

  • Committer: Jan Balster
  • Date: 2006-08-15 12:39:42 UTC
  • mfrom: (1923 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1928.
  • Revision ID: jan@merlinux.de-20060815123942-22c388c6e9a8ac91
merge bzr.dev 1923

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
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
"""Test the executable bit under various working tree formats."""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib.inventory import InventoryFile
 
22
from bzrlib.transform import TreeTransform
 
23
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
24
 
 
25
 
 
26
class TestExecutable(TestCaseWithWorkingTree):
 
27
 
 
28
    def setUp(self):
 
29
        super(TestExecutable, self).setUp()
 
30
 
 
31
        self.a_id = "a-20051208024829-849e76f7968d7a86"
 
32
        self.b_id = "b-20051208024829-849e76f7968d7a86"
 
33
        wt = self.make_branch_and_tree('b1')
 
34
        b = wt.branch
 
35
        tt = TreeTransform(wt)
 
36
        tt.new_file('a', tt.root, 'a test\n', self.a_id, True)
 
37
        tt.new_file('b', tt.root, 'b test\n', self.b_id, False)
 
38
        tt.apply()
 
39
 
 
40
        self.wt = wt
 
41
 
 
42
    def check_exist(self, tree):
 
43
        """Just check that both files have the right executable bits set"""
 
44
        measured = []
 
45
        for cn, ie in tree.inventory.iter_entries():
 
46
            if isinstance(ie, InventoryFile):
 
47
                measured.append((cn, ie.executable))
 
48
        self.assertEqual([('a', True), ('b', False)], measured)
 
49
        self.failUnless(tree.is_executable(self.a_id),
 
50
                        "'a' lost the execute bit")
 
51
        self.failIf(tree.is_executable(self.b_id),
 
52
                    "'b' gained an execute bit")
 
53
 
 
54
    def check_empty(self, tree, ignore_inv=False):
 
55
        """Check that the files are truly missing
 
56
        :param ignore_inv: If you just delete files from a working tree
 
57
                the inventory still shows them, so don't assert that
 
58
                the inventory is empty, just that the tree doesn't have them
 
59
        """
 
60
        if not ignore_inv:
 
61
            self.assertEqual(
 
62
                [('', tree.inventory.root)],
 
63
                list(tree.inventory.iter_entries()))
 
64
        self.failIf(tree.has_id(self.a_id))
 
65
        self.failIf(tree.has_filename('a'))
 
66
        self.failIf(tree.has_id(self.b_id))
 
67
        self.failIf(tree.has_filename('b'))
 
68
 
 
69
    def commit_and_branch(self):
 
70
        """Commit the current tree, and create a second tree"""
 
71
        self.wt.commit('adding a,b', rev_id='r1')
 
72
 
 
73
        # Now make sure that 'bzr branch' also preserves the
 
74
        # executable bit
 
75
        # TODO: Maybe this should be a blackbox test
 
76
        dir2 = self.wt.branch.bzrdir.clone('b2', revision_id='r1')
 
77
        wt2 = dir2.open_workingtree()
 
78
        self.assertEqual('r1', wt2.last_revision())
 
79
        self.assertEqual('r1', wt2.branch.last_revision())
 
80
        return wt2
 
81
 
 
82
    def test_01_is_executable(self):
 
83
        """Make sure that the tree was created and has the executable bit set"""
 
84
        self.check_exist(self.wt)
 
85
 
 
86
    def test_02_stays_executable(self):
 
87
        """reopen the tree and ensure it stuck."""
 
88
        self.wt = self.wt.bzrdir.open_workingtree()
 
89
        self.check_exist(self.wt)
 
90
 
 
91
    def test_03_after_commit(self):
 
92
        """Commit the change, and check the history"""
 
93
        self.wt.commit('adding a,b', rev_id='r1')
 
94
 
 
95
        rev_tree = self.wt.branch.repository.revision_tree('r1')
 
96
        self.check_exist(rev_tree)
 
97
 
 
98
    def test_04_after_removed(self):
 
99
        """Make sure reverting removed files brings them back correctly"""
 
100
        self.wt.commit('adding a,b', rev_id='r1')
 
101
 
 
102
        # Make sure the entries are gone
 
103
        os.remove('b1/a')
 
104
        os.remove('b1/b')
 
105
        self.check_empty(self.wt, ignore_inv=True)
 
106
 
 
107
        # Make sure that revert is able to bring them back,
 
108
        # and sets 'a' back to being executable
 
109
 
 
110
        rev_tree = self.wt.branch.repository.revision_tree('r1')
 
111
 
 
112
        self.wt.revert(['a', 'b'], rev_tree, backups=False)
 
113
        self.check_exist(self.wt)
 
114
 
 
115
    def test_05_removed_and_committed(self):
 
116
        """Check that reverting to an earlier commit restores them"""
 
117
        self.wt.commit('adding a,b', rev_id='r1')
 
118
 
 
119
        # Now remove them again, and make sure that after a
 
120
        # commit, they are still marked correctly
 
121
        os.remove('b1/a')
 
122
        os.remove('b1/b')
 
123
        self.wt.commit('removed', rev_id='r2')
 
124
 
 
125
        self.check_empty(self.wt)
 
126
 
 
127
        rev_tree = self.wt.branch.repository.revision_tree('r1')
 
128
        # Now revert back to the previous commit
 
129
        self.wt.revert([], rev_tree, backups=False)
 
130
 
 
131
        self.check_exist(self.wt)
 
132
 
 
133
    def test_06_branch(self):
 
134
        """branch b1=>b2 should preserve the executable bits"""
 
135
        # TODO: Maybe this should be a blackbox test
 
136
        wt2 = self.commit_and_branch()
 
137
 
 
138
        self.check_exist(wt2)
 
139
 
 
140
    def test_07_pull(self):
 
141
        """Test that pull will handle bits correctly"""
 
142
        wt2 = self.commit_and_branch()
 
143
 
 
144
        os.remove('b1/a')
 
145
        os.remove('b1/b')
 
146
        self.wt.commit('removed', rev_id='r2')
 
147
 
 
148
        # now wt2 can pull and the files should be removed
 
149
 
 
150
        # Make sure pull will delete the files
 
151
        wt2.pull(self.wt.branch)
 
152
        self.assertEquals('r2', wt2.last_revision())
 
153
        self.assertEquals('r2', wt2.branch.last_revision())
 
154
        self.check_empty(wt2)
 
155
 
 
156
        # Now restore the files on the first branch and commit
 
157
        # so that the second branch can pull the changes
 
158
        # and make sure that the executable bit has been copied
 
159
        rev_tree = self.wt.branch.repository.revision_tree('r1')
 
160
        self.wt.revert([], rev_tree, backups=False)
 
161
        self.wt.commit('resurrected', rev_id='r3')
 
162
 
 
163
        self.check_exist(self.wt)
 
164
 
 
165
        wt2.pull(self.wt.branch)
 
166
        self.assertEquals('r3', wt2.last_revision())
 
167
        self.assertEquals('r3', wt2.branch.last_revision())
 
168
        self.check_exist(wt2)
 
169
 
 
170
    def test_08_no_op_revert(self):
 
171
        """Just do a simple revert without anything changed
 
172
        
 
173
        The bits shouldn't swap.
 
174
        """
 
175
        self.wt.commit('adding a,b', rev_id='r1')
 
176
        rev_tree = self.wt.branch.repository.revision_tree('r1')
 
177
        self.wt.revert([], rev_tree, backups=False)
 
178
        self.check_exist(self.wt)
 
179