1
# Copyright (C) 2005, 2006 by Canonical Ltd
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.tests import TestCaseWithTransport, TestCase
21
from bzrlib.branch import Branch
4
from bzrlib.tests import TestCaseInTempDir, TestCase
5
from bzrlib.branch import ScratchBranch, Branch
22
6
from bzrlib.errors import PathNotChild
23
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
26
class MoreTests(TestCaseWithTransport):
9
class TestBranch(TestCaseInTempDir):
11
def test_no_changes(self):
12
from bzrlib.errors import PointlessCommit
14
b = Branch.initialize(u'.')
16
self.build_tree(['hello.txt'])
18
self.assertRaises(PointlessCommit,
19
b.working_tree().commit,
20
'commit without adding',
21
allow_pointless=False)
23
b.working_tree().commit('commit pointless tree',
26
b.working_tree().add('hello.txt')
28
b.working_tree().commit('commit first added file',
29
allow_pointless=False)
31
self.assertRaises(PointlessCommit,
32
b.working_tree().commit,
33
'commit after adding file',
34
allow_pointless=False)
36
b.working_tree().commit('commit pointless revision with one file',
40
class MoreTests(TestCaseInTempDir):
42
def test_rename_dirs(self):
43
"""Test renaming directories and the files within them."""
44
b = Branch.initialize(u'.')
45
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
46
b.working_tree().add(['dir', 'dir/sub', 'dir/sub/file'])
48
b.working_tree().commit('create initial state')
50
# TODO: lift out to a test helper that checks the shape of
53
revid = b.revision_history()[0]
54
self.log('first revision_id is {%s}' % revid)
56
inv = b.get_revision_inventory(revid)
57
self.log('contents of inventory: %r' % inv.entries())
59
self.check_inventory_shape(inv,
60
['dir', 'dir/sub', 'dir/sub/file'])
62
b.working_tree().rename_one('dir', 'newdir')
64
self.check_inventory_shape(b.working_tree().read_working_inventory(),
65
['newdir', 'newdir/sub', 'newdir/sub/file'])
67
b.working_tree().rename_one('newdir/sub', 'newdir/newsub')
68
self.check_inventory_shape(b.working_tree().read_working_inventory(),
69
['newdir', 'newdir/newsub',
70
'newdir/newsub/file'])
28
72
def test_relpath(self):
29
73
"""test for branch path lookups
32
76
job: given a path (either relative to cwd or absolute), work out
33
77
if it is inside a branch and return the path relative to the base.
36
from bzrlib.osutils import rmtree
79
from bzrlib.osutils import relpath
80
import tempfile, shutil
38
82
savedir = os.getcwdu()
39
83
dtmp = tempfile.mkdtemp()
40
84
# On Mac OSX, /tmp actually expands to /private/tmp
85
dtmp = os.path.realpath(dtmp)
44
88
return relpath(dtmp, p)
47
91
# check paths inside dtmp while standing outside it
48
self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
92
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
51
95
self.assertEqual(rp(dtmp), '')
68
112
# directory, or nearby
71
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
115
FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
116
self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
73
118
self.assertEqual(rp('foo'), 'foo')
75
120
self.assertEqual(rp('./foo'), 'foo')
77
self.assertEqual(rp(abspath('foo')), 'foo')
122
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
79
124
self.assertRaises(PathNotChild,