~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2007-07-05 17:04:38 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070705170438-74dsm7b1bcs4d9hu
Fix deprecation warnings

Show diffs side-by-side

added added

removed removed

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