/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
1692.3.1 by Robert Collins
Fix push to work with just a branch, no need for a working tree.
19
"""Black-box tests for bzr push."""
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
20
21
import os
22
1692.3.1 by Robert Collins
Fix push to work with just a branch, no need for a working tree.
23
import bzrlib
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
24
from bzrlib.branch import Branch
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
25
from bzrlib.bzrdir import BzrDirMetaFormat1
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
26
from bzrlib.osutils import abspath
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
27
from bzrlib.repository import RepositoryFormatKnit1
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
28
from bzrlib.tests.blackbox import ExternalBase
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
29
from bzrlib.uncommit import uncommit
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
30
from bzrlib.workingtree import WorkingTree
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
31
32
33
class TestPush(ExternalBase):
34
35
    def test_push_remember(self):
36
        """Push changes from one branch to another and test push location."""
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
37
        transport = self.get_transport()
38
        tree_a = self.make_branch_and_tree('branch_a')
39
        branch_a = tree_a.branch
40
        self.build_tree(['branch_a/a'])
41
        tree_a.add('a')
42
        tree_a.commit('commit a')
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
43
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
44
        branch_b = tree_b.branch
45
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
46
        branch_c = tree_c.branch
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
47
        self.build_tree(['branch_a/b'])
48
        tree_a.add('b')
49
        tree_a.commit('commit b')
50
        self.build_tree(['branch_b/c'])
51
        tree_b.add('c')
52
        tree_b.commit('commit c')
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
53
        # initial push location must be empty
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
54
        self.assertEqual(None, branch_b.get_push_location())
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
55
        # test push for failure without push location set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
56
        os.chdir('branch_a')
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
57
        out = self.runbzr('push', retcode=3)
58
        self.assertEquals(out,
59
                ('','bzr: ERROR: No push location known or specified.\n'))
60
        # test implicit --remember when no push location set, push fails
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
61
        out = self.runbzr('push ../branch_b', retcode=3)
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
62
        self.assertEquals(out,
63
                ('','bzr: ERROR: These branches have diverged.  '
64
                    'Try a merge then push with overwrite.\n'))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
65
        self.assertEquals(abspath(branch_a.get_push_location()),
66
                          abspath(branch_b.bzrdir.root_transport.base))
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
67
        # test implicit --remember after resolving previous failure
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
68
        uncommit(branch=branch_b, tree=tree_b)
69
        transport.delete('branch_b/c')
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
70
        self.runbzr('push')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
71
        self.assertEquals(abspath(branch_a.get_push_location()),
72
                          abspath(branch_b.bzrdir.root_transport.base))
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
73
        # test explicit --remember
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
74
        self.runbzr('push ../branch_c --remember')
75
        self.assertEquals(abspath(branch_a.get_push_location()),
76
                          abspath(branch_c.bzrdir.root_transport.base))
1692.3.1 by Robert Collins
Fix push to work with just a branch, no need for a working tree.
77
    
78
    def test_push_without_tree(self):
79
        # bzr push from a branch that does not have a checkout should work.
80
        b = self.make_branch('.')
81
        out, err = self.run_bzr('push', 'pushed-location')
82
        self.assertEqual('', out)
83
        self.assertEqual('0 revision(s) pushed.\n', err)
84
        b2 = bzrlib.branch.Branch.open('pushed-location')
85
        self.assertEndsWith(b2.base, 'pushed-location/')
1692.3.6 by Robert Collins
Show the correct number of revisions pushed when pushing a new branch (Robert Collins).
86
87
    def test_push_new_branch_revision_count(self):
88
        # bzr push of a branch with revisions to a new location 
89
        # should print the number of revisions equal to the length of the 
90
        # local branch.
91
        t = self.make_branch_and_tree('tree')
92
        self.build_tree(['tree/file'])
93
        t.add('file')
94
        t.commit('commit 1')
95
        os.chdir('tree')
96
        out, err = self.run_bzr('push', 'pushed-to')
97
        os.chdir('..')
98
        self.assertEqual('', out)
99
        self.assertEqual('1 revision(s) pushed.\n', err)
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
100
101
    def test_push_only_pushes_history(self):
102
        # Knit branches should only push the history for the current revision.
103
        format = BzrDirMetaFormat1()
104
        format.repository_format = RepositoryFormatKnit1()
105
        shared_repo = self.make_repository('repo', format=format, shared=True)
106
        shared_repo.set_make_working_trees(True)
107
108
        def make_shared_tree(path):
109
            shared_repo.bzrdir.root_transport.mkdir(path)
110
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
111
            return WorkingTree.open('repo/' + path)
112
        tree_a = make_shared_tree('a')
113
        self.build_tree(['repo/a/file'])
114
        tree_a.add('file')
115
        tree_a.commit('commit a-1', rev_id='a-1')
116
        f = open('repo/a/file', 'ab')
117
        f.write('more stuff\n')
118
        f.close()
119
        tree_a.commit('commit a-2', rev_id='a-2')
120
121
        tree_b = make_shared_tree('b')
122
        self.build_tree(['repo/b/file'])
123
        tree_b.add('file')
124
        tree_b.commit('commit b-1', rev_id='b-1')
125
126
        self.assertTrue(shared_repo.has_revision('a-1'))
127
        self.assertTrue(shared_repo.has_revision('a-2'))
128
        self.assertTrue(shared_repo.has_revision('b-1'))
129
130
        # Now that we have a repository with shared files, make sure
131
        # that things aren't copied out by a 'push'
132
        os.chdir('repo/b')
133
        self.run_bzr('push', '../../push-b')
134
        pushed_tree = WorkingTree.open('../../push-b')
135
        pushed_repo = pushed_tree.branch.repository
136
        self.assertFalse(pushed_repo.has_revision('a-1'))
137
        self.assertFalse(pushed_repo.has_revision('a-2'))
138
        self.assertTrue(pushed_repo.has_revision('b-1'))
139