17
17
"""Tests for lock-breaking user interface"""
22
19
from bzrlib import (
26
from bzrlib.branch import Branch
27
from bzrlib.bzrdir import BzrDir
28
from bzrlib.tests import TestCaseWithTransport
31
class TestBreakLock(TestCaseWithTransport):
27
from bzrlib.tests.script import (
32
class TestBreakLock(tests.TestCaseWithTransport):
33
34
# General principal for break-lock: All the elements that might be locked
34
35
# by a bzr operation on PATH, are candidates that break-lock may unlock.
55
bzrlib.bzrdir.BzrDir.create('master-repo').create_repository()
56
self.master_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
56
bzrdir.BzrDir.create('master-repo').create_repository()
57
self.master_branch = bzrdir.BzrDir.create_branch_convenience(
57
58
'master-repo/master-branch')
58
bzrlib.bzrdir.BzrDir.create('repo').create_repository()
59
local_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('repo/branch')
59
bzrdir.BzrDir.create('repo').create_repository()
60
local_branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
60
61
local_branch.bind(self.master_branch)
61
checkoutdir = bzrlib.bzrdir.BzrDir.create('checkout')
62
bzrlib.branch.BranchReferenceFormat().initialize(
62
checkoutdir = bzrdir.BzrDir.create('checkout')
63
branch.BranchReferenceFormat().initialize(
63
64
checkoutdir, target_branch=local_branch)
64
65
self.wt = checkoutdir.create_workingtree()
68
69
# shouldn't fail and should not produce error output
69
70
self.assertEqual('', err)
72
def test_break_lock_no_interaction(self):
73
"""With --force, the user isn't asked for confirmation"""
74
self.master_branch.lock_write()
76
$ bzr break-lock --force master-repo/master-branch
77
Broke lock ...master-branch/.bzr/...
79
# lock should now be dead
80
self.assertRaises(errors.LockBroken, self.master_branch.unlock)
71
82
def test_break_lock_everything_locked(self):
72
83
### if everything is locked, we should be able to unlock the lot.
73
84
# however, we dont test breaking the working tree because we
74
85
# cannot accurately do so right now: the dirstate lock is held
75
86
# by an os lock, and we need to spawn a separate process to lock it
78
89
# lock most of the dir:
79
90
self.wt.branch.lock_write()
82
93
# we need 5 yes's - wt, branch, repo, bound branch, bound repo.
83
94
self.run_bzr('break-lock checkout', stdin="y\ny\ny\ny\n")
84
95
# a new tree instance should be lockable
85
branch = bzrlib.branch.Branch.open('checkout')
96
br = branch.Branch.open('checkout')
88
99
# and a new instance of the master branch
89
mb = branch.get_master_branch()
100
mb = br.get_master_branch()
92
103
self.assertRaises(errors.LockBroken, self.wt.unlock)
93
104
self.assertRaises(errors.LockBroken, self.master_branch.unlock)
96
class TestBreakLockOldBranch(TestCaseWithTransport):
107
class TestBreakLockOldBranch(tests.TestCaseWithTransport):
98
109
def test_break_lock_format_5_bzrdir(self):
99
110
# break lock on a format 5 bzrdir should just return
100
self.make_branch_and_tree('foo', format=bzrlib.bzrdir.BzrDirFormat5())
111
self.make_branch_and_tree('foo', format=bzrdir.BzrDirFormat5())
101
112
out, err = self.run_bzr('break-lock foo')
102
113
self.assertEqual('', out)
103
114
self.assertEqual('', err)
116
class TestConfigBreakLock(tests.TestCaseWithTransport):
119
super(TestConfigBreakLock, self).setUp()
120
self.config_file_name = './my.conf'
121
self.build_tree_contents([(self.config_file_name,
122
'[DEFAULT]\none=1\n')])
123
self.config = config.LockableConfig(file_name=self.config_file_name)
124
self.config.lock_write()
126
def test_create_pending_lock(self):
127
self.addCleanup(self.config.unlock)
128
self.assertTrue(self.config._lock.is_held)
130
def test_break_lock(self):
131
self.run_bzr('break-lock --config %s'
132
% osutils.dirname(self.config_file_name),
134
self.assertRaises(errors.LockBroken, self.config.unlock)