~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2006-07-20 13:00:31 UTC
  • mto: (1852.9.1 Tree.compare().)
  • mto: This revision was merged to the branch mainline in revision 1890.
  • Revision ID: robertc@robertcollins.net-20060720130031-d26103a427ea10f3
StartĀ treeĀ implementationĀ tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Test the uncommit command."""
18
18
 
25
25
 
26
26
 
27
27
class TestUncommit(TestCaseWithTransport):
28
 
 
29
28
    def create_simple_tree(self):
30
29
        wt = self.make_branch_and_tree('tree')
31
30
        self.build_tree(['tree/a', 'tree/b', 'tree/c'])
32
31
        wt.add(['a', 'b', 'c'])
33
32
        wt.commit('initial commit', rev_id='a1')
34
33
 
35
 
        self.build_tree_contents([('tree/a', 'new contents of a\n')])
 
34
        open('tree/a', 'wb').write('new contents of a\n')
36
35
        wt.commit('second commit', rev_id='a2')
37
36
 
38
37
        return wt
42
41
        wt = self.create_simple_tree()
43
42
 
44
43
        os.chdir('tree')
45
 
        out, err = self.run_bzr('uncommit --dry-run --force')
 
44
        out, err = self.run_bzr('uncommit', '--dry-run', '--force')
46
45
        self.assertContainsRe(out, 'Dry-run')
47
46
        self.assertNotContainsRe(out, 'initial commit')
48
47
        self.assertContainsRe(out, 'second commit')
49
48
 
50
49
        # Nothing has changed
51
 
        self.assertEqual(['a2'], wt.get_parent_ids())
 
50
        self.assertEqual('a2', wt.last_revision())
52
51
 
53
52
        # Uncommit, don't prompt
54
 
        out, err = self.run_bzr('uncommit --force')
 
53
        out, err = self.run_bzr('uncommit', '--force')
55
54
        self.assertNotContainsRe(out, 'initial commit')
56
55
        self.assertContainsRe(out, 'second commit')
57
56
 
58
57
        # This should look like we are back in revno 1
59
 
        self.assertEqual(['a1'], wt.get_parent_ids())
 
58
        self.assertEqual('a1', wt.last_revision())
60
59
        out, err = self.run_bzr('status')
61
60
        self.assertEquals(out, 'modified:\n  a\n')
62
61
 
63
 
    def test_uncommit_no_history(self):
64
 
        wt = self.make_branch_and_tree('tree')
65
 
        out, err = self.run_bzr('uncommit --force', retcode=1)
66
 
        self.assertEqual('', err)
67
 
        self.assertEqual('No revisions to uncommit.\n', out)
68
 
 
69
62
    def test_uncommit_checkout(self):
70
63
        wt = self.create_simple_tree()
71
 
        checkout_tree = wt.branch.create_checkout('checkout')
72
 
 
73
 
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
 
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())
74
69
 
75
70
        os.chdir('checkout')
76
 
        out, err = self.run_bzr('uncommit --dry-run --force')
 
71
        out, err = self.run_bzr('uncommit', '--dry-run', '--force')
77
72
        self.assertContainsRe(out, 'Dry-run')
78
73
        self.assertNotContainsRe(out, 'initial commit')
79
74
        self.assertContainsRe(out, 'second commit')
80
75
 
81
 
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
 
76
        self.assertEqual('a2', checkout_tree.last_revision())
82
77
 
83
 
        out, err = self.run_bzr('uncommit --force')
 
78
        out, err = self.run_bzr('uncommit', '--force')
84
79
        self.assertNotContainsRe(out, 'initial commit')
85
80
        self.assertContainsRe(out, 'second commit')
86
81
 
87
82
        # uncommit in a checkout should uncommit the parent branch
88
83
        # (but doesn't effect the other working tree)
89
 
        self.assertEquals(['a1'], checkout_tree.get_parent_ids())
 
84
        self.assertEquals('a1', checkout_tree.last_revision())
90
85
        self.assertEquals('a1', wt.branch.last_revision())
91
 
        self.assertEquals(['a2'], wt.get_parent_ids())
 
86
        self.assertEquals('a2', wt.last_revision())
92
87
 
93
88
    def test_uncommit_bound(self):
94
89
        os.mkdir('a')
95
90
        a = BzrDirMetaFormat1().initialize('a')
96
91
        a.create_repository()
97
92
        a.create_branch()
98
 
        t_a = a.create_workingtree()
99
 
        t_a.commit('commit 1')
100
 
        t_a.commit('commit 2')
101
 
        t_a.commit('commit 3')
102
 
        b = t_a.branch.create_checkout('b').branch
 
93
        t = a.create_workingtree()
 
94
        t.commit('commit 1')
 
95
        t.commit('commit 2')
 
96
        t.commit('commit 3')
 
97
        b = t.bzrdir.sprout('b').open_branch()
 
98
        b.bind(t.branch)
103
99
        uncommit.uncommit(b)
 
100
        t.set_last_revision(t.branch.last_revision())
104
101
        self.assertEqual(len(b.revision_history()), 2)
105
 
        self.assertEqual(len(t_a.branch.revision_history()), 2)
106
 
        # update A's tree to not have the uncommitted revision referenced.
107
 
        t_a.update()
108
 
        t_a.commit('commit 3b')
 
102
        self.assertEqual(len(t.branch.revision_history()), 2)
 
103
        t.commit('commit 3b')
109
104
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
110
 
        b.pull(t_a.branch)
 
105
        b.pull(t.branch)
111
106
        uncommit.uncommit(b)
112
107
 
113
 
    def test_uncommit_bound_local(self):
114
 
        t_a = self.make_branch_and_tree('a')
115
 
        rev_id1 = t_a.commit('commit 1')
116
 
        rev_id2 = t_a.commit('commit 2')
117
 
        rev_id3 = t_a.commit('commit 3')
118
 
        b = t_a.branch.create_checkout('b').branch
119
 
 
120
 
        out, err = self.run_bzr(['uncommit', '--local', 'b', '--force'])
121
 
        self.assertEqual(rev_id3, t_a.last_revision())
122
 
        self.assertEqual((3, rev_id3), t_a.branch.last_revision_info())
123
 
        self.assertEqual((2, rev_id2), b.last_revision_info())
124
 
 
125
108
    def test_uncommit_revision(self):
126
109
        wt = self.create_simple_tree()
127
110
 
128
111
        os.chdir('tree')
129
 
        out, err = self.run_bzr('uncommit -r1 --force')
 
112
        out, err = self.run_bzr('uncommit', '-r1', '--force')
130
113
 
131
114
        self.assertNotContainsRe(out, 'initial commit')
132
115
        self.assertContainsRe(out, 'second commit')
133
 
        self.assertEqual(['a1'], wt.get_parent_ids())
 
116
        self.assertEqual('a1', wt.last_revision())
134
117
        self.assertEqual('a1', wt.branch.last_revision())
135
118
 
136
119
    def test_uncommit_neg_1(self):
137
120
        wt = self.create_simple_tree()
138
121
        os.chdir('tree')
139
 
        out, err = self.run_bzr('uncommit -r -1', retcode=1)
 
122
        out, err = self.run_bzr('uncommit', '-r', '-1', retcode=1)
140
123
        self.assertEqual('No revisions to uncommit.\n', out)
141
124
 
142
125
    def test_uncommit_merges(self):
147
130
        tree2.commit('unchanged', rev_id='b3')
148
131
        tree2.commit('unchanged', rev_id='b4')
149
132
 
150
 
        wt.merge_from_branch(tree2.branch)
 
133
        wt.branch.fetch(tree2.branch)
 
134
        wt.set_pending_merges(['b4'])
151
135
        wt.commit('merge b4', rev_id='a3')
152
136
 
153
 
        self.assertEqual(['a3'], wt.get_parent_ids())
154
 
 
155
 
        os.chdir('tree')
156
 
        out, err = self.run_bzr('uncommit --force')
157
 
 
158
 
        self.assertEqual(['a2', 'b4'], wt.get_parent_ids())
159
 
 
160
 
    def test_uncommit_pending_merge(self):
161
 
        wt = self.create_simple_tree()
162
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
163
 
        tree2.commit('unchanged', rev_id='b3')
164
 
 
165
 
        wt.branch.fetch(tree2.branch)
166
 
        wt.set_pending_merges(['b3'])
167
 
 
168
 
        os.chdir('tree')
169
 
        out, err = self.run_bzr('uncommit --force')
170
 
        self.assertEqual(['a1', 'b3'], wt.get_parent_ids())
 
137
        self.assertEqual('a3', wt.last_revision())
 
138
        self.assertEqual([], wt.pending_merges())
 
139
 
 
140
        os.chdir('tree')
 
141
        out, err = self.run_bzr('uncommit', '--force')
 
142
 
 
143
        self.assertEqual('a2', wt.last_revision())
 
144
        self.assertEqual(['b4'], wt.pending_merges())
171
145
 
172
146
    def test_uncommit_multiple_merge(self):
173
147
        wt = self.create_simple_tree()
174
148
 
175
149
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
176
 
        tree2.commit('unchanged', rev_id='b3')
177
 
 
178
 
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
179
 
        tree3.commit('unchanged', rev_id='c3')
180
 
 
181
 
        wt.merge_from_branch(tree2.branch)
182
 
        wt.commit('merge b3', rev_id='a3')
183
 
 
184
 
        wt.merge_from_branch(tree3.branch)
185
 
        wt.commit('merge c3', rev_id='a4')
186
 
 
187
 
        self.assertEqual(['a4'], wt.get_parent_ids())
188
 
 
189
 
        os.chdir('tree')
190
 
        out, err = self.run_bzr('uncommit --force -r 2')
191
 
 
192
 
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
193
 
 
194
 
    def test_uncommit_merge_plus_pending(self):
195
 
        wt = self.create_simple_tree()
196
 
 
197
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
198
 
        tree2.commit('unchanged', rev_id='b3')
199
 
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
200
 
        tree3.commit('unchanged', rev_id='c3')
201
 
 
 
150
 
 
151
        tree2.commit('unchanged', rev_id='b3')
202
152
        wt.branch.fetch(tree2.branch)
203
153
        wt.set_pending_merges(['b3'])
204
154
        wt.commit('merge b3', rev_id='a3')
205
155
 
206
 
 
207
 
        wt.merge_from_branch(tree3.branch)
208
 
 
209
 
        self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
 
156
        tree2.commit('unchanged', rev_id='b4')
 
157
        wt.branch.fetch(tree2.branch)
 
158
        wt.set_pending_merges(['b4'])
 
159
        wt.commit('merge b4', rev_id='a4')
 
160
 
 
161
        self.assertEqual('a4', wt.last_revision())
 
162
        self.assertEqual([], wt.pending_merges())
210
163
 
211
164
        os.chdir('tree')
212
 
        out, err = self.run_bzr('uncommit --force -r 2')
213
 
 
214
 
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
215
 
 
216
 
    def test_uncommit_shows_log_with_revision_id(self):
217
 
        wt = self.create_simple_tree()
218
 
 
219
 
        out, err = self.run_bzr('uncommit --force', working_dir='tree')
220
 
        self.assertContainsRe(out, r'second commit')
221
 
        self.assertContainsRe(err, r'You can restore the old tip by running')
222
 
        self.assertContainsRe(err, r'bzr pull . -r revid:a2')
 
165
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
 
166
 
 
167
        self.assertEqual('a2', wt.last_revision())
 
168
        self.assertEqual(['b3', 'b4'], wt.pending_merges())
223
169
 
224
170
    def test_uncommit_octopus_merge(self):
225
171
        # Check that uncommit keeps the pending merges in the same order
226
 
        # though it will also filter out ones in the ancestry
227
172
        wt = self.create_simple_tree()
228
173
 
229
174
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
231
176
 
232
177
        tree2.commit('unchanged', rev_id='b3')
233
178
        tree3.commit('unchanged', rev_id='c3')
234
 
 
235
 
        wt.merge_from_branch(tree2.branch)
236
 
        wt.merge_from_branch(tree3.branch, force=True)
 
179
        wt.branch.fetch(tree2.branch)
 
180
        wt.branch.fetch(tree3.branch)
 
181
        wt.set_pending_merges(['b3', 'c3'])
237
182
        wt.commit('merge b3, c3', rev_id='a3')
238
183
 
239
184
        tree2.commit('unchanged', rev_id='b4')
240
185
        tree3.commit('unchanged', rev_id='c4')
241
 
 
242
 
        wt.merge_from_branch(tree3.branch)
243
 
        wt.merge_from_branch(tree2.branch, force=True)
 
186
        wt.branch.fetch(tree2.branch)
 
187
        wt.branch.fetch(tree3.branch)
 
188
        wt.set_pending_merges(['c4', 'b4'])
244
189
        wt.commit('merge b4, c4', rev_id='a4')
245
190
 
246
 
        self.assertEqual(['a4'], wt.get_parent_ids())
 
191
        self.assertEqual('a4', wt.last_revision())
 
192
        self.assertEqual([], wt.pending_merges())
247
193
 
248
194
        os.chdir('tree')
249
 
        out, err = self.run_bzr('uncommit --force -r 2')
250
 
 
251
 
        self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
252
 
 
253
 
    def test_uncommit_nonascii(self):
254
 
        tree = self.make_branch_and_tree('tree')
255
 
        tree.commit(u'\u1234 message')
256
 
        out, err = self.run_bzr('uncommit --force tree', encoding='ascii')
257
 
        self.assertContainsRe(out, r'\? message')
 
195
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
 
196
 
 
197
        self.assertEqual('a2', wt.last_revision())
 
198
        self.assertEqual(['b3', 'c3', 'c4', 'b4'], wt.pending_merges())