1
# Copyright (C) 2008 Canonical Ltd
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.
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.
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
27
class TestUncommit(tests.TestCaseWithTransport):
29
def make_linear_tree(self):
30
tree = self.make_branch_and_tree('tree')
33
self.build_tree(['tree/one'])
35
rev_id1 = tree.commit('one')
36
self.build_tree(['tree/two'])
38
rev_id2 = tree.commit('two')
41
return tree, [rev_id1, rev_id2]
43
def test_uncommit(self):
44
tree, history = self.make_linear_tree()
45
self.assertEqual(history[1], tree.last_revision())
46
self.assertEqual((2, history[1]), tree.branch.last_revision_info())
47
uncommit.uncommit(tree.branch, tree=tree)
48
self.assertEqual(history[0], tree.last_revision())
49
self.assertEqual((1, history[0]), tree.branch.last_revision_info())
51
# The file should not be removed
52
self.failUnlessExists('tree/two')
53
# And it should still be listed as added
54
self.assertIsNot(None, tree.path2id('two'))
56
def test_uncommit_bound(self):
57
tree, history = self.make_linear_tree()
58
child = tree.bzrdir.sprout('child').open_workingtree()
59
child.branch.bind(tree.branch)
61
self.assertEqual(history[1], tree.last_revision())
62
self.assertEqual((2, history[1]), tree.branch.last_revision_info())
63
self.assertEqual(history[1], child.last_revision())
64
self.assertEqual((2, history[1]), child.branch.last_revision_info())
66
# Uncommit in a bound branch should uncommit the master branch, but not
67
# touch the other working tree.
68
uncommit.uncommit(child.branch, tree=child)
70
self.assertEqual(history[1], tree.last_revision())
71
self.assertEqual((1, history[0]), tree.branch.last_revision_info())
72
self.assertEqual(history[0], child.last_revision())
73
self.assertEqual((1, history[0]), child.branch.last_revision_info())
75
def test_uncommit_bound_local(self):
76
tree, history = self.make_linear_tree()
77
child = tree.bzrdir.sprout('child').open_workingtree()
78
child.branch.bind(tree.branch)
80
self.assertEqual(history[1], tree.last_revision())
81
self.assertEqual((2, history[1]), tree.branch.last_revision_info())
82
self.assertEqual(history[1], child.last_revision())
83
self.assertEqual((2, history[1]), child.branch.last_revision_info())
85
# Uncommit local=True should only affect the local branch
86
uncommit.uncommit(child.branch, tree=child, local=True)
88
self.assertEqual(history[1], tree.last_revision())
89
self.assertEqual((2, history[1]), tree.branch.last_revision_info())
90
self.assertEqual(history[0], child.last_revision())
91
self.assertEqual((1, history[0]), child.branch.last_revision_info())
93
def test_uncommit_unbound_local(self):
94
tree, history = self.make_linear_tree()
96
# If this tree isn't bound, local=True raises an exception
97
self.assertRaises(errors.LocalRequiresBoundBranch,
98
uncommit.uncommit, tree.branch, tree=tree, local=True)