~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_pull.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
import sys
22
22
 
23
23
from bzrlib import (
 
24
    branch,
24
25
    debug,
25
26
    remote,
26
27
    tests,
249
250
        tree_a.commit('commit b')
250
251
        # reset parent
251
252
        parent = branch_b.get_parent()
 
253
        branch_b = branch.Branch.open('branch_b')
 
254
        branch_b.lock_write()
252
255
        branch_b.set_parent(None)
 
256
        branch_b.unlock()
253
257
        self.assertEqual(None, branch_b.get_parent())
254
258
        # test pull for failure without parent set
255
 
        os.chdir('branch_b')
256
 
        out = self.run_bzr('pull', retcode=3)
 
259
        out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
257
260
        self.assertEqual(out,
258
261
                ('','bzr: ERROR: No pull location known or specified.\n'))
259
262
        # test implicit --remember when no parent set, this pull conflicts
260
 
        self.build_tree(['d'])
 
263
        self.build_tree(['branch_b/d'])
261
264
        tree_b.add('d')
262
265
        tree_b.commit('commit d')
263
 
        out = self.run_bzr('pull ../branch_a', retcode=3)
 
266
        out = self.run_bzr('pull ../branch_a', retcode=3,
 
267
                           working_dir='branch_b')
264
268
        self.assertEqual(out,
265
269
                ('','bzr: ERROR: These branches have diverged.'
266
270
                    ' Use the missing command to see how.\n'
267
271
                    'Use the merge command to reconcile them.\n'))
268
 
        self.assertEqual(branch_b.get_parent(), parent)
 
272
        branch_b = branch.Branch.open('branch_b')
 
273
        self.assertEqual(parent, branch_b.get_parent())
269
274
        # test implicit --remember after resolving previous failure
270
 
        uncommit(branch=branch_b, tree=tree_b)
 
275
        uncommit(branch=tree_b.branch, tree=tree_b)
271
276
        transport.delete('branch_b/d')
272
 
        self.run_bzr('pull')
 
277
        self.run_bzr('pull', working_dir='branch_b')
 
278
        branch_b = branch.Branch.open('branch_b')
273
279
        self.assertEqual(branch_b.get_parent(), parent)
274
280
        # test explicit --remember
275
 
        self.run_bzr('pull ../branch_c --remember')
276
 
        self.assertEqual(branch_b.get_parent(),
277
 
                          branch_c.bzrdir.root_transport.base)
 
281
        self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
 
282
        branch_b = branch.Branch.open('branch_b')
 
283
        self.assertEqual(branch_c.bzrdir.root_transport.base,
 
284
                         branch_b.get_parent())
278
285
 
279
286
    def test_pull_bundle(self):
280
287
        from bzrlib.testament import Testament