22
22
from bzrlib import (
33
class TestBreakLock(tests.TestCaseWithTransport):
26
from bzrlib.branch import Branch
27
from bzrlib.bzrdir import BzrDir
28
from bzrlib.tests.blackbox import ExternalBase
31
class TestBreakLock(ExternalBase):
35
33
# General principal for break-lock: All the elements that might be locked
36
34
# by a bzr operation on PATH, are candidates that break-lock may unlock.
57
bzrdir.BzrDir.create('master-repo').create_repository()
58
self.master_branch = bzrdir.BzrDir.create_branch_convenience(
55
bzrlib.bzrdir.BzrDir.create('master-repo').create_repository()
56
self.master_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
59
57
'master-repo/master-branch')
60
bzrdir.BzrDir.create('repo').create_repository()
61
local_branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
58
bzrlib.bzrdir.BzrDir.create('repo').create_repository()
59
local_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('repo/branch')
62
60
local_branch.bind(self.master_branch)
63
checkoutdir = bzrdir.BzrDir.create('checkout')
64
branch.BranchReferenceFormat().initialize(
61
checkoutdir = bzrlib.bzrdir.BzrDir.create('checkout')
62
bzrlib.branch.BranchReferenceFormat().initialize(
65
63
checkoutdir, target_branch=local_branch)
66
64
self.wt = checkoutdir.create_workingtree()
75
73
# however, we dont test breaking the working tree because we
76
74
# cannot accurately do so right now: the dirstate lock is held
77
75
# by an os lock, and we need to spawn a separate process to lock it
80
78
# lock most of the dir:
81
79
self.wt.branch.lock_write()
84
82
# we need 5 yes's - wt, branch, repo, bound branch, bound repo.
85
83
self.run_bzr('break-lock checkout', stdin="y\ny\ny\ny\n")
86
84
# a new tree instance should be lockable
87
br = branch.Branch.open('checkout')
85
branch = bzrlib.branch.Branch.open('checkout')
90
88
# and a new instance of the master branch
91
mb = br.get_master_branch()
89
mb = branch.get_master_branch()
94
92
self.assertRaises(errors.LockBroken, self.wt.unlock)
95
93
self.assertRaises(errors.LockBroken, self.master_branch.unlock)
98
class TestBreakLockOldBranch(tests.TestCaseWithTransport):
96
class TestBreakLockOldBranch(ExternalBase):
100
98
def test_break_lock_format_5_bzrdir(self):
101
99
# break lock on a format 5 bzrdir should just return
102
self.make_branch_and_tree('foo', format=bzrdir.BzrDirFormat5())
100
self.make_branch_and_tree('foo', format=bzrlib.bzrdir.BzrDirFormat5())
103
101
out, err = self.run_bzr('break-lock foo')
104
102
self.assertEqual('', out)
105
103
self.assertEqual('', err)
107
class TestConfigBreakLock(tests.TestCaseWithTransport):
110
super(TestConfigBreakLock, self).setUp()
111
self.config_file_name = './my.conf'
112
self.build_tree_contents([(self.config_file_name,
113
'[DEFAULT]\none=1\n')])
114
self.config = config.LockableConfig(file_name=self.config_file_name)
115
self.config.lock_write()
117
def test_create_pending_lock(self):
118
self.addCleanup(self.config.unlock)
119
self.assertTrue(self.config._lock.is_held)
121
def test_break_lock(self):
122
self.run_bzr('break-lock --config %s'
123
% osutils.dirname(self.config_file_name),
125
self.assertRaises(errors.LockBroken, self.config.unlock)