~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

- improved handling of non-ascii branch names and test
  patch from Joel Rosdahl

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""Test the uncommit command."""
18
 
 
19
 
import os
20
 
 
21
 
from bzrlib import uncommit, workingtree
22
 
from bzrlib.bzrdir import BzrDirMetaFormat1
23
 
from bzrlib.errors import BzrError, BoundBranchOutOfDate
24
 
from bzrlib.tests import TestCaseWithTransport
25
 
 
26
 
 
27
 
class TestUncommit(TestCaseWithTransport):
28
 
 
29
 
    def create_simple_tree(self):
30
 
        wt = self.make_branch_and_tree('tree')
31
 
        self.build_tree(['tree/a', 'tree/b', 'tree/c'])
32
 
        wt.add(['a', 'b', 'c'])
33
 
        wt.commit('initial commit', rev_id='a1')
34
 
 
35
 
        open('tree/a', 'wb').write('new contents of a\n')
36
 
        wt.commit('second commit', rev_id='a2')
37
 
 
38
 
        return wt
39
 
 
40
 
    def test_uncommit(self):
41
 
        """Test uncommit functionality."""
42
 
        wt = self.create_simple_tree()
43
 
 
44
 
        os.chdir('tree')
45
 
        out, err = self.run_bzr('uncommit', '--dry-run', '--force')
46
 
        self.assertContainsRe(out, 'Dry-run')
47
 
        self.assertNotContainsRe(out, 'initial commit')
48
 
        self.assertContainsRe(out, 'second commit')
49
 
 
50
 
        # Nothing has changed
51
 
        self.assertEqual(['a2'], wt.get_parent_ids())
52
 
 
53
 
        # Uncommit, don't prompt
54
 
        out, err = self.run_bzr('uncommit', '--force')
55
 
        self.assertNotContainsRe(out, 'initial commit')
56
 
        self.assertContainsRe(out, 'second commit')
57
 
 
58
 
        # This should look like we are back in revno 1
59
 
        self.assertEqual(['a1'], wt.get_parent_ids())
60
 
        out, err = self.run_bzr('status')
61
 
        self.assertEquals(out, 'modified:\n  a\n')
62
 
 
63
 
    def test_uncommit_checkout(self):
64
 
        wt = self.create_simple_tree()
65
 
        checkout_tree = wt.branch.create_checkout('checkout')
66
 
 
67
 
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
68
 
 
69
 
        os.chdir('checkout')
70
 
        out, err = self.run_bzr('uncommit', '--dry-run', '--force')
71
 
        self.assertContainsRe(out, 'Dry-run')
72
 
        self.assertNotContainsRe(out, 'initial commit')
73
 
        self.assertContainsRe(out, 'second commit')
74
 
 
75
 
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
76
 
 
77
 
        out, err = self.run_bzr('uncommit', '--force')
78
 
        self.assertNotContainsRe(out, 'initial commit')
79
 
        self.assertContainsRe(out, 'second commit')
80
 
 
81
 
        # uncommit in a checkout should uncommit the parent branch
82
 
        # (but doesn't effect the other working tree)
83
 
        self.assertEquals(['a1'], checkout_tree.get_parent_ids())
84
 
        self.assertEquals('a1', wt.branch.last_revision())
85
 
        self.assertEquals(['a2'], wt.get_parent_ids())
86
 
 
87
 
    def test_uncommit_bound(self):
88
 
        os.mkdir('a')
89
 
        a = BzrDirMetaFormat1().initialize('a')
90
 
        a.create_repository()
91
 
        a.create_branch()
92
 
        t_a = a.create_workingtree()
93
 
        t_a.commit('commit 1')
94
 
        t_a.commit('commit 2')
95
 
        t_a.commit('commit 3')
96
 
        b = t_a.branch.create_checkout('b').branch
97
 
        uncommit.uncommit(b)
98
 
        self.assertEqual(len(b.revision_history()), 2)
99
 
        self.assertEqual(len(t_a.branch.revision_history()), 2)
100
 
        # update A's tree to not have the uncomitted revision referenced.
101
 
        t_a.update()
102
 
        t_a.commit('commit 3b')
103
 
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
104
 
        b.pull(t_a.branch)
105
 
        uncommit.uncommit(b)
106
 
 
107
 
    def test_uncommit_revision(self):
108
 
        wt = self.create_simple_tree()
109
 
 
110
 
        os.chdir('tree')
111
 
        out, err = self.run_bzr('uncommit', '-r1', '--force')
112
 
 
113
 
        self.assertNotContainsRe(out, 'initial commit')
114
 
        self.assertContainsRe(out, 'second commit')
115
 
        self.assertEqual(['a1'], wt.get_parent_ids())
116
 
        self.assertEqual('a1', wt.branch.last_revision())
117
 
 
118
 
    def test_uncommit_neg_1(self):
119
 
        wt = self.create_simple_tree()
120
 
        os.chdir('tree')
121
 
        out, err = self.run_bzr('uncommit', '-r', '-1', retcode=1)
122
 
        self.assertEqual('No revisions to uncommit.\n', out)
123
 
 
124
 
    def test_uncommit_merges(self):
125
 
        wt = self.create_simple_tree()
126
 
 
127
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
128
 
 
129
 
        tree2.commit('unchanged', rev_id='b3')
130
 
        tree2.commit('unchanged', rev_id='b4')
131
 
 
132
 
        wt.merge_from_branch(tree2.branch)
133
 
        wt.commit('merge b4', rev_id='a3')
134
 
 
135
 
        self.assertEqual(['a3'], wt.get_parent_ids())
136
 
 
137
 
        os.chdir('tree')
138
 
        out, err = self.run_bzr('uncommit', '--force')
139
 
 
140
 
        self.assertEqual(['a2', 'b4'], wt.get_parent_ids())
141
 
 
142
 
    def test_uncommit_pending_merge(self):
143
 
        wt = self.create_simple_tree()
144
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
145
 
        tree2.commit('unchanged', rev_id='b3')
146
 
 
147
 
        wt.branch.fetch(tree2.branch)
148
 
        wt.set_pending_merges(['b3'])
149
 
 
150
 
        os.chdir('tree')
151
 
        out, err = self.run_bzr('uncommit', '--force')
152
 
        self.assertEqual(['a1', 'b3'], wt.get_parent_ids())
153
 
 
154
 
    def test_uncommit_multiple_merge(self):
155
 
        wt = self.create_simple_tree()
156
 
 
157
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
158
 
 
159
 
        tree2.commit('unchanged', rev_id='b3')
160
 
 
161
 
        wt.merge_from_branch(tree2.branch)
162
 
        wt.commit('merge b3', rev_id='a3')
163
 
 
164
 
        tree2.commit('unchanged', rev_id='b4')
165
 
 
166
 
        wt.merge_from_branch(tree2.branch)
167
 
        wt.commit('merge b4', rev_id='a4')
168
 
 
169
 
        self.assertEqual(['a4'], wt.get_parent_ids())
170
 
 
171
 
        os.chdir('tree')
172
 
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
173
 
 
174
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
175
 
 
176
 
    def test_uncommit_merge_plus_pending(self):
177
 
        wt = self.create_simple_tree()
178
 
 
179
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
180
 
 
181
 
        tree2.commit('unchanged', rev_id='b3')
182
 
        wt.branch.fetch(tree2.branch)
183
 
        wt.set_pending_merges(['b3'])
184
 
        wt.commit('merge b3', rev_id='a3')
185
 
 
186
 
        tree2.commit('unchanged', rev_id='b4')
187
 
        wt.branch.fetch(tree2.branch)
188
 
        wt.set_pending_merges(['b4'])
189
 
 
190
 
        self.assertEqual(['a3', 'b4'], wt.get_parent_ids())
191
 
 
192
 
        os.chdir('tree')
193
 
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
194
 
 
195
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
196
 
 
197
 
    def test_uncommit_octopus_merge(self):
198
 
        # Check that uncommit keeps the pending merges in the same order
199
 
        wt = self.create_simple_tree()
200
 
 
201
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
202
 
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
203
 
 
204
 
        tree2.commit('unchanged', rev_id='b3')
205
 
        tree3.commit('unchanged', rev_id='c3')
206
 
        
207
 
        wt.merge_from_branch(tree2.branch)
208
 
        wt.merge_from_branch(tree3.branch)
209
 
        wt.commit('merge b3, c3', rev_id='a3')
210
 
 
211
 
        tree2.commit('unchanged', rev_id='b4')
212
 
        tree3.commit('unchanged', rev_id='c4')
213
 
 
214
 
        wt.merge_from_branch(tree3.branch)
215
 
        wt.merge_from_branch(tree2.branch)
216
 
        wt.commit('merge b4, c4', rev_id='a4')
217
 
 
218
 
        self.assertEqual(['a4'], wt.get_parent_ids())
219
 
 
220
 
        os.chdir('tree')
221
 
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
222
 
 
223
 
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())