~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2006-03-31 01:47:15 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20060331014715-127c9cda9bbc1e6f
Strip trailing / from input location

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from shutil import rmtree
2
2
 
3
 
from bzrlib.branch import Branch
4
3
from bzrlib.errors import NoWorkingTree, NotLocalUrl, NotBranchError
5
4
from bzrlib.delta import compare_trees
6
5
from bzrlib.workingtree import WorkingTree
7
6
 
8
 
from errors import (NotCheckout, UncommittedCheckout, ParentMissingRevisions, 
9
 
                    NoParent)
 
7
from errors import NotCheckout, UncommittedCheckout
10
8
 
11
9
 
12
10
def zap(path, remove_branch=False):
22
20
    delta = compare_trees(wt.basis_tree(), wt, want_unchanged=False)
23
21
    if delta.has_changed():
24
22
        raise UncommittedCheckout()
25
 
    if remove_branch:
26
 
        parent_loc = branch.get_parent()
27
 
        if parent_loc is None:
28
 
            raise NoParent()
29
 
        parent = Branch.open(parent_loc)
30
 
        p_ancestry = parent.repository.get_ancestry(parent.last_revision())
31
 
        if branch.last_revision() not in p_ancestry:
32
 
            raise ParentMissingRevisions(branch.get_parent())
33
23
    rmtree(path)
34
24
    if remove_branch:
35
25
        t = branch.bzrdir.transport
56
46
            BranchReferenceFormat().initialize(checkout, wt.branch)
57
47
            return checkout.create_workingtree()
58
48
 
59
 
        def make_checkout2(self):
60
 
            wt = self.make_checkout()
61
 
            wt2 = wt.branch.bzrdir.sprout('source2').open_workingtree()
62
 
            os.mkdir('checkout2')
63
 
            checkout = BzrDirMetaFormat1().initialize('checkout2')
64
 
            BranchReferenceFormat().initialize(checkout, wt2.branch)
65
 
            return checkout.create_workingtree()
66
 
 
67
49
        def test_is_checkout(self):
68
50
            self.assertRaises(NotCheckout, zap, '.')
69
51
            wt = BzrDir.create_standalone_workingtree('.')
77
59
            self.assertIs(True, os.path.exists('source'))
78
60
 
79
61
        def test_zap_branch(self):
80
 
            self.make_checkout2()
 
62
            self.make_checkout()
81
63
            base = WorkingTree.open('checkout').branch.base
82
64
            self.assertIs(True, os.path.exists('checkout'))
83
 
            self.assertRaises(NoParent, zap, 'checkout', remove_branch=True)
84
 
            self.assertIs(True, os.path.exists('checkout'))
85
 
            self.assertIs(True, os.path.exists('source'))
86
 
            zap('checkout2', remove_branch=True)
87
 
            self.assertIs(False, os.path.exists('checkout2'))
88
 
            self.assertIs(False, os.path.exists('source2'))
 
65
            zap('checkout', remove_branch=True)
 
66
            self.assertIs(False, os.path.exists('checkout'))
 
67
            self.assertIs(False, os.path.exists('source'))
89
68
 
90
69
        def test_checks_modified(self):
91
70
            checkout = self.make_checkout()