~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_bound_branches.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-12 04:17:05 UTC
  • mto: (1587.1.6 bound-branches)
  • mto: This revision was merged to the branch mainline in revision 1590.
  • Revision ID: john@arbash-meinel.com-20051112041705-f53471838021b7f3
Adding test for bound behavior

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 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
 
 
18
"""Tests of bound branches (binding, unbinding, commit, etc) command.
 
19
 
 
20
"""
 
21
 
 
22
import os
 
23
from cStringIO import StringIO
 
24
 
 
25
from bzrlib.selftest import TestCaseInTempDir
 
26
from bzrlib.branch import Branch
 
27
 
 
28
class TestBoundBranches(TestCaseInTempDir):
 
29
    
 
30
    def create_branches(self):
 
31
        self.build_tree(['base/', 'base/a', 'base/b'])
 
32
 
 
33
        os.chdir('base')
 
34
        self.run_bzr('init')
 
35
        self.run_bzr('add')
 
36
        self.run_bzr('commit', '-m', 'init')
 
37
 
 
38
        os.chdir('..')
 
39
 
 
40
        bzr('get', '--bound', 'base', 'child')
 
41
 
 
42
        self.failUnlessExists('child')
 
43
 
 
44
        os.chdir('child')
 
45
        self.check_revno('1')
 
46
        self.failUnlessExists('.bzr/bound')
 
47
        os.chdir('..')
 
48
 
 
49
    def check_revno(self, val):
 
50
        self.assertEquals(self.capture('bzr revno').strip(), val)
 
51
 
 
52
    def test_bound_commit(self):
 
53
        bzr = self.run_bzr
 
54
        self.create_branches()
 
55
 
 
56
        os.chdir('child')
 
57
        open('a', 'wb').write('new contents\n')
 
58
        bzr('commit', '-m', 'child')
 
59
 
 
60
        self.check_revno('2')
 
61
 
 
62
        # Make sure it committed on the parent
 
63
        os.chdir('../base')
 
64
        self.check_revno('2')
 
65
 
 
66
    def test_bound_fail(self)
 
67
        """Make sure commit fails if out of date."""
 
68
        bzr = self.run_bzr
 
69
        self.create_branches()
 
70
 
 
71
        os.chdir('base')
 
72
        open('a', 'wb').write('new base contents\n')
 
73
        bzr('commit', '-m', 'base')
 
74
 
 
75
        os.chdir('../child')
 
76
        open('b', 'wb').write('new b child contents\n')
 
77
        bzr('commit', '-m', 'child', retcode=1)
 
78
 
 
79
        bzr('pull')
 
80
        self.check_revno('2')
 
81
 
 
82
        bzr('commit', '-m', 'child')
 
83
        self.check_revno('3')
 
84
        os.chdir('../base')
 
85
        self.check_revno('3')
 
86
 
 
87
    def test_unbinding(self):
 
88
        bzr = self.run_bzr
 
89
        self.create_branches()
 
90
 
 
91
        os.chdir('base')
 
92
        open('a', 'wb').write('new base contents\n')
 
93
        bzr('commit', '-m', 'base')
 
94
        self.check_revno('2')
 
95
 
 
96
        os.chdir('../child')
 
97
        open('b', 'wb').write('new b child contents\n')
 
98
        self.check_revno('1')
 
99
        bzr('commit', '-m', 'child', retcode=1)
 
100
        self.check_revno('1')
 
101
        bzr('unbind')
 
102
        bzr('commit', '-m', 'child')
 
103
        self.check_revno('2')
 
104
 
 
105
        bzr('bind', retcode=1)
 
106
    
 
107