~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_rspush.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 07:12:26 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129071226-a04b3f827880025d
Unshelve --pick was broken, because we deleted the whole patch, even when only
part of it was unshelved. So now if we unshelve part of a patch, the patch is
replaced with a new patch that has just the unshelved parts. That's a long way
of saying it does what you'd expect.

Implementing this required changing HunkSelector to return both the selected,
and unselected hunks (ie. patches to shelve, and patches to keep).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Aaron Bentley
2
 
#
3
 
#    This program is free software; you can redistribute it and/or modify
4
 
#    it under the terms of the GNU General Public License as published by
5
 
#    the Free Software Foundation; either version 2 of the License, or
6
 
#    (at your option) any later version.
7
 
#
8
 
#    This program is distributed in the hope that it will be useful,
9
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
#    GNU General Public License for more details.
12
 
#
13
 
#    You should have received a copy of the GNU General Public License
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
16
 
 
17
 
 
18
 
import os
19
 
 
20
 
from bzrlib.bzrdir import BzrDir
21
 
from bzrlib.tests import TestCaseWithTransport, TestSkipped
22
 
 
23
 
from bzrlib.plugins.bzrtools.bzrtools import (
24
 
    history_subset,
25
 
    NoRsync,
26
 
    NotStandalone,
27
 
    rspush,
28
 
    rsync,
29
 
    RsyncNoFile,
30
 
)
31
 
 
32
 
 
33
 
class MockRSync(object):
34
 
 
35
 
    def __init__(self):
36
 
        self.calls = []
37
 
 
38
 
    def __call__(self, source, target, **kwargs):
39
 
        self.calls.append((source, target, kwargs))
40
 
        if target.endswith('revision-history'):
41
 
            output = open(target, 'wb')
42
 
            output.close()
43
 
 
44
 
 
45
 
class TestRSPush(TestCaseWithTransport):
46
 
 
47
 
    def test_rsync(self):
48
 
        cwd = os.getcwd()
49
 
        try:
50
 
            self.assertRaises(RsyncNoFile, rsync, "a", "b", silent=True)
51
 
        except NoRsync:
52
 
            raise TestSkipped('rsync not installed')
53
 
        self.assertRaises(RsyncNoFile, rsync, cwd + "/a", cwd + "/b",
54
 
                          excludes=("*.py",), silent=True)
55
 
        self.assertRaises(NoRsync, rsync, cwd + "/a", cwd + "/b",
56
 
                          excludes=("*.py",), silent=True,
57
 
                          rsync_name="rsyncc")
58
 
 
59
 
    def test_rspush_locking(self):
60
 
        tree = self.make_branch_and_tree('tree', format='dirstate-tags')
61
 
        tree.commit('some changes')
62
 
        mock_rsync = MockRSync()
63
 
        rspush(tree, 'example.org:foo', _rsync=mock_rsync)
64
 
        rspush(tree, 'example.org:foo', working_tree = False,
65
 
               _rsync=mock_rsync)
66
 
        tree2 = self.make_branch_and_tree('tree2',
67
 
                                          format='pack-0.92')
68
 
        rspush(tree2, 'example.org:foo', _rsync=mock_rsync)
69
 
 
70
 
    def test_refuse_lightweight_checkout(self):
71
 
        branch = self.make_branch('tree')
72
 
        checkout = branch.create_checkout('checkout', lightweight=True)
73
 
        checkout.commit('some changes')
74
 
        mock_rsync = MockRSync()
75
 
        e = self.assertRaises(NotStandalone, rspush, checkout,
76
 
                              'example.org:foo', _rsync=mock_rsync)
77
 
        self.assertContainsRe(str(e), '/checkout/ is not a standalone tree.$')
78
 
 
79
 
    def test_refuse_checkout(self):
80
 
        branch = self.make_branch('tree')
81
 
        checkout = branch.create_checkout('checkout')
82
 
        checkout.commit('some changes')
83
 
        mock_rsync = MockRSync()
84
 
        self.assertRaises(NotStandalone, rspush, checkout, 'example.org:foo',
85
 
                          _rsync=mock_rsync)
86
 
 
87
 
    def test_refuse_shared(self):
88
 
        repo = self.make_repository('repo', shared=True)
89
 
        bzrdir = BzrDir.open('repo')
90
 
        bzrdir.create_branch()
91
 
        bzrdir.create_workingtree()
92
 
        tree = bzrdir.open_workingtree()
93
 
        tree.commit('some changes')
94
 
        mock_rsync = MockRSync()
95
 
        self.assertRaises(NotStandalone, rspush, tree, 'example.org:foo',
96
 
                          _rsync=mock_rsync)
97
 
 
98
 
    def do_history_subset(self, format):
99
 
        tree_a = self.make_branch_and_tree('tree_a', format=format)
100
 
        tree_a.lock_write()
101
 
        self.addCleanup(tree_a.unlock)
102
 
        tree_a.commit('foo')
103
 
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
104
 
        tree_a.commit('bar')
105
 
        try:
106
 
            self.assertTrue(history_subset('tree_b/', tree_a.branch))
107
 
        except NoRsync:
108
 
            raise TestSkipped('rsync not installed')
109
 
        self.assertFalse(history_subset('tree_a/', tree_b.branch))
110
 
 
111
 
    def do_history_subset_no_commits(self, format):
112
 
        tree_a = self.make_branch_and_tree('tree_a', format=format)
113
 
        tree_b = self.make_branch_and_tree('tree_b', format=format)
114
 
        try:
115
 
            self.assertTrue(history_subset('tree_b/', tree_a.branch))
116
 
        except NoRsync:
117
 
            raise TestSkipped('rsync not installed')
118
 
 
119
 
    def test_history_subset_dirstate(self):
120
 
        self.do_history_subset('dirstate')
121
 
 
122
 
    def test_history_subset_no_commits_dirstate(self):
123
 
        self.do_history_subset_no_commits('dirstate')
124
 
 
125
 
    def test_history_subset_pack(self):
126
 
        self.do_history_subset('pack-0.92')
127
 
 
128
 
    def test_history_subset_no_commits_pack(self):
129
 
        self.do_history_subset_no_commits('pack-0.92')