~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2006-03-22 22:18:19 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060322221819-0e627e73d1232926
Added zap command

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, remove_branch=False):
 
10
def zap(path):
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 = wt.branch
17
 
    branch_base = branch.bzrdir.transport.base
 
16
    branch_base = wt.branch.bzrdir.transport.base
18
17
    if tree_base == branch_base:
19
18
        raise NotCheckout(path)
20
19
    delta = compare_trees(wt.basis_tree(), wt, want_unchanged=False)
21
20
    if delta.has_changed():
22
21
        raise UncommittedCheckout()
23
22
    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('')
30
23
 
31
24
 
32
25
def test_suite():
56
49
            self.assertIs(True, os.path.exists('checkout'))
57
50
            zap('checkout')
58
51
            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'))
68
52
 
69
53
        def test_checks_modified(self):
70
54
            checkout = self.make_checkout()