/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4988.10.5 by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS
1
# Copyright (C) 2006-2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
16
17
"""Tests for branch.pull behaviour."""
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
20
    branch,
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
21
    controldir,
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
22
    errors,
23
    memorytree,
24
    revision,
25
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
26
from breezy.tests import (
5651.5.1 by Andrew Bennetts
Make 'bzr reconfigure --unstacked' fetch tagged revisions too. (#401646)
27
    fixtures,
28
    per_branch,
29
    TestNotApplicable,
30
    )
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
31
32
33
class TestPull(per_branch.TestCaseWithBranch):
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
34
35
    def test_pull_convergence_simple(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
36
        # when revisions are pulled, the left-most accessible parents must
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
37
        # become the revision-history.
38
        parent = self.make_branch_and_tree('parent')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
39
        p1 = parent.commit('1st post', allow_pointless=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
40
        mine = parent.controldir.sprout('mine').open_workingtree()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
41
        m1 = mine.commit('my change', allow_pointless=True)
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
42
        parent.merge_from_branch(mine.branch)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
43
        p2 = parent.commit('merge my change')
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
44
        mine.pull(parent.branch)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
45
        self.assertEqual(p2, mine.branch.last_revision())
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
46
47
    def test_pull_merged_indirect(self):
48
        # it should be possible to do a pull from one branch into another
49
        # when the tip of the target was merged into the source branch
50
        # via a third branch - so its buried in the ancestry and is not
51
        # directly accessible.
52
        parent = self.make_branch_and_tree('parent')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
53
        p1 = parent.commit('1st post', allow_pointless=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
54
        mine = parent.controldir.sprout('mine').open_workingtree()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
55
        m1 = mine.commit('my change', allow_pointless=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
56
        other = parent.controldir.sprout('other').open_workingtree()
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
57
        other.merge_from_branch(mine.branch)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
58
        o2 = other.commit('merge my change')
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
59
        parent.merge_from_branch(other.branch)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
60
        p2 = parent.commit('merge other')
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
61
        mine.pull(parent.branch)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
62
        self.assertEqual(p2, mine.branch.last_revision())
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
63
64
    def test_pull_updates_checkout_and_master(self):
65
        """Pulling into a checkout updates the checkout and the master branch"""
66
        master_tree = self.make_branch_and_tree('master')
67
        rev1 = master_tree.commit('master')
68
        checkout = master_tree.branch.create_checkout('checkout')
69
7143.15.2 by Jelmer Vernooij
Run autopep8.
70
        other = master_tree.branch.controldir.sprout(
71
            'other').open_workingtree()
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
72
        rev2 = other.commit('other commit')
73
        # now pull, which should update both checkout and master.
74
        checkout.branch.pull(other.branch)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
75
        self.assertEqual(rev2, checkout.branch.last_revision())
76
        self.assertEqual(rev2, master_tree.branch.last_revision())
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
77
4056.6.3 by Gary van der Merwe
Add local args to pull methods, and add more tests
78
    def test_pull_local_updates_checkout_only(self):
79
        """Pulling --local into a checkout updates the checkout and not the
80
        master branch"""
81
        master_tree = self.make_branch_and_tree('master')
82
        rev1 = master_tree.commit('master')
83
        checkout = master_tree.branch.create_checkout('checkout')
84
7143.15.2 by Jelmer Vernooij
Run autopep8.
85
        other = master_tree.branch.controldir.sprout(
86
            'other').open_workingtree()
4056.6.3 by Gary van der Merwe
Add local args to pull methods, and add more tests
87
        rev2 = other.commit('other commit')
4335.1.1 by Ian Clatworthy
(igc) pull --local (Gary van der Merwe)
88
        # now pull local, which should update checkout but not master.
7143.15.2 by Jelmer Vernooij
Run autopep8.
89
        checkout.branch.pull(other.branch, local=True)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
90
        self.assertEqual(rev2, checkout.branch.last_revision())
91
        self.assertEqual(rev1, master_tree.branch.last_revision())
4056.6.3 by Gary van der Merwe
Add local args to pull methods, and add more tests
92
93
    def test_pull_local_raises_LocalRequiresBoundBranch_on_unbound(self):
94
        """Pulling --local into a branch that is not bound should fail."""
95
        master_tree = self.make_branch_and_tree('branch')
96
        rev1 = master_tree.commit('master')
97
7143.15.2 by Jelmer Vernooij
Run autopep8.
98
        other = master_tree.branch.controldir.sprout(
99
            'other').open_workingtree()
4056.6.3 by Gary van der Merwe
Add local args to pull methods, and add more tests
100
        rev2 = other.commit('other commit')
101
        # now pull --local, which should raise LocalRequiresBoundBranch error.
102
        self.assertRaises(errors.LocalRequiresBoundBranch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
103
                          master_tree.branch.pull, other.branch, local=True)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
104
        self.assertEqual(rev1, master_tree.branch.last_revision())
4056.6.3 by Gary van der Merwe
Add local args to pull methods, and add more tests
105
3482.1.1 by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result.
106
    def test_pull_returns_result(self):
107
        parent = self.make_branch_and_tree('parent')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
108
        p1 = parent.commit('1st post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
109
        mine = parent.controldir.sprout('mine').open_workingtree()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
110
        m1 = mine.commit('my change')
3482.1.1 by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result.
111
        result = parent.branch.pull(mine.branch)
112
        self.assertIsNot(None, result)
113
        self.assertIs(mine.branch, result.source_branch)
114
        self.assertIs(parent.branch, result.target_branch)
115
        self.assertIs(parent.branch, result.master_branch)
116
        self.assertIs(None, result.local_branch)
117
        self.assertEqual(1, result.old_revno)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
118
        self.assertEqual(p1, result.old_revid)
3482.1.1 by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result.
119
        self.assertEqual(2, result.new_revno)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
120
        self.assertEqual(m1, result.new_revid)
6112.4.7 by Jelmer Vernooij
Fix tests.
121
        self.assertEqual([], result.tag_conflicts)
3482.1.1 by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result.
122
1551.10.23 by Aaron Bentley
Update test case per review
123
    def test_pull_overwrite(self):
124
        tree_a = self.make_branch_and_tree('tree_a')
125
        tree_a.commit('message 1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
126
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
6862.1.1 by Jelmer Vernooij
Add some uniqueness to commit messages.
127
        rev2a = tree_a.commit('message 2a')
128
        rev2b = tree_b.commit('message 2b')
1551.10.23 by Aaron Bentley
Update test case per review
129
        self.assertRaises(errors.DivergedBranches, tree_a.pull, tree_b.branch)
3052.5.2 by John Arbash Meinel
Use a Graph.heads() check to determine if the ancestries are compatible.
130
        self.assertRaises(errors.DivergedBranches,
131
                          tree_a.branch.pull, tree_b.branch,
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
132
                          overwrite=False, stop_revision=rev2b)
3052.5.2 by John Arbash Meinel
Use a Graph.heads() check to determine if the ancestries are compatible.
133
        # It should not have updated the branch tip, but it should have fetched
6217.4.1 by Jelmer Vernooij
Add RepositoryFormat.supports_invisible_revisions.
134
        # the revision if the repository supports "invisible" revisions
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
135
        self.assertEqual(rev2a, tree_a.branch.last_revision())
6217.4.2 by Jelmer Vernooij
s/invisible/unreferenced.
136
        if tree_a.branch.repository._format.supports_unreferenced_revisions:
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
137
            self.assertTrue(tree_a.branch.repository.has_revision(rev2b))
2975.1.1 by Robert Collins
Minor fixes for foreign format friendliness.
138
        tree_a.branch.pull(tree_b.branch, overwrite=True,
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
139
                           stop_revision=rev2b)
140
        self.assertEqual(rev2b, tree_a.branch.last_revision())
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
141
        self.assertEqual(tree_b.branch.last_revision(),
142
                         tree_a.branch.last_revision())
1551.10.23 by Aaron Bentley
Update test case per review
143
7142.3.2 by Jelmer Vernooij
Fix overwrite for git branches.
144
    def test_pull_overwrite_set(self):
145
        tree_a = self.make_branch_and_tree('tree_a')
146
        rev1 = tree_a.commit('message 1')
147
148
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
149
        rev2a = tree_a.commit('message 2a')
150
        rev2b = tree_b.commit('message 2b')
151
        self.assertRaises(errors.DivergedBranches, tree_a.pull, tree_b.branch)
152
        self.assertRaises(errors.DivergedBranches,
153
                          tree_a.branch.pull, tree_b.branch,
154
                          overwrite=set(), stop_revision=rev2b)
155
        # It should not have updated the branch tip, but it should have fetched
156
        # the revision if the repository supports "invisible" revisions
157
        self.assertEqual(rev2a, tree_a.branch.last_revision())
158
        if tree_a.branch.repository._format.supports_unreferenced_revisions:
159
            self.assertTrue(tree_a.branch.repository.has_revision(rev2b))
160
        tree_a.branch.pull(tree_b.branch, overwrite=set(['history']),
161
                           stop_revision=rev2b)
162
        self.assertEqual(rev2b, tree_a.branch.last_revision())
163
        self.assertEqual(tree_b.branch.last_revision(),
164
                         tree_a.branch.last_revision())
165
        tree_a.branch.pull(tree_b.branch, overwrite=set(['history', 'tags']),
166
                           stop_revision=rev2b)
167
168
    def test_pull_overwrite_set_tags(self):
169
        tree_a = self.make_branch_and_tree('tree_a')
170
        if not tree_a.branch.supports_tags():
171
            raise TestNotApplicable("branch does not support tags")
172
        rev1 = tree_a.commit('message 1')
173
        tree_a.branch.tags.set_tag('tag1', rev1)
174
175
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
176
        rev2b = tree_b.commit('message 2b')
7190.1.1 by Jelmer Vernooij
Fix test with ghost revisions.
177
        tree_b.branch.tags.set_tag('tag1', rev2b)
178
        rev1b = tree_a.commit('message 1b')
7142.3.2 by Jelmer Vernooij
Fix overwrite for git branches.
179
        tree_a.branch.get_config_stack().set('branch.fetch_tags', True)
180
        self.assertRaises(errors.DivergedBranches, tree_a.pull, tree_b.branch)
181
        self.assertRaises(errors.DivergedBranches,
182
                          tree_a.branch.pull, tree_b.branch,
183
                          overwrite=set(), stop_revision=rev2b)
184
        # It should not have updated the branch tip, but it should have fetched
185
        # the revision if the repository supports "invisible" revisions
7190.1.1 by Jelmer Vernooij
Fix test with ghost revisions.
186
        self.assertEqual(rev1b, tree_a.branch.last_revision())
187
        # It also should not have updated the tags
188
        self.assertEqual(tree_a.branch.tags.get_tag_dict(), {'tag1': rev1})
7142.3.2 by Jelmer Vernooij
Fix overwrite for git branches.
189
        if tree_a.branch.repository._format.supports_unreferenced_revisions:
190
            self.assertTrue(tree_a.branch.repository.has_revision(rev2b))
191
        tree_a.branch.pull(tree_b.branch, overwrite=set(['history']),
192
                           stop_revision=rev2b)
193
        self.assertEqual(rev2b, tree_a.branch.last_revision())
194
        self.assertEqual(tree_b.branch.last_revision(),
195
                         tree_a.branch.last_revision())
196
        self.assertEqual(rev1, tree_a.branch.tags.lookup_tag('tag1'))
197
        tree_a.branch.pull(tree_b.branch, overwrite=set(['history', 'tags']),
198
                           stop_revision=rev2b)
7190.1.1 by Jelmer Vernooij
Fix test with ghost revisions.
199
        self.assertEqual(rev2b, tree_a.branch.tags.lookup_tag('tag1'))
7142.3.2 by Jelmer Vernooij
Fix overwrite for git branches.
200
5535.3.29 by Andrew Bennetts
Add some per-branch tests.
201
    def test_pull_merges_and_fetches_tags(self):
202
        """Tags are updated by br.pull(source), and revisions named in those
203
        tags are fetched.
204
        """
205
        # Make a source, sprout a target off it
206
        try:
207
            builder = self.make_branch_builder('source')
208
        except errors.UninitializableFormat:
209
            raise TestNotApplicable('uninitializeable format')
7143.15.2 by Jelmer Vernooij
Run autopep8.
210
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
211
            builder)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
212
        target = source.controldir.sprout('target').open_branch()
5651.5.2 by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks.
213
        # Add a tag to the source, then pull from source
214
        try:
6747.3.2 by Jelmer Vernooij
Avoid more uses of revision_id.
215
            source.tags.set_tag('tag-a', rev2)
5651.5.2 by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks.
216
        except errors.TagsNotSupported:
217
            raise TestNotApplicable('format does not support tags.')
6747.3.2 by Jelmer Vernooij
Avoid more uses of revision_id.
218
        source.tags.set_tag('tag-a', rev2)
6404.1.1 by Vincent Ladeuil
Migrate branch.fetch_tags
219
        source.get_config_stack().set('branch.fetch_tags', True)
5535.3.29 by Andrew Bennetts
Add some per-branch tests.
220
        target.pull(source)
221
        # The tag is present, and so is its revision.
6747.3.2 by Jelmer Vernooij
Avoid more uses of revision_id.
222
        self.assertEqual(rev2, target.tags.lookup_tag('tag-a'))
223
        target.repository.get_revision(rev2)
5535.3.29 by Andrew Bennetts
Add some per-branch tests.
224
225
    def test_pull_stop_revision_merges_and_fetches_tags(self):
226
        """br.pull(source, stop_revision=REV) updates and fetches tags."""
227
        # Make a source, sprout a target off it
228
        try:
229
            builder = self.make_branch_builder('source')
230
        except errors.UninitializableFormat:
231
            raise TestNotApplicable('uninitializeable format')
7143.15.2 by Jelmer Vernooij
Run autopep8.
232
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
233
            builder)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
234
        target = source.controldir.sprout('target').open_branch()
5535.3.29 by Andrew Bennetts
Add some per-branch tests.
235
        # Add a new commit to the ancestry
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
236
        rev_2_again = builder.build_commit(message="Rev 2 again")
237
        # Add a tag to the source, then pull rev_2_again from source
5651.5.2 by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks.
238
        try:
6747.3.2 by Jelmer Vernooij
Avoid more uses of revision_id.
239
            source.tags.set_tag('tag-a', rev2)
5651.5.2 by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks.
240
        except errors.TagsNotSupported:
241
            raise TestNotApplicable('format does not support tags.')
6404.1.1 by Vincent Ladeuil
Migrate branch.fetch_tags
242
        source.get_config_stack().set('branch.fetch_tags', True)
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
243
        target.pull(source, stop_revision=rev_2_again)
5535.3.29 by Andrew Bennetts
Add some per-branch tests.
244
        # The tag is present, and so is its revision.
6747.3.2 by Jelmer Vernooij
Avoid more uses of revision_id.
245
        self.assertEqual(rev2, target.tags.lookup_tag('tag-a'))
246
        target.repository.get_revision(rev2)
5535.3.29 by Andrew Bennetts
Add some per-branch tests.
247
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
248
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
249
class TestPullHook(per_branch.TestCaseWithBranch):
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
250
251
    def setUp(self):
252
        self.hook_calls = []
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
253
        super(TestPullHook, self).setUp()
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
254
2297.1.1 by Martin Pool
Pull now returns a PullResult rather than just an integer.
255
    def capture_post_pull_hook(self, result):
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
256
        """Capture post pull hook calls to self.hook_calls.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
257
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
258
        The call is logged, as is some state of the two branches.
259
        """
2297.1.6 by Martin Pool
Add docs for Results, give some members cleaner names
260
        if result.local_branch:
261
            local_locked = result.local_branch.is_locked()
262
            local_base = result.local_branch.base
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
263
        else:
264
            local_locked = None
265
            local_base = None
266
        self.hook_calls.append(
2297.1.6 by Martin Pool
Add docs for Results, give some members cleaner names
267
            ('post_pull', result.source_branch, local_base,
268
             result.master_branch.base, result.old_revno,
2297.1.1 by Martin Pool
Pull now returns a PullResult rather than just an integer.
269
             result.old_revid,
2297.1.6 by Martin Pool
Add docs for Results, give some members cleaner names
270
             result.new_revno, result.new_revid,
271
             result.source_branch.is_locked(), local_locked,
272
             result.master_branch.is_locked()))
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
273
274
    def test_post_pull_empty_history(self):
275
        target = self.make_branch('target')
276
        source = self.make_branch('source')
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
277
        branch.Branch.hooks.install_named_hook(
278
            'post_pull', self.capture_post_pull_hook, None)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
279
        target.pull(source)
280
        # with nothing there we should still get a notification, and
281
        # have both branches locked at the notification time.
282
        self.assertEqual([
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
283
            ('post_pull', source, None, target.base, 0, revision.NULL_REVISION,
284
             0, revision.NULL_REVISION, True, None, True)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
285
            ],
286
            self.hook_calls)
287
288
    def test_post_pull_bound_branch(self):
289
        # pulling to a bound branch should pass in the master branch to the
290
        # hook, allowing the correct number of emails to be sent, while still
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
291
        # allowing hooks that want to modify the target to do so to both
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
292
        # instances.
293
        target = self.make_branch('target')
294
        local = self.make_branch('local')
295
        try:
296
            local.bind(target)
297
        except errors.UpgradeRequired:
2477.1.2 by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel)
298
            # We can't bind this format to itself- typically it is the local
299
            # branch that doesn't support binding.  As of May 2007
300
            # remotebranches can't be bound.  Let's instead make a new local
301
            # branch of the default type, which does allow binding.
302
            # See https://bugs.launchpad.net/bzr/+bug/112020
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
303
            local = controldir.ControlDir.create_branch_convenience('local2')
2477.1.2 by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel)
304
            local.bind(target)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
305
        source = self.make_branch('source')
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
306
        branch.Branch.hooks.install_named_hook(
307
            'post_pull', self.capture_post_pull_hook, None)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
308
        local.pull(source)
309
        # with nothing there we should still get a notification, and
310
        # have both branches locked at the notification time.
311
        self.assertEqual([
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
312
            ('post_pull', source, local.base, target.base, 0,
313
             revision.NULL_REVISION, 0, revision.NULL_REVISION,
314
             True, True, True)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
315
            ],
316
            self.hook_calls)
317
318
    def test_post_pull_nonempty_history(self):
319
        target = self.make_branch_and_memory_tree('target')
320
        target.lock_write()
321
        target.add('')
322
        rev1 = target.commit('rev 1')
323
        target.unlock()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
324
        sourcedir = target.controldir.clone(self.get_url('source'))
7143.15.2 by Jelmer Vernooij
Run autopep8.
325
        source = memorytree.MemoryTree.create_on_branch(
326
            sourcedir.open_branch())
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
327
        rev2 = source.commit('rev 2')
5010.2.17 by Vincent Ladeuil
Fix imports in per_branch/test_pull.py.
328
        branch.Branch.hooks.install_named_hook(
329
            'post_pull', self.capture_post_pull_hook, None)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
330
        target.branch.pull(source.branch)
331
        # with nothing there we should still get a notification, and
332
        # have both branches locked at the notification time.
333
        self.assertEqual([
334
            ('post_pull', source.branch, None, target.branch.base, 1, rev1,
335
             2, rev2, True, None, True)
336
            ],
337
            self.hook_calls)