~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to zap.py

  • Committer: Aaron Bentley
  • Date: 2013-08-20 03:02:43 UTC
  • Revision ID: aaron@aaronbentley.com-20130820030243-r8v1xfbcnd8f10p4
Fix zap command for 2.6/7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006-2007, 2010-2011 Aaron Bentley <aaron@aaronbentley.com>
 
2
# Copyright (C) 2013 Aaron Bentley <aaron@aaronbentley.com>
2
3
# Copyright (C) 2007 Charlie Shepherd <masterdriverz@gentoo.org>
3
4
# Copyright (C) 2011 Canonical Ltd.
4
5
#
29
30
 
30
31
from errors import (NotCheckout, UncommittedCheckout, ParentMissingRevisions,
31
32
                    NoParent)
 
33
from bzrlib.plugins.bzrtools.bzrtools import read_locked
32
34
 
33
35
 
34
36
class AllowChanged(object):
83
85
change_policy_registry.default_key = 'check'
84
86
 
85
87
 
 
88
 
86
89
def zap(path, remove_branch=False, policy=HaltOnChange):
87
90
    try:
88
91
        wt = bzrdir.BzrDir.open(path).open_workingtree(path,
99
102
        parent_loc = branch.get_parent()
100
103
        if parent_loc is None:
101
104
            raise NoParent()
102
 
        parent = Branch.open(parent_loc)
103
 
        last_revision = _mod_revision.ensure_null(parent.last_revision())
104
 
        p_ancestry = parent.repository.get_ancestry(last_revision)
105
 
        if (last_revision != _mod_revision.NULL_REVISION and
106
 
            branch.last_revision() not in p_ancestry):
107
 
            raise ParentMissingRevisions(branch.get_parent())
 
105
        with read_locked(Branch.open(parent_loc)) as parent:
 
106
            last_revision = _mod_revision.ensure_null(parent.last_revision())
 
107
            if last_revision != _mod_revision.NULL_REVISION:
 
108
                graph = parent.repository.get_graph()
 
109
                heads = graph.heads([last_revision, branch.last_revision()])
 
110
                if branch.last_revision() in heads:
 
111
                    raise ParentMissingRevisions(branch.get_parent())
108
112
    rmtree(path)
109
113
    if remove_branch:
110
114
        t = branch.bzrdir.transport
118
122
    import os
119
123
    from unittest import makeSuite
120
124
 
121
 
    from bzrlib.tests import TestCaseInTempDir
 
125
    from bzrlib.tests import TestCaseWithTransport
122
126
 
123
127
 
124
128
    class PipelinePluginFeature:
133
137
                return True
134
138
 
135
139
 
136
 
    class TestZap(TestCaseInTempDir):
 
140
    class TestZap(TestCaseWithTransport):
137
141
 
138
142
        def make_checkout(self):
139
143
            wt = bzrdir.BzrDir.create_standalone_workingtree('source')
209
213
            checkout.branch.set_parent(branch.base)
210
214
            zap('checkout', policy=StoreChanges, remove_branch=True)
211
215
 
 
216
        def test_zap_branch_with_unique_revision(self):
 
217
            parent = self.make_branch_and_tree('parent')
 
218
            parent.commit('foo')
 
219
            new_branch = self.make_branch('new')
 
220
            new_branch.set_parent(parent.branch.base)
 
221
            checkout = new_branch.create_checkout('checkout', lightweight=True)
 
222
            checkout.commit('unique')
 
223
            self.assertRaises(ParentMissingRevisions, zap, 'checkout',
 
224
                              remove_branch=True)
 
225
 
212
226
    return makeSuite(TestZap)