~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Robert Collins
  • Date: 2006-04-24 01:45:23 UTC
  • mto: (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 366.
  • Revision ID: robertc@robertcollins.net-20060424014523-ef18f22034f17ec2
Backout debugging tweak to fai.py

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
 
4
from bzrlib.delta import compare_trees
5
5
from bzrlib.workingtree import WorkingTree
6
6
 
7
 
from errors import (NotCheckout, UncommittedCheckout, ParentMissingRevisions,
8
 
                    NoParent)
 
7
from errors import NotCheckout, UncommittedCheckout
9
8
 
10
9
 
11
10
def zap(path, remove_branch=False):
18
17
    branch_base = branch.bzrdir.transport.base
19
18
    if tree_base == branch_base:
20
19
        raise NotCheckout(path)
21
 
    delta = wt.changes_from(wt.basis_tree(), want_unchanged=False)
 
20
    delta = compare_trees(wt.basis_tree(), wt, want_unchanged=False)
22
21
    if delta.has_changed():
23
22
        raise UncommittedCheckout()
24
 
    if remove_branch:
25
 
        parent_loc = branch.get_parent()
26
 
        if parent_loc is None:
27
 
            raise NoParent()
28
 
        parent = Branch.open(parent_loc)
29
 
        p_ancestry = parent.repository.get_ancestry(parent.last_revision())
30
 
        if branch.last_revision() not in p_ancestry:
31
 
            raise ParentMissingRevisions(branch.get_parent())
32
23
    rmtree(path)
33
24
    if remove_branch:
34
25
        t = branch.bzrdir.transport
41
32
def test_suite():
42
33
    import os
43
34
    from unittest import makeSuite
44
 
 
 
35
    
45
36
    from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
46
37
    from bzrlib.branch import BranchReferenceFormat
47
38
    from bzrlib.tests import TestCaseInTempDir
55
46
            BranchReferenceFormat().initialize(checkout, wt.branch)
56
47
            return checkout.create_workingtree()
57
48
 
58
 
        def make_checkout2(self):
59
 
            wt = self.make_checkout()
60
 
            wt2 = wt.branch.bzrdir.sprout('source2').open_workingtree()
61
 
            os.mkdir('checkout2')
62
 
            checkout = BzrDirMetaFormat1().initialize('checkout2')
63
 
            BranchReferenceFormat().initialize(checkout, wt2.branch)
64
 
            return checkout.create_workingtree()
65
 
 
66
49
        def test_is_checkout(self):
67
50
            self.assertRaises(NotCheckout, zap, '.')
68
51
            wt = BzrDir.create_standalone_workingtree('.')
76
59
            self.assertIs(True, os.path.exists('source'))
77
60
 
78
61
        def test_zap_branch(self):
79
 
            self.make_checkout2()
 
62
            self.make_checkout()
80
63
            base = WorkingTree.open('checkout').branch.base
81
64
            self.assertIs(True, os.path.exists('checkout'))
82
 
            self.assertRaises(NoParent, zap, 'checkout', remove_branch=True)
83
 
            self.assertIs(True, os.path.exists('checkout'))
84
 
            self.assertIs(True, os.path.exists('source'))
85
 
            zap('checkout2', remove_branch=True)
86
 
            self.assertIs(False, os.path.exists('checkout2'))
87
 
            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'))
88
68
 
89
69
        def test_checks_modified(self):
90
70
            checkout = self.make_checkout()