/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 breezy/tests/test_revert.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007, 2009, 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import os
 
18
 
 
19
from breezy import merge, tests, transform, workingtree
 
20
 
 
21
 
 
22
class TestRevert(tests.TestCaseWithTransport):
 
23
    """Ensure that revert behaves as expected"""
 
24
 
 
25
    def test_revert_merged_dir(self):
 
26
        """Reverting a merge that adds a directory deletes the directory"""
 
27
        source_tree = self.make_branch_and_tree('source')
 
28
        source_tree.commit('empty tree')
 
29
        target_tree = source_tree.controldir.sprout(
 
30
            'target').open_workingtree()
 
31
        self.build_tree(['source/dir/', 'source/dir/contents'])
 
32
        source_tree.add(['dir', 'dir/contents'], [b'dir-id', b'contents-id'])
 
33
        source_tree.commit('added dir')
 
34
        target_tree.lock_write()
 
35
        self.addCleanup(target_tree.unlock)
 
36
        merge.merge_inner(target_tree.branch, source_tree.basis_tree(),
 
37
                          target_tree.basis_tree(), this_tree=target_tree)
 
38
        self.assertPathExists('target/dir')
 
39
        self.assertPathExists('target/dir/contents')
 
40
        target_tree.revert()
 
41
        self.assertPathDoesNotExist('target/dir/contents')
 
42
        self.assertPathDoesNotExist('target/dir')
 
43
 
 
44
    def test_revert_new(self):
 
45
        """Only locally-changed new files should be preserved when reverting
 
46
 
 
47
        When a file isn't present in revert's target tree:
 
48
        If a file hasn't been committed, revert should unversion it, but not
 
49
        delete it.
 
50
        If a file has local changes, revert should unversion it, but not
 
51
        delete it.
 
52
        If a file has no changes from the last commit, revert should delete it.
 
53
        If a file has changes due to a merge, revert should delete it.
 
54
        """
 
55
        tree = self.make_branch_and_tree('tree')
 
56
        tree.commit('empty tree')
 
57
        merge_target = tree.controldir.sprout(
 
58
            'merge_target').open_workingtree()
 
59
        self.build_tree(['tree/new_file'])
 
60
 
 
61
        # newly-added files should not be deleted
 
62
        tree.add('new_file')
 
63
        basis_tree = tree.branch.repository.revision_tree(tree.last_revision())
 
64
        tree.revert()
 
65
        self.assertPathExists('tree/new_file')
 
66
 
 
67
        # unchanged files should be deleted
 
68
        tree.add('new_file')
 
69
        tree.commit('add new_file')
 
70
        tree.revert(old_tree=basis_tree)
 
71
        self.assertPathDoesNotExist('tree/new_file')
 
72
 
 
73
        # files should be deleted if their changes came from merges
 
74
        merge_target.merge_from_branch(tree.branch)
 
75
        self.assertPathExists('merge_target/new_file')
 
76
        merge_target.revert()
 
77
        self.assertPathDoesNotExist('merge_target/new_file')
 
78
 
 
79
        # files should not be deleted if changed after a merge
 
80
        merge_target.merge_from_branch(tree.branch)
 
81
        self.assertPathExists('merge_target/new_file')
 
82
        self.build_tree_contents([('merge_target/new_file', b'new_contents')])
 
83
        merge_target.revert()
 
84
        self.assertPathExists('merge_target/new_file')
 
85
 
 
86
    def tree_with_executable(self):
 
87
        tree = self.make_branch_and_tree('tree')
 
88
        tt = tree.transform()
 
89
        tt.new_file('newfile', tt.root, [b'helooo!'], b'newfile-id', True)
 
90
        tt.apply()
 
91
        with tree.lock_write():
 
92
            self.assertTrue(tree.is_executable('newfile'))
 
93
            tree.commit('added newfile')
 
94
        return tree
 
95
 
 
96
    def test_preserve_execute(self):
 
97
        tree = self.tree_with_executable()
 
98
        tt = tree.transform()
 
99
        newfile = tt.trans_id_tree_path('newfile')
 
100
        tt.delete_contents(newfile)
 
101
        tt.create_file([b'Woooorld!'], newfile)
 
102
        tt.apply()
 
103
        tree = workingtree.WorkingTree.open('tree')
 
104
        tree.lock_write()
 
105
        self.addCleanup(tree.unlock)
 
106
        self.assertTrue(tree.is_executable('newfile'))
 
107
        transform.revert(tree, tree.basis_tree(), None, backups=True)
 
108
        with tree.get_file('newfile', 'rb') as f:
 
109
            self.assertEqual(b'helooo!', f.read())
 
110
        self.assertTrue(tree.is_executable('newfile'))
 
111
 
 
112
    def test_revert_executable(self):
 
113
        tree = self.tree_with_executable()
 
114
        tt = tree.transform()
 
115
        newfile = tt.trans_id_tree_path('newfile')
 
116
        tt.set_executability(False, newfile)
 
117
        tt.apply()
 
118
        tree.lock_write()
 
119
        self.addCleanup(tree.unlock)
 
120
        transform.revert(tree, tree.basis_tree(), None)
 
121
        self.assertTrue(tree.is_executable('newfile'))
 
122
 
 
123
    def test_revert_deletes_files_from_revert(self):
 
124
        tree = self.make_branch_and_tree('.')
 
125
        self.build_tree(['file'])
 
126
        tree.add('file')
 
127
        rev1 = tree.commit('added file')
 
128
        with tree.lock_read():
 
129
            file_sha = tree.get_file_sha1('file')
 
130
        os.unlink('file')
 
131
        tree.commit('removed file')
 
132
        self.assertPathDoesNotExist('file')
 
133
        tree.revert(old_tree=tree.branch.repository.revision_tree(rev1))
 
134
        self.assertEqual({'file': file_sha}, tree.merge_modified())
 
135
        self.assertPathExists('file')
 
136
        tree.revert()
 
137
        self.assertPathDoesNotExist('file')
 
138
        self.assertEqual({}, tree.merge_modified())
 
139
 
 
140
    def test_revert_file_in_deleted_dir(self):
 
141
        tree = self.make_branch_and_tree('.')
 
142
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
 
143
        tree.add(['dir', 'dir/file1', 'dir/file2'],
 
144
                 [b'dir-id', b'file1-id', b'file2-id'])
 
145
        tree.commit("Added files")
 
146
        os.unlink('dir/file1')
 
147
        os.unlink('dir/file2')
 
148
        os.rmdir('dir')
 
149
        tree.remove(['dir/', 'dir/file1', 'dir/file2'])
 
150
        tree.revert(['dir/file1'])
 
151
        self.assertPathExists('dir/file1')
 
152
        self.assertPathDoesNotExist('dir/file2')
 
153
        self.assertEqual(b'dir-id', tree.path2id('dir'))
 
154
 
 
155
    def test_revert_root_id_change(self):
 
156
        tree = self.make_branch_and_tree('.')
 
157
        tree.set_root_id(b'initial-root-id')
 
158
        self.build_tree(['file1'])
 
159
        tree.add(['file1'])
 
160
        tree.commit('first')
 
161
        tree.set_root_id(b'temp-root-id')
 
162
        self.assertEqual(b'temp-root-id', tree.path2id(''))
 
163
        tree.revert()
 
164
        self.assertEqual(b'initial-root-id', tree.path2id(''))