/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

Merge updated set_parents api.

Show diffs side-by-side

added added

removed removed

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