2
Test the uncommit command.
7
from bzrlib.bzrdir import BzrDirMetaFormat1
8
from bzrlib.errors import BzrError, BoundBranchOutOfDate
9
from bzrlib.uncommit import uncommit
10
from bzrlib.tests import TestCaseInTempDir
12
class TestUncommit(TestCaseInTempDir):
13
def test_uncommit(self):
14
"""Test uncommit functionality."""
19
self.build_tree(['a', 'b', 'c'])
22
bzr('commit -m initial')
24
self.assertEquals(bzr('revno'), '1\n')
26
open('a', 'wb').write('new contents of a\n')
27
self.assertEquals(bzr('status'), 'modified:\n a\n')
28
bzr('commit -m second')
30
self.assertEquals(bzr('status'), '')
31
self.assertEquals(bzr('revno'), '2\n')
33
txt = bzr('uncommit --dry-run --force')
34
self.failIfEqual(txt.find('Dry-run'), -1)
36
self.assertEquals(bzr('status'), '')
37
self.assertEquals(bzr('revno'), '2\n')
39
txt = bzr('uncommit --force')
41
self.assertEquals(bzr('revno'), '1\n')
42
self.assertEquals(bzr('status'), 'modified:\n a\n')
44
bzr('checkout . ../checkout')
45
os.chdir('../checkout')
46
self.assertEquals("", bzr('status'))
47
self.assertEquals(bzr('revno'), '1\n')
49
open('a', 'wb').write('new contents of a\n')
50
self.assertEquals(bzr('status'), 'modified:\n a\n')
51
bzr('commit -m second')
53
self.assertEquals(bzr('status'), '')
54
self.assertEquals(bzr('revno'), '2\n')
56
txt = bzr('uncommit --dry-run --force')
57
self.failIfEqual(txt.find('Dry-run'), -1)
59
self.assertEquals(bzr('status'), '')
60
self.assertEquals(bzr('revno'), '2\n')
62
txt = bzr('uncommit --force')
64
self.assertEquals(bzr('revno'), '1\n')
65
self.assertEquals(bzr('status'), 'modified:\n a\n')
67
def test_uncommit_bound(self):
69
a = BzrDirMetaFormat1().initialize('a')
72
t = a.create_workingtree()
76
b = t.bzrdir.sprout('b').open_branch()
79
t.set_last_revision(t.branch.last_revision())
80
self.assertEqual(len(b.revision_history()), 2)
81
self.assertEqual(len(t.branch.revision_history()), 2)
83
self.assertRaises(BoundBranchOutOfDate, uncommit, b)