~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2007-01-08 17:27:48 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070108172748-1b22qtszaadoby89
Improve bzr import docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from shutil import rmtree
2
2
 
3
 
from bzrlib import (
4
 
    bzrdir,
5
 
    revision as _mod_revision,
6
 
    )
7
3
from bzrlib.branch import Branch
8
4
from bzrlib.errors import NoWorkingTree, NotLocalUrl, NotBranchError
9
5
from bzrlib.workingtree import WorkingTree
10
6
 
11
 
from errors import (NotCheckout, UncommittedCheckout, ParentMissingRevisions,
 
7
from errors import (NotCheckout, UncommittedCheckout, ParentMissingRevisions, 
12
8
                    NoParent)
13
9
 
14
10
 
15
 
def zap(path, remove_branch=False, allow_modified=False):
 
11
def zap(path, remove_branch=False):
16
12
    try:
17
 
        wt = bzrdir.BzrDir.open(path).open_workingtree(path,
18
 
                                                       recommend_upgrade=False)
 
13
        wt = WorkingTree.open(path)
19
14
    except (NoWorkingTree, NotBranchError):
20
15
        raise NotCheckout(path)
21
16
    tree_base = wt.bzrdir.transport.base
23
18
    branch_base = branch.bzrdir.transport.base
24
19
    if tree_base == branch_base:
25
20
        raise NotCheckout(path)
26
 
    if not allow_modified:
27
 
        delta = wt.changes_from(wt.basis_tree(), want_unchanged=False)
28
 
        if delta.has_changed():
29
 
            raise UncommittedCheckout()
 
21
    delta = wt.changes_from(wt.basis_tree(), want_unchanged=False)
 
22
    if delta.has_changed():
 
23
        raise UncommittedCheckout()
30
24
    if remove_branch:
31
25
        parent_loc = branch.get_parent()
32
26
        if parent_loc is None:
33
27
            raise NoParent()
34
28
        parent = Branch.open(parent_loc)
35
 
        last_revision = _mod_revision.ensure_null(parent.last_revision())
36
 
        p_ancestry = parent.repository.get_ancestry(last_revision)
37
 
        if (last_revision != _mod_revision.NULL_REVISION and
38
 
            branch.last_revision() not in p_ancestry):
 
29
        p_ancestry = parent.repository.get_ancestry(parent.last_revision())
 
30
        if branch.last_revision() not in p_ancestry:
39
31
            raise ParentMissingRevisions(branch.get_parent())
40
32
    rmtree(path)
41
33
    if remove_branch:
49
41
def test_suite():
50
42
    import os
51
43
    from unittest import makeSuite
52
 
 
 
44
    
53
45
    from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
54
46
    from bzrlib.branch import BranchReferenceFormat
55
47
    from bzrlib.tests import TestCaseInTempDir
102
94
            checkout.commit('commit changes to branch')
103
95
            zap('checkout')
104
96
 
105
 
        def test_allow_modified(self):
106
 
            checkout = self.make_checkout()
107
 
            os.mkdir('checkout/foo')
108
 
            checkout.add('foo')
109
 
            self.assertRaises(UncommittedCheckout, zap, 'checkout')
110
 
            zap('checkout', allow_modified=True)
111
 
 
112
97
    return makeSuite(TestZap)