~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_uncommit.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Test the uncommit command."""
18
18
 
19
19
import os
20
20
 
21
 
from bzrlib import uncommit, workingtree
 
21
from bzrlib import uncommit
22
22
from bzrlib.bzrdir import BzrDirMetaFormat1
23
 
from bzrlib.errors import BzrError, BoundBranchOutOfDate
 
23
from bzrlib.errors import BoundBranchOutOfDate
24
24
from bzrlib.tests import TestCaseWithTransport
 
25
from bzrlib.tests.script import (
 
26
    run_script,
 
27
    ScriptRunner,
 
28
    )
25
29
 
26
30
 
27
31
class TestUncommit(TestCaseWithTransport):
60
64
        out, err = self.run_bzr('status')
61
65
        self.assertEquals(out, 'modified:\n  a\n')
62
66
 
 
67
    def test_uncommit_interactive(self):
 
68
        """Uncommit seeks confirmation, and doesn't proceed without it."""
 
69
        wt = self.create_simple_tree()
 
70
        os.chdir('tree')
 
71
        run_script(self, """    
 
72
        $ bzr uncommit
 
73
        ...
 
74
        The above revision(s) will be removed.
 
75
        2>Uncommit these revisions? [y/n]: 
 
76
        <n
 
77
        Canceled
 
78
        """)
 
79
        self.assertEqual(['a2'], wt.get_parent_ids())
 
80
 
63
81
    def test_uncommit_no_history(self):
64
82
        wt = self.make_branch_and_tree('tree')
65
83
        out, err = self.run_bzr('uncommit --force', retcode=1)
103
121
        uncommit.uncommit(b)
104
122
        self.assertEqual(len(b.revision_history()), 2)
105
123
        self.assertEqual(len(t_a.branch.revision_history()), 2)
106
 
        # update A's tree to not have the uncomitted revision referenced.
 
124
        # update A's tree to not have the uncommitted revision referenced.
107
125
        t_a.update()
108
126
        t_a.commit('commit 3b')
109
127
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
216
234
    def test_uncommit_shows_log_with_revision_id(self):
217
235
        wt = self.create_simple_tree()
218
236
 
219
 
        out, err = self.run_bzr('uncommit --force', working_dir='tree')
220
 
        self.assertContainsRe(out, r'second commit')
221
 
        self.assertContainsRe(err, r'You can restore the old tip by running')
222
 
        self.assertContainsRe(err, r'bzr pull . -r revid:a2')
 
237
        script = ScriptRunner()
 
238
        script.run_script(self, """
 
239
$ cd tree
 
240
$ bzr uncommit --force 
 
241
    2 ...
 
242
      second commit
 
243
...
 
244
The above revision(s) will be removed.
 
245
You can restore the old tip by running:
 
246
  bzr pull . -r revid:a2
 
247
""")
223
248
 
224
249
    def test_uncommit_octopus_merge(self):
225
250
        # Check that uncommit keeps the pending merges in the same order
233
258
        tree3.commit('unchanged', rev_id='c3')
234
259
 
235
260
        wt.merge_from_branch(tree2.branch)
236
 
        wt.merge_from_branch(tree3.branch)
 
261
        wt.merge_from_branch(tree3.branch, force=True)
237
262
        wt.commit('merge b3, c3', rev_id='a3')
238
263
 
239
264
        tree2.commit('unchanged', rev_id='b4')
240
265
        tree3.commit('unchanged', rev_id='c4')
241
266
 
242
267
        wt.merge_from_branch(tree3.branch)
243
 
        wt.merge_from_branch(tree2.branch)
 
268
        wt.merge_from_branch(tree2.branch, force=True)
244
269
        wt.commit('merge b4, c4', rev_id='a4')
245
270
 
246
271
        self.assertEqual(['a4'], wt.get_parent_ids())
255
280
        tree.commit(u'\u1234 message')
256
281
        out, err = self.run_bzr('uncommit --force tree', encoding='ascii')
257
282
        self.assertContainsRe(out, r'\? message')
 
283
 
 
284
    def test_uncommit_removes_tags(self):
 
285
        tree = self.make_branch_and_tree('tree')
 
286
        revid = tree.commit('message')
 
287
        tree.branch.tags.set_tag("atag", revid)
 
288
        out, err = self.run_bzr('uncommit --force tree')
 
289
        self.assertEquals({}, tree.branch.tags.get_tag_dict())
 
290
 
 
291
    def test_uncommit_keep_tags(self):
 
292
        tree = self.make_branch_and_tree('tree')
 
293
        revid = tree.commit('message')
 
294
        tree.branch.tags.set_tag("atag", revid)
 
295
        out, err = self.run_bzr('uncommit --keep-tags --force tree')
 
296
        self.assertEquals({"atag": revid}, tree.branch.tags.get_tag_dict())