~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2006-03-24 19:51:54 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060324195154-e183244265faeb50
Handled more hrefs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from shutil import rmtree
 
2
 
 
3
from bzrlib.errors import NoWorkingTree, NotLocalUrl, NotBranchError
 
4
from bzrlib.delta import compare_trees
 
5
from bzrlib.workingtree import WorkingTree
 
6
 
 
7
from errors import NotCheckout, UncommittedCheckout
 
8
 
 
9
 
 
10
def zap(path):
 
11
    try:
 
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()
 
22
    rmtree(path)
 
23
 
 
24
 
 
25
def test_suite():
 
26
    import os
 
27
    from unittest import makeSuite
 
28
    
 
29
    from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
 
30
    from bzrlib.branch import BranchReferenceFormat
 
31
    from bzrlib.tests import TestCaseInTempDir
 
32
 
 
33
    class TestZap(TestCaseInTempDir):
 
34
 
 
35
        def make_checkout(self):
 
36
            wt = BzrDir.create_standalone_workingtree('source')
 
37
            os.mkdir('checkout')
 
38
            checkout = BzrDirMetaFormat1().initialize('checkout')
 
39
            BranchReferenceFormat().initialize(checkout, wt.branch)
 
40
            return checkout.create_workingtree()
 
41
 
 
42
        def test_is_checkout(self):
 
43
            self.assertRaises(NotCheckout, zap, '.')
 
44
            wt = BzrDir.create_standalone_workingtree('.')
 
45
            self.assertRaises(NotCheckout, zap, '.')
 
46
 
 
47
        def test_zap_works(self):
 
48
            self.make_checkout()
 
49
            self.assertIs(True, os.path.exists('checkout'))
 
50
            zap('checkout')
 
51
            self.assertIs(False, os.path.exists('checkout'))
 
52
 
 
53
        def test_checks_modified(self):
 
54
            checkout = self.make_checkout()
 
55
            os.mkdir('checkout/foo')
 
56
            checkout.add('foo')
 
57
            self.assertRaises(UncommittedCheckout, zap, 'checkout')
 
58
            checkout.commit('commit changes to branch')
 
59
            zap('checkout')
 
60
 
 
61
    return makeSuite(TestZap)