~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 21:33:59 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-20051112213359-925abcf4ba6b452f
(broken) Adding more tests, and some functionality

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        self.failUnlessExists('child')
43
43
 
44
44
        os.chdir('child')
45
 
        self.check_revno('1')
 
45
        self.check_revno(1)
46
46
        self.failUnlessExists('.bzr/bound')
47
47
        os.chdir('..')
48
48
 
49
 
    def check_revno(self, val):
50
 
        self.assertEquals(self.capture('bzr revno').strip(), val)
 
49
    def check_revno(self, val, loc=None):
 
50
        if loc is not None:
 
51
            cwd = os.getcwd()
 
52
            os.chdir(loc)
 
53
        self.assertEquals(self.capture('bzr revno').strip(), str(val))
 
54
        if loc is not None:
 
55
            os.chdir(cwd)
51
56
 
52
57
    def test_bound_commit(self):
53
58
        bzr = self.run_bzr
57
62
        open('a', 'wb').write('new contents\n')
58
63
        bzr('commit', '-m', 'child')
59
64
 
60
 
        self.check_revno('2')
 
65
        self.check_revno(2)
61
66
 
62
67
        # Make sure it committed on the parent
63
68
        os.chdir('../base')
64
 
        self.check_revno('2')
 
69
        self.check_revno(2)
65
70
 
66
71
    def test_bound_fail(self)
67
72
        """Make sure commit fails if out of date."""
77
82
        bzr('commit', '-m', 'child', retcode=1)
78
83
 
79
84
        bzr('pull')
80
 
        self.check_revno('2')
 
85
        self.check_revno(2)
81
86
 
82
87
        bzr('commit', '-m', 'child')
83
 
        self.check_revno('3')
 
88
        self.check_revno(3)
84
89
        os.chdir('../base')
85
 
        self.check_revno('3')
 
90
        self.check_revno(3)
86
91
 
87
92
    def test_double_binding(self):
 
93
        # The behavior of this test is under debate
88
94
        bzr = self.run_bzr
89
95
        self.create_branches()
90
96
 
93
99
 
94
100
        bzr('bind', '../child', retcode=1)
95
101
 
96
 
        # The binding should fail, because child2 is bound
 
102
        # The binding should fail, because child is bound
97
103
        self.failIf(os.path.lexists('.bzr/bound'))
98
104
 
99
105
    def test_unbinding(self):
103
109
        os.chdir('base')
104
110
        open('a', 'wb').write('new base contents\n')
105
111
        bzr('commit', '-m', 'base')
106
 
        self.check_revno('2')
 
112
        self.check_revno(2)
107
113
 
108
114
        os.chdir('../child')
109
115
        open('b', 'wb').write('new b child contents\n')
110
 
        self.check_revno('1')
 
116
        self.check_revno(1)
111
117
        bzr('commit', '-m', 'child', retcode=1)
112
 
        self.check_revno('1')
 
118
        self.check_revno(1)
113
119
        bzr('unbind')
114
120
        bzr('commit', '-m', 'child')
115
 
        self.check_revno('2')
 
121
        self.check_revno(2)
116
122
 
117
123
        bzr('bind', retcode=1)
118
 
    
 
124
 
 
125
    def test_commit_remote_bound(self):
 
126
        # It is not possible to commit to a branch
 
127
        # which is bound to a branch which is bound
 
128
        bzr = self.run_bzr
 
129
        bzr('branch', 'base', 'newbase')
 
130
        os.chdir('base')
 
131
        
 
132
        # There is no way to know that B has already
 
133
        # been bound by someone else, otherwise it
 
134
        # might be nice if this would fail
 
135
        bzr('bind', '../newbase')
 
136
 
 
137
        os.chdir('../child')
 
138
        bzr('commit', '-m', 'failure', '--unchanged', retcode=1)
 
139
        
 
140
 
 
141
    def test_pull_updates_both(self):
 
142
        bzr = self.run_bzr
 
143
        self.create_branches()
 
144
        bzr('branch', 'base', 'newchild')
 
145
        os.chdir('newchild')
 
146
        open('b', 'wb').write('newchild b contents\n')
 
147
        bzr('commit', '-m', 'newchild')
 
148
        self.check_revno(2)
 
149
 
 
150
        os.chdir('../child')
 
151
        # The pull should succeed, and update
 
152
        # the bound parent branch
 
153
        bzr('pull', '../newchild')
 
154
        self.check_revno(2)
 
155
 
 
156
        os.chdir('../base')
 
157
        self.check_revno(2)
 
158
 
 
159
    def test_bind_diverged(self):
 
160
        bzr = self.run_bzr
 
161
        self.create_branches()
 
162
 
 
163
        os.chdir('child')
 
164
        bzr('unbind')
 
165
 
 
166
        bzr('commit', '-m', 'child', '--unchanged')
 
167
        self.check_revno(2)
 
168
 
 
169
        os.chdir('../base')
 
170
        self.check_revno(1)
 
171
        bzr('commit', '-m', 'base', '--unchanged')
 
172
        self.check_revno(2)
 
173
 
 
174
        os.chdir('../child')
 
175
        # These branches have diverged
 
176
        bzr('bind', '../base', retcode=1)
 
177
 
 
178
        # TODO: In the future, this might require actual changes
 
179
        # to have occurred, rather than just a new revision entry
 
180
        bzr('merge', '../base')
 
181
        bzr('commit', '-m', 'merged')
 
182
        self.check_revno(3)
 
183
 
 
184
        # This should also be possible by doing a 'bzr push' to the
 
185
        # base, rather than doing 'bzr pull' from it
 
186
        os.chdir('../base')
 
187
        bzr('pull', '../child')
 
188
        self.check_revno(3)
 
189
 
 
190
        os.chdir('../child')
 
191
        bzr('bind', '../base')
 
192
 
 
193
        # After binding, the revision history should be identical
 
194
        child_rh = self.capture('bzr revision-history')
 
195
        os.chdir('../base')
 
196
        base_rh = self.capture('bzr revision-history')
 
197
        self.assertEquals(child_rh, base_rh)
 
198
 
 
199
    def test_bind_parent_ahead(self):
 
200
        bzr = self.run_bzr
 
201
        self.create_branches()
 
202
 
 
203
        os.chdir('child')
 
204
        bzr('unbind')
 
205
 
 
206
        os.chdir('../base')
 
207
        bzr('commit', '-m', 'base', '--unchanged')
 
208
 
 
209
        os.chdir('../child')
 
210
        self.check_revno(1)
 
211
        bzr('bind', '../base')
 
212
 
 
213
        self.check_revno(2)
 
214
 
 
215
    def test_bind_child_ahead(self):
 
216
        bzr = self.run_bzr
 
217
        self.create_branches()
 
218
 
 
219
        os.chdir('child')
 
220
        bzr('unbind')
 
221
        bzr('commit', '-m', 'child', '--unchanged')
 
222
        self.check_revno(2)
 
223
        self.check_revno(1, '../base')
 
224
 
 
225
        bzr('bind', '../base')
 
226
        self.check_revno(2, '../base')
119
227