~bzr-pqm/bzr/bzr.dev

0.3.11 by John Arbash Meinel
Updated to latest bzr.dev code, and added tests.
1
"""\
2
Test the uncommit command.
3
"""
1558.1.12 by Aaron Bentley
Got uncommit working properly with checkouts
4
5
import os
6
1558.9.1 by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking
7
from bzrlib.bzrdir import BzrDirMetaFormat1
8
from bzrlib.errors import BzrError, BoundBranchOutOfDate
9
from bzrlib.uncommit import uncommit
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
10
from bzrlib.tests import TestCaseInTempDir
0.3.11 by John Arbash Meinel
Updated to latest bzr.dev code, and added tests.
11
12
class TestUncommit(TestCaseInTempDir):
13
    def test_uncommit(self):
14
        """Test uncommit functionality."""
15
        bzr = self.capture 
1558.1.12 by Aaron Bentley
Got uncommit working properly with checkouts
16
        os.mkdir('branch')
17
        os.chdir('branch')
0.3.11 by John Arbash Meinel
Updated to latest bzr.dev code, and added tests.
18
        bzr('init')
19
        self.build_tree(['a', 'b', 'c'])
20
21
        bzr('add')
22
        bzr('commit -m initial')
23
24
        self.assertEquals(bzr('revno'), '1\n')
25
26
        open('a', 'wb').write('new contents of a\n')
27
        self.assertEquals(bzr('status'), 'modified:\n  a\n')
28
        bzr('commit -m second')
29
30
        self.assertEquals(bzr('status'), '')
31
        self.assertEquals(bzr('revno'), '2\n')
32
33
        txt = bzr('uncommit --dry-run --force')
34
        self.failIfEqual(txt.find('Dry-run'), -1)
35
36
        self.assertEquals(bzr('status'), '')
37
        self.assertEquals(bzr('revno'), '2\n')
38
39
        txt = bzr('uncommit --force')
40
41
        self.assertEquals(bzr('revno'), '1\n')
42
        self.assertEquals(bzr('status'), 'modified:\n  a\n')
1558.1.12 by Aaron Bentley
Got uncommit working properly with checkouts
43
        
44
        bzr('checkout . ../checkout')
45
        os.chdir('../checkout')
46
        self.assertEquals("", bzr('status'))
47
        self.assertEquals(bzr('revno'), '1\n')
48
49
        open('a', 'wb').write('new contents of a\n')
50
        self.assertEquals(bzr('status'), 'modified:\n  a\n')
51
        bzr('commit -m second')
52
53
        self.assertEquals(bzr('status'), '')
54
        self.assertEquals(bzr('revno'), '2\n')
55
56
        txt = bzr('uncommit --dry-run --force')
57
        self.failIfEqual(txt.find('Dry-run'), -1)
58
59
        self.assertEquals(bzr('status'), '')
60
        self.assertEquals(bzr('revno'), '2\n')
61
62
        txt = bzr('uncommit --force')
63
64
        self.assertEquals(bzr('revno'), '1\n')
65
        self.assertEquals(bzr('status'), 'modified:\n  a\n')
1558.9.1 by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking
66
67
    def test_uncommit_bound(self):
68
        os.mkdir('a')
69
        a = BzrDirMetaFormat1().initialize('a')
70
        a.create_repository()
71
        a.create_branch()
72
        t = a.create_workingtree()
73
        t.commit('commit 1')
74
        t.commit('commit 2')
75
        t.commit('commit 3')
76
        b = t.bzrdir.sprout('b').open_branch()
77
        b.bind(t.branch)
78
        uncommit(b)
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)
82
        t.commit('commit 3b')
83
        self.assertRaises(BoundBranchOutOfDate, uncommit, b)
84
        b.pull(t.branch)
85
        uncommit(b)
86