~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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
19
19
 
20
20
import os
21
21
 
 
22
from bzrlib import ignores
 
23
 
22
24
from bzrlib.tests.blackbox import ExternalBase
23
 
from bzrlib.tests.test_win32utils import NeedsGlobExpansionFeature
24
25
 
25
26
 
26
27
class TestAdd(ExternalBase):
27
28
        
28
29
    def test_add_reports(self):
29
30
        """add command prints the names of added files."""
30
 
        tree = self.make_branch_and_tree('.')
 
31
        ignores._set_user_ignores(['./.bazaar'])
 
32
 
 
33
        self.runbzr('init')
31
34
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
32
35
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
33
 
        out = self.run_bzr('add')[0]
 
36
        out = self.run_bzr_captured(['add'], retcode=0)[0]
34
37
        # the ordering is not defined at the moment
35
38
        results = sorted(out.rstrip('\n').split('\n'))
36
39
        self.assertEquals(['If you wish to add some of these files, please'\
39
42
                           'added dir',
40
43
                           'added dir/sub.txt',
41
44
                           'added top.txt',
42
 
                           'ignored 1 file(s).'],
 
45
                           'ignored 2 file(s).'],
43
46
                          results)
44
 
        out = self.run_bzr('add -v')[0]
 
47
        out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
45
48
        results = sorted(out.rstrip('\n').split('\n'))
46
49
        self.assertEquals(['If you wish to add some of these files, please'\
47
50
                           ' add them by name.',
 
51
                           'ignored .bazaar matching "./.bazaar"',
48
52
                           'ignored CVS matching "CVS"'],
49
53
                          results)
50
54
 
51
55
    def test_add_quiet_is(self):
52
56
        """add -q does not print the names of added files."""
53
 
        tree = self.make_branch_and_tree('.') 
 
57
        self.runbzr('init')
54
58
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
55
 
        out = self.run_bzr('add -q')[0]
 
59
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
56
60
        # the ordering is not defined at the moment
57
61
        results = sorted(out.rstrip('\n').split('\n'))
58
62
        self.assertEquals([''], results)
62
66
 
63
67
        "bzr add" should add the parent(s) as necessary.
64
68
        """
65
 
        tree = self.make_branch_and_tree('.')
 
69
        ignores._set_user_ignores(['./.bazaar'])
 
70
 
 
71
        self.runbzr('init')
66
72
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
67
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
68
 
        self.run_bzr('add inertiatic/esp')
69
 
        self.assertEquals(self.run_bzr('unknowns')[0], '')
 
73
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
 
74
        self.run_bzr('add', 'inertiatic/esp')
 
75
        self.assertEquals(self.capture('unknowns'), '')
70
76
 
71
77
        # Multiple unversioned parents
72
78
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
73
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n')
74
 
        self.run_bzr('add veil/cerpin/taxt')
75
 
        self.assertEquals(self.run_bzr('unknowns')[0], '')
 
79
        self.assertEquals(self.capture('unknowns'), 'veil\n')
 
80
        self.run_bzr('add', 'veil/cerpin/taxt')
 
81
        self.assertEquals(self.capture('unknowns'), '')
76
82
 
77
83
        # Check whacky paths work
78
84
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
79
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n')
80
 
        self.run_bzr('add inertiatic/../cicatriz/esp')
81
 
        self.assertEquals(self.run_bzr('unknowns')[0], '')
 
85
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
 
86
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
 
87
        self.assertEquals(self.capture('unknowns'), '')
82
88
 
83
89
    def test_add_in_versioned(self):
84
90
        """Try to add a file in a versioned directory.
85
91
 
86
92
        "bzr add" should do this happily.
87
93
        """
88
 
        tree = self.make_branch_and_tree('.')
 
94
        ignores._set_user_ignores(['./.bazaar'])
 
95
 
 
96
        self.runbzr('init')
89
97
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
90
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
91
 
        self.run_bzr('add --no-recurse inertiatic')
92
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
93
 
        self.run_bzr('add inertiatic/esp')
94
 
        self.assertEquals(self.run_bzr('unknowns')[0], '')
 
98
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
 
99
        self.run_bzr('add', '--no-recurse', 'inertiatic')
 
100
        self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
 
101
        self.run_bzr('add', 'inertiatic/esp')
 
102
        self.assertEquals(self.capture('unknowns'), '')
95
103
 
96
104
    def test_subdir_add(self):
97
105
        """Add in subdirectory should add only things from there down"""
98
106
        from bzrlib.workingtree import WorkingTree
99
107
 
 
108
        ignores._set_user_ignores(['./.bazaar'])
100
109
        eq = self.assertEqual
101
110
        ass = self.assertTrue
102
111
        chdir = os.chdir
108
117
        eq(sorted(t.unknowns()),
109
118
           ['README', 'src'])
110
119
        
111
 
        self.run_bzr('add src')
 
120
        self.run_bzr('add', 'src')
112
121
        
113
122
        self.build_tree(['src/foo.c'])
114
123
        
115
 
        # add with no arguments in a subdirectory gets only files below that
116
 
        # subdirectory
117
124
        chdir('src')
118
125
        self.run_bzr('add')
119
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'README\n')
120
 
        # reopen to see the new changes
121
 
        t = t.bzrdir.open_workingtree()
122
 
        versioned = [path for path, entry in t.iter_entries_by_dir()]
123
 
        self.assertEquals(versioned,
124
 
            ['', 'src', 'src/foo.c'])
 
126
        
 
127
        self.assertEquals(self.capture('unknowns'), 'README\n')
 
128
        eq(len(t.read_working_inventory()), 3)
125
129
                
126
 
        # add from the parent directory should pick up all file names
127
130
        chdir('..')
128
131
        self.run_bzr('add')
129
 
        self.assertEquals(self.run_bzr('unknowns')[0], '')
 
132
        self.assertEquals(self.capture('unknowns'), '')
130
133
        self.run_bzr('check')
131
134
 
132
135
    def test_add_missing(self):
133
136
        """bzr add foo where foo is missing should error."""
134
137
        self.make_branch_and_tree('.')
135
 
        self.run_bzr('add missing-file', retcode=3)
136
 
 
137
 
    def test_add_from(self):
138
 
        base_tree = self.make_branch_and_tree('base')
139
 
        self.build_tree(['base/a', 'base/b/', 'base/b/c'])
140
 
        base_tree.add(['a', 'b', 'b/c'])
141
 
        base_tree.commit('foo')
142
 
 
143
 
        new_tree = self.make_branch_and_tree('new')
144
 
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
145
 
 
146
 
        os.chdir('new')
147
 
        out, err = self.run_bzr('add --file-ids-from ../base')
148
 
        self.assertEqual('', err)
149
 
        self.assertEqualDiff('added a w/ file id from a\n'
150
 
                             'added b w/ file id from b\n'
151
 
                             'added b/c w/ file id from b/c\n',
152
 
                             out)
153
 
        new_tree = new_tree.bzrdir.open_workingtree()
154
 
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
155
 
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
156
 
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
157
 
 
158
 
    def test_add_from_subdir(self):
159
 
        base_tree = self.make_branch_and_tree('base')
160
 
        self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d'])
161
 
        base_tree.add(['a', 'b', 'b/c', 'b/d'])
162
 
        base_tree.commit('foo')
163
 
 
164
 
        new_tree = self.make_branch_and_tree('new')
165
 
        self.build_tree(['new/c', 'new/d'])
166
 
 
167
 
        os.chdir('new')
168
 
        out, err = self.run_bzr('add --file-ids-from ../base/b')
169
 
        self.assertEqual('', err)
170
 
        self.assertEqualDiff('added c w/ file id from b/c\n'
171
 
                             'added d w/ file id from b/d\n',
172
 
                             out)
173
 
 
174
 
        new_tree = new_tree.bzrdir.open_workingtree()
175
 
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
176
 
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
177
 
 
178
 
    def test_add_dry_run(self):
179
 
        """Test a dry run add, make sure nothing is added."""
180
 
        wt = self.make_branch_and_tree('.')
181
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
182
 
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
183
 
        self.run_bzr('add --dry-run')
184
 
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
185
 
 
186
 
    def test_add_control_dir(self):
187
 
        """The control dir and its content should be refused."""
188
 
        self.make_branch_and_tree('.')
189
 
        err = self.run_bzr('add .bzr', retcode=3)[1]
190
 
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
191
 
        err = self.run_bzr('add .bzr/README', retcode=3)[1]
192
 
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
193
 
        self.build_tree(['.bzr/crescent'])
194
 
        err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
195
 
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
196
 
 
197
 
    def test_add_with_wildcards(self):
198
 
        self.requireFeature(NeedsGlobExpansionFeature)
199
 
        self.make_branch_and_tree('.')
200
 
        self.build_tree(['a1', 'a2', 'b', 'c33'])
201
 
        self.run_bzr(['add', 'a?', 'c*'])
202
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'b\n')
203
 
 
204
 
    def test_add_with_wildcards_unicode(self):
205
 
        self.requireFeature(NeedsGlobExpansionFeature)
206
 
        self.make_branch_and_tree('.')
207
 
        self.build_tree([u'\u1234A', u'\u1235A', u'\u1235AA', 'cc'])
208
 
        self.run_bzr(['add', u'\u1234?', u'\u1235*'])
209
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'cc\n')
 
138
        self.run_bzr('add', 'missing-file', retcode=3)