1
from shutil import rmtree
3
from bzrlib.errors import NoWorkingTree, NotLocalUrl, NotBranchError
4
from bzrlib.delta import compare_trees
5
from bzrlib.workingtree import WorkingTree
7
from errors import NotCheckout, UncommittedCheckout
12
wt = WorkingTree.open(path)
13
except (NoWorkingTree, NotBranchError):
14
raise NotCheckout(path)
15
tree_base = wt.bzrdir.transport.base
16
branch_base = wt.branch.bzrdir.transport.base
17
if tree_base == branch_base:
18
raise NotCheckout(path)
19
delta = compare_trees(wt.basis_tree(), wt, want_unchanged=False)
20
if delta.has_changed():
21
raise UncommittedCheckout()
27
from unittest import makeSuite
29
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
30
from bzrlib.branch import BranchReferenceFormat
31
from bzrlib.tests import TestCaseInTempDir
33
class TestZap(TestCaseInTempDir):
35
def make_checkout(self):
36
wt = BzrDir.create_standalone_workingtree('source')
38
checkout = BzrDirMetaFormat1().initialize('checkout')
39
BranchReferenceFormat().initialize(checkout, wt.branch)
40
return checkout.create_workingtree()
42
def test_is_checkout(self):
43
self.assertRaises(NotCheckout, zap, '.')
44
wt = BzrDir.create_standalone_workingtree('.')
45
self.assertRaises(NotCheckout, zap, '.')
47
def test_zap_works(self):
49
self.assertIs(True, os.path.exists('checkout'))
51
self.assertIs(False, os.path.exists('checkout'))
53
def test_checks_modified(self):
54
checkout = self.make_checkout()
55
os.mkdir('checkout/foo')
57
self.assertRaises(UncommittedCheckout, zap, 'checkout')
58
checkout.commit('commit changes to branch')
61
return makeSuite(TestZap)