~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2006-03-29 06:43:34 UTC
  • mfrom: (355.1.3 bzrtools)
  • Revision ID: aaron.bentley@utoronto.ca-20060329064334-62e56b84dedf3f8d
Merge combined work

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
from errors import NotCheckout, UncommittedCheckout
8
8
 
9
9
 
10
 
def zap(path):
 
10
def zap(path, remove_branch=False):
11
11
    try:
12
12
        wt = WorkingTree.open(path)
13
13
    except (NoWorkingTree, NotBranchError):
14
14
        raise NotCheckout(path)
15
15
    tree_base = wt.bzrdir.transport.base
16
 
    branch_base = wt.branch.bzrdir.transport.base
 
16
    branch = wt.branch
 
17
    branch_base = branch.bzrdir.transport.base
17
18
    if tree_base == branch_base:
18
19
        raise NotCheckout(path)
19
20
    delta = compare_trees(wt.basis_tree(), wt, want_unchanged=False)
20
21
    if delta.has_changed():
21
22
        raise UncommittedCheckout()
22
23
    rmtree(path)
 
24
    if remove_branch:
 
25
        t = branch.bzrdir.transport
 
26
        while t.base != branch_base:
 
27
            t = t.clone('..')
 
28
        t = t.clone('..')
 
29
        t.delete_tree('')
23
30
 
24
31
 
25
32
def test_suite():
49
56
            self.assertIs(True, os.path.exists('checkout'))
50
57
            zap('checkout')
51
58
            self.assertIs(False, os.path.exists('checkout'))
 
59
            self.assertIs(True, os.path.exists('source'))
 
60
 
 
61
        def test_zap_branch(self):
 
62
            self.make_checkout()
 
63
            base = WorkingTree.open('checkout').branch.base
 
64
            self.assertIs(True, os.path.exists('checkout'))
 
65
            zap('checkout', remove_branch=True)
 
66
            self.assertIs(False, os.path.exists('checkout'))
 
67
            self.assertIs(False, os.path.exists('source'))
52
68
 
53
69
        def test_checks_modified(self):
54
70
            checkout = self.make_checkout()