1
# Copyright (C) 2007 Aaron Bentley
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.
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.
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
20
from bzrlib.bzrdir import BzrDir
21
from bzrlib.tests import TestCaseWithTransport, TestSkipped
23
from bzrlib.plugins.bzrtools.bzrtools import (
33
class MockRSync(object):
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')
45
class TestRSPush(TestCaseWithTransport):
50
self.assertRaises(RsyncNoFile, rsync, "a", "b", silent=True)
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,
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,
66
tree2 = self.make_branch_and_tree('tree2',
68
rspush(tree2, 'example.org:foo', _rsync=mock_rsync)
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
self.assertRaises(NotStandalone, rspush, checkout, 'example.org:foo',
78
def test_refuse_checkout(self):
79
branch = self.make_branch('tree')
80
checkout = branch.create_checkout('checkout')
81
checkout.commit('some changes')
82
mock_rsync = MockRSync()
83
self.assertRaises(NotStandalone, rspush, checkout, 'example.org:foo',
86
def test_refuse_shared(self):
87
repo = self.make_repository('repo', shared=True)
88
bzrdir = BzrDir.open('repo')
89
bzrdir.create_branch()
90
bzrdir.create_workingtree()
91
tree = bzrdir.open_workingtree()
92
tree.commit('some changes')
93
mock_rsync = MockRSync()
94
self.assertRaises(NotStandalone, rspush, tree, 'example.org:foo',
97
def do_history_subset(self, format):
98
tree_a = self.make_branch_and_tree('tree_a', format=format)
100
self.addCleanup(tree_a.unlock)
102
tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
105
self.assertTrue(history_subset('tree_b/', tree_a.branch))
107
raise TestSkipped('rsync not installed')
108
self.assertFalse(history_subset('tree_a/', tree_b.branch))
110
def do_history_subset_no_commits(self, format):
111
tree_a = self.make_branch_and_tree('tree_a', format=format)
112
tree_b = self.make_branch_and_tree('tree_b', format=format)
114
self.assertTrue(history_subset('tree_b/', tree_a.branch))
116
raise TestSkipped('rsync not installed')
118
def test_history_subset_dirstate(self):
119
self.do_history_subset('dirstate')
121
def test_history_subset_no_commits_dirstate(self):
122
self.do_history_subset_no_commits('dirstate')
124
def test_history_subset_pack(self):
125
self.do_history_subset('pack-0.92')
127
def test_history_subset_no_commits_pack(self):
128
self.do_history_subset_no_commits('pack-0.92')