~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-01 23:48:08 UTC
  • mfrom: (2225.1.6 revert)
  • Revision ID: pqm@pqm.ubuntu.com-20070201234808-3b1302d73474bd8c
Display changes made by revert

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
25
25
 
26
26
 
27
27
class TestUncommit(TestCaseWithTransport):
 
28
 
28
29
    def create_simple_tree(self):
29
30
        wt = self.make_branch_and_tree('tree')
30
31
        self.build_tree(['tree/a', 'tree/b', 'tree/c'])
47
48
        self.assertContainsRe(out, 'second commit')
48
49
 
49
50
        # Nothing has changed
50
 
        self.assertEqual('a2', wt.last_revision())
 
51
        self.assertEqual(['a2'], wt.get_parent_ids())
51
52
 
52
53
        # Uncommit, don't prompt
53
54
        out, err = self.run_bzr('uncommit', '--force')
55
56
        self.assertContainsRe(out, 'second commit')
56
57
 
57
58
        # This should look like we are back in revno 1
58
 
        self.assertEqual('a1', wt.last_revision())
 
59
        self.assertEqual(['a1'], wt.get_parent_ids())
59
60
        out, err = self.run_bzr('status')
60
61
        self.assertEquals(out, 'modified:\n  a\n')
61
62
 
62
63
    def test_uncommit_checkout(self):
63
64
        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())
 
65
        checkout_tree = wt.branch.create_checkout('checkout')
 
66
 
 
67
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
69
68
 
70
69
        os.chdir('checkout')
71
70
        out, err = self.run_bzr('uncommit', '--dry-run', '--force')
73
72
        self.assertNotContainsRe(out, 'initial commit')
74
73
        self.assertContainsRe(out, 'second commit')
75
74
 
76
 
        self.assertEqual('a2', checkout_tree.last_revision())
 
75
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
77
76
 
78
77
        out, err = self.run_bzr('uncommit', '--force')
79
78
        self.assertNotContainsRe(out, 'initial commit')
81
80
 
82
81
        # uncommit in a checkout should uncommit the parent branch
83
82
        # (but doesn't effect the other working tree)
84
 
        self.assertEquals('a1', checkout_tree.last_revision())
 
83
        self.assertEquals(['a1'], checkout_tree.get_parent_ids())
85
84
        self.assertEquals('a1', wt.branch.last_revision())
86
 
        self.assertEquals('a2', wt.last_revision())
 
85
        self.assertEquals(['a2'], wt.get_parent_ids())
87
86
 
88
87
    def test_uncommit_bound(self):
89
88
        os.mkdir('a')
90
89
        a = BzrDirMetaFormat1().initialize('a')
91
90
        a.create_repository()
92
91
        a.create_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)
 
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
99
97
        uncommit.uncommit(b)
100
 
        t.set_last_revision(t.branch.last_revision())
101
98
        self.assertEqual(len(b.revision_history()), 2)
102
 
        self.assertEqual(len(t.branch.revision_history()), 2)
103
 
        t.commit('commit 3b')
 
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')
104
103
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
105
 
        b.pull(t.branch)
 
104
        b.pull(t_a.branch)
106
105
        uncommit.uncommit(b)
107
106
 
108
107
    def test_uncommit_revision(self):
113
112
 
114
113
        self.assertNotContainsRe(out, 'initial commit')
115
114
        self.assertContainsRe(out, 'second commit')
116
 
        self.assertEqual('a1', wt.last_revision())
 
115
        self.assertEqual(['a1'], wt.get_parent_ids())
117
116
        self.assertEqual('a1', wt.branch.last_revision())
118
117
 
119
118
    def test_uncommit_neg_1(self):
130
129
        tree2.commit('unchanged', rev_id='b3')
131
130
        tree2.commit('unchanged', rev_id='b4')
132
131
 
133
 
        wt.branch.fetch(tree2.branch)
134
 
        wt.set_pending_merges(['b4'])
 
132
        wt.merge_from_branch(tree2.branch)
135
133
        wt.commit('merge b4', rev_id='a3')
136
134
 
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())
 
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())
145
153
 
146
154
    def test_uncommit_multiple_merge(self):
147
155
        wt = self.create_simple_tree()
149
157
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
150
158
 
151
159
        tree2.commit('unchanged', rev_id='b3')
152
 
        wt.branch.fetch(tree2.branch)
153
 
        wt.set_pending_merges(['b3'])
 
160
 
 
161
        wt.merge_from_branch(tree2.branch)
154
162
        wt.commit('merge b3', rev_id='a3')
155
163
 
156
164
        tree2.commit('unchanged', rev_id='b4')
157
 
        wt.branch.fetch(tree2.branch)
158
 
        wt.set_pending_merges(['b4'])
 
165
 
 
166
        wt.merge_from_branch(tree2.branch)
159
167
        wt.commit('merge b4', rev_id='a4')
160
168
 
161
 
        self.assertEqual('a4', wt.last_revision())
162
 
        self.assertEqual([], wt.pending_merges())
163
 
 
164
 
        os.chdir('tree')
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())
 
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())
169
196
 
170
197
    def test_uncommit_octopus_merge(self):
171
198
        # Check that uncommit keeps the pending merges in the same order
176
203
 
177
204
        tree2.commit('unchanged', rev_id='b3')
178
205
        tree3.commit('unchanged', rev_id='c3')
179
 
        wt.branch.fetch(tree2.branch)
180
 
        wt.branch.fetch(tree3.branch)
181
 
        wt.set_pending_merges(['b3', 'c3'])
 
206
        
 
207
        wt.merge_from_branch(tree2.branch)
 
208
        wt.merge_from_branch(tree3.branch)
182
209
        wt.commit('merge b3, c3', rev_id='a3')
183
210
 
184
211
        tree2.commit('unchanged', rev_id='b4')
185
212
        tree3.commit('unchanged', rev_id='c4')
186
 
        wt.branch.fetch(tree2.branch)
187
 
        wt.branch.fetch(tree3.branch)
188
 
        wt.set_pending_merges(['c4', 'b4'])
 
213
 
 
214
        wt.merge_from_branch(tree3.branch)
 
215
        wt.merge_from_branch(tree2.branch)
189
216
        wt.commit('merge b4, c4', rev_id='a4')
190
217
 
191
 
        self.assertEqual('a4', wt.last_revision())
192
 
        self.assertEqual([], wt.pending_merges())
 
218
        self.assertEqual(['a4'], wt.get_parent_ids())
193
219
 
194
220
        os.chdir('tree')
195
221
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
196
222
 
197
 
        self.assertEqual('a2', wt.last_revision())
198
 
        self.assertEqual(['b3', 'c3', 'c4', 'b4'], wt.pending_merges())
 
223
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())