~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_interbranch/test_fetch.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011, 2016 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
"""Tests for InterBranch.fetch."""
 
18
 
 
19
from bzrlib.revision import NULL_REVISION
 
20
from bzrlib.tests.per_interbranch import (
 
21
    TestCaseWithInterBranch,
 
22
    )
 
23
 
 
24
 
 
25
class TestInterBranchFetch(TestCaseWithInterBranch):
 
26
 
 
27
    def test_fetch_revisions(self):
 
28
        """Test fetch-revision operation."""
 
29
        wt = self.make_from_branch_and_tree('b1')
 
30
        b1 = wt.branch
 
31
        self.build_tree_contents([('b1/foo', 'hello')])
 
32
        wt.add(['foo'], ['foo-id'])
 
33
        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
 
34
 
 
35
        b2 = self.make_to_branch('b2')
 
36
        b2.fetch(b1)
 
37
 
 
38
        # fetch does not update the last revision
 
39
        self.assertEqual(NULL_REVISION, b2.last_revision())
 
40
 
 
41
        rev = b2.repository.get_revision('revision-1')
 
42
        tree = b2.repository.revision_tree('revision-1')
 
43
        tree.lock_read()
 
44
        self.addCleanup(tree.unlock)
 
45
        self.assertEqual(tree.get_file_text('foo-id'), 'hello')
 
46
 
 
47
    def test_fetch_revisions_limit(self):
 
48
        """Test fetch-revision operation."""
 
49
        builder = self.make_branch_builder('b1',
 
50
            format=self.branch_format_from._matchingbzrdir)
 
51
        builder.start_series()
 
52
        builder.build_commit(rev_id='revision-1')
 
53
        builder.build_commit(rev_id='revision-2')
 
54
        builder.build_commit(rev_id='revision-3')
 
55
        builder.finish_series()
 
56
        b1 = builder.get_branch()
 
57
        b2 = self.make_to_branch('b2')
 
58
        b2.fetch(b1, limit=1)
 
59
 
 
60
        # fetch does not update the last revision
 
61
        self.assertEqual(NULL_REVISION, b2.last_revision())
 
62
 
 
63
        self.assertEqual(
 
64
            set(['revision-1']),
 
65
            b2.repository.has_revisions(
 
66
                ['revision-1', 'revision-2', 'revision-3']))
 
67
 
 
68
    def test_fetch_revisions_limit_incremental(self):
 
69
        """Test incremental fetch-revision operation with limit."""
 
70
        wt = self.make_from_branch_and_tree('b1')
 
71
        b1 = wt.branch
 
72
        self.build_tree_contents([('b1/foo', 'hello')])
 
73
        wt.add(['foo'], ['foo-id'])
 
74
        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
 
75
 
 
76
        b2 = self.make_to_branch('b2')
 
77
        b2.fetch(b1, limit=1)
 
78
 
 
79
        self.assertEqual(
 
80
            set(['revision-1']),
 
81
            b2.repository.has_revisions(
 
82
                ['revision-1', 'revision-2', 'revision-3']))
 
83
 
 
84
        wt.commit('hmm', rev_id='revision-2')
 
85
        wt.commit('hmmm', rev_id='revision-3')
 
86
 
 
87
        b2.fetch(b1, limit=1)
 
88
 
 
89
        # fetch does not update the last revision
 
90
        self.assertEqual(NULL_REVISION, b2.last_revision())
 
91
 
 
92
        self.assertEqual(
 
93
            set(['revision-1', 'revision-2']),
 
94
            b2.repository.has_revisions(
 
95
                ['revision-1', 'revision-2', 'revision-3']))