1850.3.4
by John Arbash Meinel
Add copyright to test_uncommit.py |
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."""
|
|
1558.1.12
by Aaron Bentley
Got uncommit working properly with checkouts |
18 |
|
19 |
import os |
|
20 |
||
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
21 |
from bzrlib import uncommit, workingtree |
1558.9.1
by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking |
22 |
from bzrlib.bzrdir import BzrDirMetaFormat1 |
23 |
from bzrlib.errors import BzrError, BoundBranchOutOfDate |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
24 |
from bzrlib.tests import TestCaseWithTransport |
25 |
||
26 |
||
27 |
class TestUncommit(TestCaseWithTransport): |
|
1956.1.1
by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges |
28 |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
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']) |
|
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
33 |
wt.commit('initial commit', rev_id='a1') |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
34 |
|
35 |
open('tree/a', 'wb').write('new contents of a\n') |
|
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
36 |
wt.commit('second commit', rev_id='a2') |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
37 |
|
38 |
return wt |
|
39 |
||
0.3.11
by John Arbash Meinel
Updated to latest bzr.dev code, and added tests. |
40 |
def test_uncommit(self): |
41 |
"""Test uncommit functionality."""
|
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
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') |
|
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
47 |
self.assertNotContainsRe(out, 'initial commit') |
48 |
self.assertContainsRe(out, 'second commit') |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
49 |
|
50 |
# Nothing has changed
|
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
51 |
self.assertEqual(['a2'], wt.get_parent_ids()) |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
52 |
|
53 |
# Uncommit, don't prompt
|
|
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
54 |
out, err = self.run_bzr('uncommit', '--force') |
55 |
self.assertNotContainsRe(out, 'initial commit') |
|
56 |
self.assertContainsRe(out, 'second commit') |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
57 |
|
58 |
# This should look like we are back in revno 1
|
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
59 |
self.assertEqual(['a1'], wt.get_parent_ids()) |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
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 |
||
66 |
checkout_tree = wt.bzrdir.sprout('checkout').open_workingtree() |
|
67 |
checkout_tree.branch.bind(wt.branch) |
|
68 |
||
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
69 |
self.assertEqual(['a2'], checkout_tree.get_parent_ids()) |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
70 |
|
71 |
os.chdir('checkout') |
|
72 |
out, err = self.run_bzr('uncommit', '--dry-run', '--force') |
|
73 |
self.assertContainsRe(out, 'Dry-run') |
|
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
74 |
self.assertNotContainsRe(out, 'initial commit') |
75 |
self.assertContainsRe(out, 'second commit') |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
76 |
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
77 |
self.assertEqual(['a2'], checkout_tree.get_parent_ids()) |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
78 |
|
79 |
out, err = self.run_bzr('uncommit', '--force') |
|
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
80 |
self.assertNotContainsRe(out, 'initial commit') |
81 |
self.assertContainsRe(out, 'second commit') |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
82 |
|
83 |
# uncommit in a checkout should uncommit the parent branch
|
|
84 |
# (but doesn't effect the other working tree)
|
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
85 |
self.assertEquals(['a1'], checkout_tree.get_parent_ids()) |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
86 |
self.assertEquals('a1', wt.branch.last_revision()) |
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
87 |
self.assertEquals(['a2'], wt.get_parent_ids()) |
1558.9.1
by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking |
88 |
|
89 |
def test_uncommit_bound(self): |
|
90 |
os.mkdir('a') |
|
91 |
a = BzrDirMetaFormat1().initialize('a') |
|
92 |
a.create_repository() |
|
93 |
a.create_branch() |
|
1908.6.1
by Robert Collins
Change all callers of set_last_revision to use set_parent_trees. |
94 |
t_a = a.create_workingtree() |
95 |
t_a.commit('commit 1') |
|
96 |
t_a.commit('commit 2') |
|
97 |
t_a.commit('commit 3') |
|
98 |
b = t_a.bzrdir.sprout('b').open_branch() |
|
99 |
b.bind(t_a.branch) |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
100 |
uncommit.uncommit(b) |
1558.9.1
by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking |
101 |
self.assertEqual(len(b.revision_history()), 2) |
1908.6.1
by Robert Collins
Change all callers of set_last_revision to use set_parent_trees. |
102 |
self.assertEqual(len(t_a.branch.revision_history()), 2) |
103 |
# update A's tree to not have the uncomitted revision referenced.
|
|
104 |
t_a.update() |
|
105 |
t_a.commit('commit 3b') |
|
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
106 |
self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b) |
1908.6.1
by Robert Collins
Change all callers of set_last_revision to use set_parent_trees. |
107 |
b.pull(t_a.branch) |
1850.3.1
by John Arbash Meinel
cleanup the uncommit tests |
108 |
uncommit.uncommit(b) |
1558.9.1
by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking |
109 |
|
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
110 |
def test_uncommit_revision(self): |
111 |
wt = self.create_simple_tree() |
|
112 |
||
113 |
os.chdir('tree') |
|
114 |
out, err = self.run_bzr('uncommit', '-r1', '--force') |
|
115 |
||
116 |
self.assertNotContainsRe(out, 'initial commit') |
|
117 |
self.assertContainsRe(out, 'second commit') |
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
118 |
self.assertEqual(['a1'], wt.get_parent_ids()) |
1850.3.2
by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10 |
119 |
self.assertEqual('a1', wt.branch.last_revision()) |
120 |
||
121 |
def test_uncommit_neg_1(self): |
|
122 |
wt = self.create_simple_tree() |
|
123 |
os.chdir('tree') |
|
124 |
out, err = self.run_bzr('uncommit', '-r', '-1', retcode=1) |
|
125 |
self.assertEqual('No revisions to uncommit.\n', out) |
|
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
126 |
|
127 |
def test_uncommit_merges(self): |
|
128 |
wt = self.create_simple_tree() |
|
129 |
||
130 |
tree2 = wt.bzrdir.sprout('tree2').open_workingtree() |
|
131 |
||
132 |
tree2.commit('unchanged', rev_id='b3') |
|
133 |
tree2.commit('unchanged', rev_id='b4') |
|
134 |
||
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
135 |
wt.merge_from_branch(tree2.branch) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
136 |
wt.commit('merge b4', rev_id='a3') |
137 |
||
1908.6.11
by Robert Collins
Remove usage of tree.pending_merges(). |
138 |
self.assertEqual(['a3'], wt.get_parent_ids()) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
139 |
|
140 |
os.chdir('tree') |
|
141 |
out, err = self.run_bzr('uncommit', '--force') |
|
142 |
||
1908.6.11
by Robert Collins
Remove usage of tree.pending_merges(). |
143 |
self.assertEqual(['a2', 'b4'], wt.get_parent_ids()) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
144 |
|
1956.1.1
by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges |
145 |
def test_uncommit_pending_merge(self): |
146 |
wt = self.create_simple_tree() |
|
147 |
tree2 = wt.bzrdir.sprout('tree2').open_workingtree() |
|
148 |
tree2.commit('unchanged', rev_id='b3') |
|
149 |
||
150 |
wt.branch.fetch(tree2.branch) |
|
151 |
wt.set_pending_merges(['b3']) |
|
152 |
||
153 |
os.chdir('tree') |
|
154 |
out, err = self.run_bzr('uncommit', '--force') |
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
155 |
self.assertEqual(['a1', 'b3'], wt.get_parent_ids()) |
1956.1.1
by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges |
156 |
|
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
157 |
def test_uncommit_multiple_merge(self): |
158 |
wt = self.create_simple_tree() |
|
159 |
||
160 |
tree2 = wt.bzrdir.sprout('tree2').open_workingtree() |
|
161 |
||
162 |
tree2.commit('unchanged', rev_id='b3') |
|
1908.6.7
by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly. |
163 |
|
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
164 |
wt.merge_from_branch(tree2.branch) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
165 |
wt.commit('merge b3', rev_id='a3') |
166 |
||
167 |
tree2.commit('unchanged', rev_id='b4') |
|
1908.6.7
by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly. |
168 |
|
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
169 |
wt.merge_from_branch(tree2.branch) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
170 |
wt.commit('merge b4', rev_id='a4') |
171 |
||
1908.6.11
by Robert Collins
Remove usage of tree.pending_merges(). |
172 |
self.assertEqual(['a4'], wt.get_parent_ids()) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
173 |
|
174 |
os.chdir('tree') |
|
175 |
out, err = self.run_bzr('uncommit', '--force', '-r', '2') |
|
176 |
||
1908.6.11
by Robert Collins
Remove usage of tree.pending_merges(). |
177 |
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids()) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
178 |
|
1956.1.1
by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges |
179 |
def test_uncommit_merge_plus_pending(self): |
180 |
wt = self.create_simple_tree() |
|
181 |
||
182 |
tree2 = wt.bzrdir.sprout('tree2').open_workingtree() |
|
183 |
||
184 |
tree2.commit('unchanged', rev_id='b3') |
|
185 |
wt.branch.fetch(tree2.branch) |
|
186 |
wt.set_pending_merges(['b3']) |
|
187 |
wt.commit('merge b3', rev_id='a3') |
|
188 |
||
189 |
tree2.commit('unchanged', rev_id='b4') |
|
190 |
wt.branch.fetch(tree2.branch) |
|
191 |
wt.set_pending_merges(['b4']) |
|
192 |
||
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
193 |
self.assertEqual(['a3', 'b4'], wt.get_parent_ids()) |
1956.1.1
by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges |
194 |
|
195 |
os.chdir('tree') |
|
196 |
out, err = self.run_bzr('uncommit', '--force', '-r', '2') |
|
197 |
||
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
198 |
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids()) |
1956.1.1
by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges |
199 |
|
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
200 |
def test_uncommit_octopus_merge(self): |
201 |
# Check that uncommit keeps the pending merges in the same order
|
|
202 |
wt = self.create_simple_tree() |
|
203 |
||
204 |
tree2 = wt.bzrdir.sprout('tree2').open_workingtree() |
|
205 |
tree3 = wt.bzrdir.sprout('tree3').open_workingtree() |
|
206 |
||
207 |
tree2.commit('unchanged', rev_id='b3') |
|
208 |
tree3.commit('unchanged', rev_id='c3') |
|
1908.6.7
by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly. |
209 |
|
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
210 |
wt.merge_from_branch(tree2.branch) |
211 |
wt.merge_from_branch(tree3.branch) |
|
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
212 |
wt.commit('merge b3, c3', rev_id='a3') |
213 |
||
214 |
tree2.commit('unchanged', rev_id='b4') |
|
215 |
tree3.commit('unchanged', rev_id='c4') |
|
1908.6.7
by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly. |
216 |
|
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
217 |
wt.merge_from_branch(tree3.branch) |
218 |
wt.merge_from_branch(tree2.branch) |
|
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
219 |
wt.commit('merge b4, c4', rev_id='a4') |
220 |
||
1908.6.11
by Robert Collins
Remove usage of tree.pending_merges(). |
221 |
self.assertEqual(['a4'], wt.get_parent_ids()) |
1850.3.5
by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges. |
222 |
|
223 |
os.chdir('tree') |
|
224 |
out, err = self.run_bzr('uncommit', '--force', '-r', '2') |
|
225 |
||
1908.6.11
by Robert Collins
Remove usage of tree.pending_merges(). |
226 |
self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids()) |