~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: 2006-07-12 15:13:59 UTC
  • mfrom: (1850.1.2 diff-6391)
  • Revision ID: pqm@pqm.ubuntu.com-20060712151359-b22a8c043fa52eb7
(jam) update help text for diff (bug #6391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""\
 
2
Test the uncommit command.
 
3
"""
 
4
 
 
5
import os
 
6
 
 
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
 
11
 
 
12
class TestUncommit(TestCaseInTempDir):
 
13
    def test_uncommit(self):
 
14
        """Test uncommit functionality."""
 
15
        bzr = self.capture 
 
16
        os.mkdir('branch')
 
17
        os.chdir('branch')
 
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')
 
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')
 
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