~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2005, 2007 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
20
19
 
21
20
import os
22
21
 
23
 
import bzrlib
 
22
from bzrlib import (
 
23
    errors,
 
24
    urlutils,
 
25
    )
24
26
from bzrlib.branch import Branch
25
27
from bzrlib.bzrdir import BzrDirMetaFormat1
26
28
from bzrlib.osutils import abspath
27
 
from bzrlib.repository import RepositoryFormatKnit1
 
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
28
30
from bzrlib.tests.blackbox import ExternalBase
29
31
from bzrlib.uncommit import uncommit
30
32
from bzrlib.urlutils import local_path_from_url
56
58
 
57
59
        # test push for failure without push location set
58
60
        os.chdir('branch_a')
59
 
        out = self.runbzr('push', retcode=3)
 
61
        out = self.run_bzr('push', retcode=3)
60
62
        self.assertEquals(out,
61
63
                ('','bzr: ERROR: No push location known or specified.\n'))
62
64
 
71
73
        out = self.run_bzr('push', '../branch_b', retcode=3)
72
74
        self.assertEquals(out,
73
75
                ('','bzr: ERROR: These branches have diverged.  '
74
 
                    'Try a merge then push with overwrite.\n'))
 
76
                    'Try using "merge" and then "push".\n'))
75
77
        self.assertEquals(abspath(branch_a.get_push_location()),
76
78
                          abspath(branch_b.bzrdir.root_transport.base))
77
79
 
78
80
        # test implicit --remember after resolving previous failure
79
81
        uncommit(branch=branch_b, tree=tree_b)
80
82
        transport.delete('branch_b/c')
81
 
        out = self.run_bzr('push')
 
83
        out, err = self.run_bzr('push')
82
84
        path = branch_a.get_push_location()
83
 
        self.assertEquals(('Using saved location: %s\n' 
84
 
                           % (local_path_from_url(path),)
85
 
                          , 'All changes applied successfully.\n'
86
 
                            '1 revision(s) pushed.\n'), out)
 
85
        self.assertEquals(out,
 
86
                          'Using saved location: %s\n' 
 
87
                          'Pushed up to revision 2.\n'
 
88
                          % local_path_from_url(path))
 
89
        self.assertEqual(err,
 
90
                         'All changes applied successfully.\n')
87
91
        self.assertEqual(path,
88
92
                         branch_b.bzrdir.root_transport.base)
89
93
        # test explicit --remember
96
100
        b = self.make_branch('.')
97
101
        out, err = self.run_bzr('push', 'pushed-location')
98
102
        self.assertEqual('', out)
99
 
        self.assertEqual('0 revision(s) pushed.\n', err)
100
 
        b2 = bzrlib.branch.Branch.open('pushed-location')
 
103
        self.assertEqual('Created new branch.\n', err)
 
104
        b2 = Branch.open('pushed-location')
101
105
        self.assertEndsWith(b2.base, 'pushed-location/')
102
106
 
103
107
    def test_push_new_branch_revision_count(self):
112
116
        out, err = self.run_bzr('push', 'pushed-to')
113
117
        os.chdir('..')
114
118
        self.assertEqual('', out)
115
 
        self.assertEqual('1 revision(s) pushed.\n', err)
 
119
        self.assertEqual('Created new branch.\n', err)
116
120
 
117
121
    def test_push_only_pushes_history(self):
118
122
        # Knit branches should only push the history for the current revision.
160
164
        t.add('filename', 'funky-chars<>%&;"\'')
161
165
        t.commit('commit filename')
162
166
        self.run_bzr('push', '../new-tree')
 
167
 
 
168
    def test_push_dash_d(self):
 
169
        t = self.make_branch_and_tree('from')
 
170
        t.commit(allow_pointless=True,
 
171
                message='first commit')
 
172
        self.run_bzr('push -d from to-one')
 
173
        self.failUnlessExists('to-one')
 
174
        self.run_bzr('push -d %s %s' 
 
175
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
 
176
        self.failUnlessExists('to-two')
 
177
 
 
178
    def create_simple_tree(self):
 
179
        tree = self.make_branch_and_tree('tree')
 
180
        self.build_tree(['tree/a'])
 
181
        tree.add(['a'], ['a-id'])
 
182
        tree.commit('one', rev_id='r1')
 
183
        return tree
 
184
 
 
185
    def test_push_create_prefix(self):
 
186
        """'bzr push --create-prefix' will create leading directories."""
 
187
        tree = self.create_simple_tree()
 
188
 
 
189
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
 
190
                           'push', '../new/tree',
 
191
                           working_dir='tree')
 
192
        self.run_bzr('push', '../new/tree', '--create-prefix',
 
193
                     working_dir='tree')
 
194
        new_tree = WorkingTree.open('new/tree')
 
195
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
 
196
        self.failUnlessExists('new/tree/a')
 
197
 
 
198
    def test_push_use_existing(self):
 
199
        """'bzr push --use-existing-dir' can push into an existing dir.
 
200
 
 
201
        By default, 'bzr push' will not use an existing, non-versioned dir.
 
202
        """
 
203
        tree = self.create_simple_tree()
 
204
        self.build_tree(['target/'])
 
205
 
 
206
        self.run_bzr_error(['Target directory ../target already exists',
 
207
                            'Supply --use-existing-dir',
 
208
                           ], 'push', '../target',
 
209
                           working_dir='tree')
 
210
 
 
211
        self.run_bzr('push', '--use-existing-dir', '../target',
 
212
                     working_dir='tree')
 
213
 
 
214
        new_tree = WorkingTree.open('target')
 
215
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
 
216
        # The push should have created target/a
 
217
        self.failUnlessExists('target/a')
 
218
 
 
219
    def test_push_onto_repo(self):
 
220
        """We should be able to 'bzr push' into an existing bzrdir."""
 
221
        tree = self.create_simple_tree()
 
222
        repo = self.make_repository('repo', shared=True)
 
223
 
 
224
        self.run_bzr('push', '../repo',
 
225
                     working_dir='tree')
 
226
 
 
227
        # Pushing onto an existing bzrdir will create a repository and
 
228
        # branch as needed, but will only create a working tree if there was
 
229
        # no BzrDir before.
 
230
        self.assertRaises(errors.NoWorkingTree, WorkingTree.open, 'repo')
 
231
        new_branch = Branch.open('repo')
 
232
        self.assertEqual(tree.last_revision(), new_branch.last_revision())
 
233
 
 
234
    def test_push_onto_just_bzrdir(self):
 
235
        """We don't handle when the target is just a bzrdir.
 
236
 
 
237
        Because you shouldn't be able to create *just* a bzrdir in the wild.
 
238
        """
 
239
        # TODO: jam 20070109 Maybe it would be better to create the repository
 
240
        #       if at this point
 
241
        tree = self.create_simple_tree()
 
242
        a_bzrdir = self.make_bzrdir('dir')
 
243
 
 
244
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
 
245
                'push', '../dir',
 
246
                working_dir='tree')