/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/per_workingtree/test_commit.py

  • Committer: Jelmer Vernooij
  • Date: 2018-03-24 18:02:48 UTC
  • mfrom: (6922 work)
  • mto: This revision was merged to the branch mainline in revision 6923.
  • Revision ID: jelmer@jelmer.uk-20180324180248-w6n7cmggk7dx1uk2
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    CannotCommitSelectedFileMerge,
34
34
    PointlessCommit,
35
35
    )
 
36
from breezy.tests.matchers import HasPathRelations
36
37
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
37
38
from breezy.tests.testui import ProgressRecordingUIFactory
38
39
 
66
67
        tree_a = self.make_branch_and_tree('a')
67
68
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])
68
69
        tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'])
69
 
        dir2_id =  tree_a.path2id('dir2')
70
 
        f1_id = tree_a.path2id('dir/f1')
71
70
        rev_id1 = tree_a.commit('init')
 
71
        revtree = tree_a.branch.repository.revision_tree(rev_id1)
72
72
        # Rename one entry out of this directory
73
73
        tree_a.rename_one('dir/f1', 'dir2/a')
74
74
        osutils.rmtree('a/dir')
75
75
        tree_a.commit('autoremoved')
76
76
 
77
 
        with tree_a.lock_read():
78
 
            root_id = tree_a.get_root_id()
79
 
            paths = [(path, ie.file_id)
80
 
                     for path, ie in tree_a.iter_entries_by_dir()]
81
77
        # The only paths left should be the root
82
 
        self.assertEqual([('', root_id),
83
 
                          ('dir2', dir2_id),
84
 
                          ('dir2/a', f1_id),
85
 
                         ], paths)
 
78
        self.assertThat(
 
79
            tree_a, HasPathRelations(
 
80
                revtree,
 
81
                [('', ''), ('dir2/', 'dir2/'), ('dir2/a', 'dir/f1')]))
86
82
 
87
83
    def test_no_autodelete_alternate_renamed(self):
88
84
        # Test for bug #114615
89
85
        tree_a = self.make_branch_and_tree('A')
90
86
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
91
87
        tree_a.add(['a', 'a/m', 'a/n'])
92
 
        a_id = tree_a.path2id('a')
93
 
        m_id = tree_a.path2id('a/m')
94
 
        n_id = tree_a.path2id('a/n')
95
88
        tree_a.commit('init')
96
89
 
97
 
        with tree_a.lock_read():
98
 
            root_id = tree_a.get_root_id()
99
 
 
100
90
        tree_b = tree_a.controldir.sprout('B').open_workingtree()
101
91
        self.build_tree(['B/xyz/'])
102
92
        tree_b.add(['xyz'])
103
 
        xyz_id = tree_b.path2id('xyz')
104
93
        tree_b.rename_one('a/m', 'xyz/m')
105
94
        osutils.rmtree('B/a')
106
95
        tree_b.commit('delete in B')
107
96
 
108
 
        paths = [(path, ie.file_id)
109
 
                 for path, ie in tree_b.iter_entries_by_dir()]
110
 
        self.assertEqual([('', root_id),
111
 
                          ('xyz', xyz_id),
112
 
                          ('xyz/m', m_id),
113
 
                         ], paths)
 
97
        self.assertThat(
 
98
                tree_b,
 
99
                HasPathRelations(
 
100
                    tree_a, [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
114
101
 
115
102
        self.build_tree_contents([('A/a/n', 'new contents for n\n')])
116
103
        tree_a.commit('change n in A')
119
106
        # (in A) and removed (in B), so 'a' needs to be restored.
120
107
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
121
108
        self.assertEqual(3, num_conflicts)
122
 
        paths = [(path, ie.file_id)
123
 
                 for path, ie in tree_b.iter_entries_by_dir()]
124
 
        self.assertEqual([('', root_id),
125
 
                          ('a', a_id),
126
 
                          ('xyz', xyz_id),
127
 
                          ('a/n.OTHER', n_id),
128
 
                          ('xyz/m', m_id),
129
 
                         ], paths)
 
109
 
 
110
        self.assertThat(
 
111
                tree_b, HasPathRelations(
 
112
                    tree_a,
 
113
                    [('', ''), ('a/', 'a/'), ('xyz/', None),
 
114
                     ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
 
115
 
130
116
        osutils.rmtree('B/a')
131
117
        try:
132
118
            # bzr resolve --all
136
122
            # effect.
137
123
            pass
138
124
        tree_b.commit('autoremove a, without touching xyz/m')
139
 
        paths = [(path, ie.file_id)
140
 
                 for path, ie in tree_b.iter_entries_by_dir()]
141
 
        self.assertEqual([('', root_id),
142
 
                          ('xyz', xyz_id),
143
 
                          ('xyz/m', m_id),
144
 
                         ], paths)
 
125
 
 
126
        self.assertThat(
 
127
                tree_b, HasPathRelations(
 
128
                    tree_a,
 
129
                    [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
145
130
 
146
131
    def test_commit_exclude_pending_merge_fails(self):
147
132
        """Excludes are a form of partial commit."""
173
158
        tree.lock_read()
174
159
        self.addCleanup(tree.unlock)
175
160
        changes = list(tree.iter_changes(tree.basis_tree()))
176
 
        self.assertEqual(2, len(changes))
177
 
        self.assertEqual((None, 'b'), changes[0][1])
178
 
        self.assertEqual((None, 'c'), changes[1][1])
 
161
        self.assertEqual([(None, 'b'), (None, 'c')], [c[1] for c in changes])
179
162
 
180
163
    def test_commit_exclude_subtree_of_selected(self):
181
164
        tree = self.make_branch_and_tree('.')
182
 
        self.build_tree(['a/', 'a/b'])
 
165
        self.build_tree(['a/', 'a/b', 'a/c'])
183
166
        tree.smart_add(['.'])
184
 
        tree.commit('test', specific_files=['a'], exclude=['a/b'])
 
167
        tree.commit('test', specific_files=['a', 'a/c'], exclude=['a/b'])
185
168
        # If a/b was excluded it will still be 'added' in status.
186
169
        tree.lock_read()
187
170
        self.addCleanup(tree.unlock)