~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_dpush.py

  • Committer: Vincent Ladeuil
  • Date: 2011-04-11 09:38:59 UTC
  • mfrom: (5609.33.1 2.3)
  • mto: This revision was merged to the branch mainline in revision 5783.
  • Revision ID: v.ladeuil+lp@free.fr-20110411093859-0gyunr0tkvnoskrm
Merge 2.3 to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009, 2010, 2011 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
 
 
18
"""Black-box tests for bzr dpush."""
 
19
 
 
20
 
 
21
import os
 
22
 
 
23
from bzrlib import (
 
24
    branch,
 
25
    bzrdir,
 
26
    foreign,
 
27
    tests,
 
28
    workingtree,
 
29
    )
 
30
from bzrlib.tests import (
 
31
    blackbox,
 
32
    script,
 
33
    test_foreign,
 
34
    )
 
35
from bzrlib.tests.blackbox import test_push
 
36
from bzrlib.tests.scenarios import (
 
37
    load_tests_apply_scenarios,
 
38
    )
 
39
 
 
40
 
 
41
load_tests = load_tests_apply_scenarios
 
42
 
 
43
 
 
44
class TestDpush(tests.TestCaseWithTransport):
 
45
 
 
46
    def setUp(self):
 
47
        super(TestDpush, self).setUp()
 
48
        test_foreign.register_dummy_foreign_for_test(self)
 
49
 
 
50
    def make_dummy_builder(self, relpath):
 
51
        builder = self.make_branch_builder(
 
52
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
 
53
        builder.build_snapshot('revid', None,
 
54
            [('add', ('', 'TREE_ROOT', 'directory', None)),
 
55
             ('add', ('foo', 'fooid', 'file', 'bar'))])
 
56
        return builder
 
57
 
 
58
    def test_dpush_native(self):
 
59
        target_tree = self.make_branch_and_tree("dp")
 
60
        source_tree = self.make_branch_and_tree("dc")
 
61
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
 
62
        self.assertEquals("", output)
 
63
        self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
 
64
 
 
65
    def test_dpush(self):
 
66
        branch = self.make_dummy_builder('d').get_branch()
 
67
 
 
68
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
 
69
        self.build_tree(("dc/foo", "blaaaa"))
 
70
        dc.open_workingtree().commit('msg')
 
71
 
 
72
        script.run_script(self, """
 
73
            $ bzr dpush -d dc d
 
74
            2>Pushed up to revision 2.
 
75
            $ bzr status dc
 
76
            """)
 
77
 
 
78
    def test_dpush_new(self):
 
79
        b = self.make_dummy_builder('d').get_branch()
 
80
 
 
81
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
82
        self.build_tree_contents([("dc/foofile", "blaaaa")])
 
83
        dc_tree = dc.open_workingtree()
 
84
        dc_tree.add("foofile")
 
85
        dc_tree.commit("msg")
 
86
 
 
87
        script.run_script(self, '''
 
88
            $ bzr dpush -d dc d
 
89
            2>Pushed up to revision 2.
 
90
            $ bzr revno dc
 
91
            2
 
92
            $ bzr status dc
 
93
            ''')
 
94
 
 
95
    def test_dpush_wt_diff(self):
 
96
        b = self.make_dummy_builder('d').get_branch()
 
97
 
 
98
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
99
        self.build_tree_contents([("dc/foofile", "blaaaa")])
 
100
        dc_tree = dc.open_workingtree()
 
101
        dc_tree.add("foofile")
 
102
        newrevid = dc_tree.commit('msg')
 
103
 
 
104
        self.build_tree_contents([("dc/foofile", "blaaaal")])
 
105
        script.run_script(self, '''
 
106
            $ bzr dpush -d dc d --no-strict
 
107
            2>Pushed up to revision 2.
 
108
            ''')
 
109
        self.assertFileEqual("blaaaal", "dc/foofile")
 
110
        # if the dummy vcs wasn't that dummy we could uncomment the line below
 
111
        # self.assertFileEqual("blaaaa", "d/foofile")
 
112
        script.run_script(self, '''
 
113
            $ bzr status dc
 
114
            modified:
 
115
              foofile
 
116
            ''')
 
117
 
 
118
    def test_diverged(self):
 
119
        builder = self.make_dummy_builder('d')
 
120
 
 
121
        b = builder.get_branch()
 
122
 
 
123
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
124
        dc_tree = dc.open_workingtree()
 
125
 
 
126
        self.build_tree_contents([("dc/foo", "bar")])
 
127
        dc_tree.commit('msg1')
 
128
 
 
129
        builder.build_snapshot('revid2', None,
 
130
          [('modify', ('fooid', 'blie'))])
 
131
 
 
132
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
 
133
        self.assertEquals(output, "")
 
134
        self.assertContainsRe(error, "have diverged")
 
135
 
 
136
 
 
137
class TestDpushStrictMixin(object):
 
138
 
 
139
    def setUp(self):
 
140
        test_foreign.register_dummy_foreign_for_test(self)
 
141
        # Create an empty branch where we will be able to push
 
142
        self.foreign = self.make_branch(
 
143
            'to', format=test_foreign.DummyForeignVcsDirFormat())
 
144
 
 
145
    def set_config_push_strict(self, value):
 
146
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
147
        # should do)
 
148
        conf = self.tree.branch.get_config()
 
149
        conf.set_user_option('dpush_strict', value)
 
150
 
 
151
    _default_command = ['dpush', '../to']
 
152
 
 
153
 
 
154
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
 
155
                                    test_push.TestPushStrictWithoutChanges):
 
156
 
 
157
    def setUp(self):
 
158
        test_push.TestPushStrictWithoutChanges.setUp(self)
 
159
        TestDpushStrictMixin.setUp(self)
 
160
 
 
161
 
 
162
class TestDpushStrictWithChanges(TestDpushStrictMixin,
 
163
                                 test_push.TestPushStrictWithChanges):
 
164
 
 
165
    scenarios = test_push.strict_push_change_scenarios
 
166
 
 
167
    _changes_type = None # Set by load_tests
 
168
 
 
169
    def setUp(self):
 
170
        test_push.TestPushStrictWithChanges.setUp(self)
 
171
        TestDpushStrictMixin.setUp(self)
 
172
 
 
173
    def test_push_with_revision(self):
 
174
        raise tests.TestNotApplicable('dpush does not handle --revision')