~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: Patch Queue Manager
  • Date: 2014-09-22 19:14:34 UTC
  • mfrom: (6598.1.2 bzr)
  • Revision ID: pqm@pqm.ubuntu.com-20140922191434-6bbnpnxi5jab4vim
(richard-wilbur) Allows launchpad APIs to use proxies by default(Paul Gear).
 (Paul Gear)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007, 2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
import os
18
 
import re
19
 
import sys
20
 
 
21
 
import bzrlib
22
17
from bzrlib import (
23
18
    bzrdir,
24
19
    errors,
25
20
    osutils,
26
 
    merge,
27
 
    repository,
 
21
    revision as _mod_revision,
28
22
    versionedfile,
29
23
    )
30
24
from bzrlib.branch import Branch
31
 
from bzrlib.bzrdir import BzrDir
32
25
from bzrlib.repofmt import knitrepo
33
26
from bzrlib.tests import TestCaseWithTransport
34
27
from bzrlib.tests.test_revision import make_branches
35
 
from bzrlib.trace import mutter
36
28
from bzrlib.upgrade import Convert
37
29
from bzrlib.workingtree import WorkingTree
38
30
 
44
36
def has_revision(branch, revision_id):
45
37
    return branch.repository.has_revision(revision_id)
46
38
 
 
39
 
 
40
def revision_history(branch):
 
41
    branch.lock_read()
 
42
    try:
 
43
        graph = branch.repository.get_graph()
 
44
        history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
 
45
            [_mod_revision.NULL_REVISION]))
 
46
    finally:
 
47
        branch.unlock()
 
48
    history.reverse()
 
49
    return history
 
50
 
 
51
 
47
52
def fetch_steps(self, br_a, br_b, writable_a):
48
53
    """A foreign test method for testing fetch locally and remotely."""
49
54
 
50
55
    # TODO RBC 20060201 make this a repository test.
51
56
    repo_b = br_b.repository
52
 
    self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
53
 
    self.assertTrue(repo_b.has_revision(br_a.revision_history()[2]))
54
 
    self.assertEquals(len(br_b.revision_history()), 7)
55
 
    br_b.fetch(br_a, br_a.revision_history()[2])
 
57
    self.assertFalse(repo_b.has_revision(revision_history(br_a)[3]))
 
58
    self.assertTrue(repo_b.has_revision(revision_history(br_a)[2]))
 
59
    self.assertEquals(len(revision_history(br_b)), 7)
 
60
    br_b.fetch(br_a, revision_history(br_a)[2])
56
61
    # branch.fetch is not supposed to alter the revision history
57
 
    self.assertEquals(len(br_b.revision_history()), 7)
58
 
    self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
 
62
    self.assertEquals(len(revision_history(br_b)), 7)
 
63
    self.assertFalse(repo_b.has_revision(revision_history(br_a)[3]))
59
64
 
60
65
    # fetching the next revision up in sample data copies one revision
61
 
    br_b.fetch(br_a, br_a.revision_history()[3])
62
 
    self.assertTrue(repo_b.has_revision(br_a.revision_history()[3]))
63
 
    self.assertFalse(has_revision(br_a, br_b.revision_history()[6]))
64
 
    self.assertTrue(br_a.repository.has_revision(br_b.revision_history()[5]))
 
66
    br_b.fetch(br_a, revision_history(br_a)[3])
 
67
    self.assertTrue(repo_b.has_revision(revision_history(br_a)[3]))
 
68
    self.assertFalse(has_revision(br_a, revision_history(br_b)[6]))
 
69
    self.assertTrue(br_a.repository.has_revision(revision_history(br_b)[5]))
65
70
 
66
71
    # When a non-branch ancestor is missing, it should be unlisted...
67
72
    # as its not reference from the inventory weave.
69
74
    br_b4.fetch(br_b)
70
75
 
71
76
    writable_a.fetch(br_b)
72
 
    self.assertTrue(has_revision(br_a, br_b.revision_history()[3]))
73
 
    self.assertTrue(has_revision(br_a, br_b.revision_history()[4]))
 
77
    self.assertTrue(has_revision(br_a, revision_history(br_b)[3]))
 
78
    self.assertTrue(has_revision(br_a, revision_history(br_b)[4]))
74
79
 
75
80
    br_b2 = self.make_branch('br_b2')
76
81
    br_b2.fetch(br_b)
77
 
    self.assertTrue(has_revision(br_b2, br_b.revision_history()[4]))
78
 
    self.assertTrue(has_revision(br_b2, br_a.revision_history()[2]))
79
 
    self.assertFalse(has_revision(br_b2, br_a.revision_history()[3]))
 
82
    self.assertTrue(has_revision(br_b2, revision_history(br_b)[4]))
 
83
    self.assertTrue(has_revision(br_b2, revision_history(br_a)[2]))
 
84
    self.assertFalse(has_revision(br_b2, revision_history(br_a)[3]))
80
85
 
81
86
    br_a2 = self.make_branch('br_a2')
82
87
    br_a2.fetch(br_a)
83
 
    self.assertTrue(has_revision(br_a2, br_b.revision_history()[4]))
84
 
    self.assertTrue(has_revision(br_a2, br_a.revision_history()[3]))
85
 
    self.assertTrue(has_revision(br_a2, br_a.revision_history()[2]))
 
88
    self.assertTrue(has_revision(br_a2, revision_history(br_b)[4]))
 
89
    self.assertTrue(has_revision(br_a2, revision_history(br_a)[3]))
 
90
    self.assertTrue(has_revision(br_a2, revision_history(br_a)[2]))
86
91
 
87
92
    br_a3 = self.make_branch('br_a3')
88
93
    # pulling a branch with no revisions grabs nothing, regardless of
90
95
    br_a3.fetch(br_a2)
91
96
    for revno in range(4):
92
97
        self.assertFalse(
93
 
            br_a3.repository.has_revision(br_a.revision_history()[revno]))
94
 
    br_a3.fetch(br_a2, br_a.revision_history()[2])
 
98
            br_a3.repository.has_revision(revision_history(br_a)[revno]))
 
99
    br_a3.fetch(br_a2, revision_history(br_a)[2])
95
100
    # pull the 3 revisions introduced by a@u-0-3
96
 
    br_a3.fetch(br_a2, br_a.revision_history()[3])
 
101
    br_a3.fetch(br_a2, revision_history(br_a)[3])
97
102
    # NoSuchRevision should be raised if the branch is missing the revision
98
103
    # that was requested.
99
104
    self.assertRaises(errors.NoSuchRevision, br_a3.fetch, br_a2, 'pizza')