~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2006-08-02 03:23:09 UTC
  • mto: This revision was merged to the branch mainline in revision 425.
  • Revision ID: aaron.bentley@utoronto.ca-20060802032309-6ad0139e61304b19
Etienne Goyer: remove unused shebangs, update packaging

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
3
4
from bzrlib.errors import NoWorkingTree, NotLocalUrl, NotBranchError
4
5
from bzrlib.delta import compare_trees
5
6
from bzrlib.workingtree import WorkingTree
6
7
 
7
 
from errors import NotCheckout, UncommittedCheckout
 
8
from errors import (NotCheckout, UncommittedCheckout, ParentMissingRevisions, 
 
9
                    NoParent)
8
10
 
9
11
 
10
12
def zap(path, remove_branch=False):
20
22
    delta = compare_trees(wt.basis_tree(), wt, want_unchanged=False)
21
23
    if delta.has_changed():
22
24
        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())
23
33
    rmtree(path)
24
34
    if remove_branch:
25
35
        t = branch.bzrdir.transport
46
56
            BranchReferenceFormat().initialize(checkout, wt.branch)
47
57
            return checkout.create_workingtree()
48
58
 
 
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
 
49
67
        def test_is_checkout(self):
50
68
            self.assertRaises(NotCheckout, zap, '.')
51
69
            wt = BzrDir.create_standalone_workingtree('.')
59
77
            self.assertIs(True, os.path.exists('source'))
60
78
 
61
79
        def test_zap_branch(self):
62
 
            self.make_checkout()
 
80
            self.make_checkout2()
63
81
            base = WorkingTree.open('checkout').branch.base
64
82
            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'))
 
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'))
68
89
 
69
90
        def test_checks_modified(self):
70
91
            checkout = self.make_checkout()