~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Packman
  • Date: 2011-12-08 19:00:14 UTC
  • mto: This revision was merged to the branch mainline in revision 6359.
  • Revision ID: martin.packman@canonical.com-20111208190014-mi8jm6v7jygmhb0r
Use --include-duplicates for make update-pot which already combines multiple msgid strings prettily

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Tests of simple versioning operations"""
 
19
 
 
20
# TODO: test trying to commit within a directory that is not yet added
 
21
 
 
22
 
 
23
import os
 
24
 
 
25
from bzrlib.branch import Branch
 
26
from bzrlib.osutils import pathjoin
 
27
from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
 
28
from bzrlib.trace import mutter
 
29
from bzrlib.workingtree import WorkingTree
 
30
 
 
31
 
 
32
class TestMkdir(TestCaseWithTransport):
 
33
 
 
34
    def test_mkdir_fails_cleanly(self):
 
35
        """'mkdir' fails cleanly when no working tree is available.
 
36
        https://bugs.launchpad.net/bzr/+bug/138600
 
37
        """
 
38
        # Since there is a safety working tree above us, we create a bare repo
 
39
        # here locally.
 
40
        shared_repo = self.make_repository('.')
 
41
        self.run_bzr(['mkdir', 'abc'], retcode=3)
 
42
        self.assertPathDoesNotExist('abc')
 
43
 
 
44
    def test_mkdir(self):
 
45
        """Basic 'bzr mkdir' operation"""
 
46
 
 
47
        self.make_branch_and_tree('.')
 
48
        self.run_bzr(['mkdir', 'foo'])
 
49
        self.assert_(os.path.isdir('foo'))
 
50
 
 
51
        self.run_bzr(['mkdir', 'foo'], retcode=3)
 
52
 
 
53
        wt = WorkingTree.open('.')
 
54
 
 
55
        delta = wt.changes_from(wt.basis_tree())
 
56
 
 
57
        self.log('delta.added = %r' % delta.added)
 
58
 
 
59
        self.assertEquals(len(delta.added), 1)
 
60
        self.assertEquals(delta.added[0][0], 'foo')
 
61
        self.assertFalse(delta.modified)
 
62
 
 
63
    def test_mkdir_in_subdir(self):
 
64
        """'bzr mkdir' operation in subdirectory"""
 
65
 
 
66
        self.make_branch_and_tree('.')
 
67
        self.run_bzr(['mkdir', 'dir'])
 
68
        self.assert_(os.path.isdir('dir'))
 
69
 
 
70
        os.chdir('dir')
 
71
        self.log('Run mkdir in subdir')
 
72
        self.run_bzr(['mkdir', 'subdir'])
 
73
        self.assert_(os.path.isdir('subdir'))
 
74
        os.chdir('..')
 
75
 
 
76
        wt = WorkingTree.open('.')
 
77
 
 
78
        delta = wt.changes_from(wt.basis_tree())
 
79
 
 
80
        self.log('delta.added = %r' % delta.added)
 
81
 
 
82
        self.assertEquals(len(delta.added), 2)
 
83
        self.assertEquals(delta.added[0][0], 'dir')
 
84
        self.assertEquals(delta.added[1][0], pathjoin('dir','subdir'))
 
85
        self.assertFalse(delta.modified)
 
86
 
 
87
    def test_mkdir_w_nested_trees(self):
 
88
        """'bzr mkdir' with nested trees"""
 
89
 
 
90
        self.make_branch_and_tree('.')
 
91
        self.make_branch_and_tree('a')
 
92
        self.make_branch_and_tree('a/b')
 
93
 
 
94
        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
 
95
        self.assertTrue(os.path.isdir('dir'))
 
96
        self.assertTrue(os.path.isdir('a/dir'))
 
97
        self.assertTrue(os.path.isdir('a/b/dir'))
 
98
 
 
99
        wt = WorkingTree.open('.')
 
100
        wt_a = WorkingTree.open('a')
 
101
        wt_b = WorkingTree.open('a/b')
 
102
 
 
103
        delta = wt.changes_from(wt.basis_tree())
 
104
        self.assertEquals(len(delta.added), 1)
 
105
        self.assertEquals(delta.added[0][0], 'dir')
 
106
        self.assertFalse(delta.modified)
 
107
 
 
108
        delta = wt_a.changes_from(wt_a.basis_tree())
 
109
        self.assertEquals(len(delta.added), 1)
 
110
        self.assertEquals(delta.added[0][0], 'dir')
 
111
        self.assertFalse(delta.modified)
 
112
 
 
113
        delta = wt_b.changes_from(wt_b.basis_tree())
 
114
        self.assertEquals(len(delta.added), 1)
 
115
        self.assertEquals(delta.added[0][0], 'dir')
 
116
        self.assertFalse(delta.modified)
 
117
 
 
118
    def test_mkdir_quiet(self):
 
119
        """'bzr mkdir --quiet' should not print a status message"""
 
120
 
 
121
        self.make_branch_and_tree('.')
 
122
        out, err = self.run_bzr(['mkdir', '--quiet', 'foo'])
 
123
        self.assertEquals('', err)
 
124
        self.assertEquals('', out)
 
125
 
 
126
 
 
127
class SubdirCommit(TestCaseWithTransport):
 
128
 
 
129
    def test_subdir_commit(self):
 
130
        """Test committing a subdirectory, and committing a directory."""
 
131
        tree = self.make_branch_and_tree('.')
 
132
        b = tree.branch
 
133
        self.build_tree(['a/', 'b/'])
 
134
        def set_contents(contents):
 
135
            self.build_tree_contents([
 
136
                ('a/one', contents),
 
137
                ('b/two', contents),
 
138
                ('top', contents),
 
139
                ])
 
140
        set_contents('old contents')
 
141
        tree.smart_add(['.'])
 
142
        tree.commit('first revision')
 
143
        set_contents('new contents')
 
144
 
 
145
        mutter('start selective subdir commit')
 
146
        self.run_bzr(['commit', 'a', '-m', 'commit a only'])
 
147
 
 
148
        new = b.repository.revision_tree(b.get_rev_id(2))
 
149
        new.lock_read()
 
150
 
 
151
        def get_text_by_path(tree, path):
 
152
            return tree.get_file_text(tree.path2id(path), path)
 
153
 
 
154
        self.assertEqual(get_text_by_path(new, 'b/two'), 'old contents')
 
155
        self.assertEqual(get_text_by_path(new, 'top'), 'old contents')
 
156
        self.assertEqual(get_text_by_path(new, 'a/one'), 'new contents')
 
157
        new.unlock()
 
158
 
 
159
        os.chdir('a')
 
160
        # commit from here should do nothing
 
161
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
 
162
        v3 = b.repository.revision_tree(b.get_rev_id(3))
 
163
        v3.lock_read()
 
164
        self.assertEqual(get_text_by_path(v3, 'b/two'), 'old contents')
 
165
        self.assertEqual(get_text_by_path(v3, 'top'), 'old contents')
 
166
        self.assertEqual(get_text_by_path(v3, 'a/one'), 'new contents')
 
167
        v3.unlock()
 
168
 
 
169
        # commit in subdirectory commits whole tree
 
170
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'])
 
171
        v4 = b.repository.revision_tree(b.get_rev_id(4))
 
172
        v4.lock_read()
 
173
        self.assertEqual(get_text_by_path(v4, 'b/two'), 'new contents')
 
174
        self.assertEqual(get_text_by_path(v4, 'top'), 'new contents')
 
175
        v4.unlock()
 
176
 
 
177
        # TODO: factor out some kind of assert_tree_state() method