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
18
"""Tests of the 'bzr add' command."""
22
from bzrlib.tests.blackbox import ExternalBase
25
class TestAdd(ExternalBase):
27
def test_add_reports(self):
28
"""add command prints the names of added files."""
30
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
31
self.build_tree_contents([('.bzrignore', 'CVS\n')])
32
out = self.run_bzr_captured(['add'], retcode=0)[0]
33
# the ordering is not defined at the moment
34
results = sorted(out.rstrip('\n').split('\n'))
35
self.assertEquals(['If you wish to add some of these files, please'\
41
'ignored 1 file(s).'],
43
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
44
results = sorted(out.rstrip('\n').split('\n'))
45
self.assertEquals(['If you wish to add some of these files, please'\
47
'ignored CVS matching "CVS"'],
50
def test_add_quiet_is(self):
51
"""add -q does not print the names of added files."""
53
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
54
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
55
# the ordering is not defined at the moment
56
results = sorted(out.rstrip('\n').split('\n'))
57
self.assertEquals([''], results)
59
def test_add_in_unversioned(self):
60
"""Try to add a file in an unversioned directory.
62
"bzr add" should add the parent(s) as necessary.
65
self.build_tree(['inertiatic/', 'inertiatic/esp'])
66
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
67
self.run_bzr('add', 'inertiatic/esp')
68
self.assertEquals(self.capture('unknowns'), '')
70
# Multiple unversioned parents
71
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
72
self.assertEquals(self.capture('unknowns'), 'veil\n')
73
self.run_bzr('add', 'veil/cerpin/taxt')
74
self.assertEquals(self.capture('unknowns'), '')
76
# Check whacky paths work
77
self.build_tree(['cicatriz/', 'cicatriz/esp'])
78
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
79
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
80
self.assertEquals(self.capture('unknowns'), '')
82
def test_add_in_versioned(self):
83
"""Try to add a file in a versioned directory.
85
"bzr add" should do this happily.
88
self.build_tree(['inertiatic/', 'inertiatic/esp'])
89
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
90
self.run_bzr('add', '--no-recurse', 'inertiatic')
91
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
92
self.run_bzr('add', 'inertiatic/esp')
93
self.assertEquals(self.capture('unknowns'), '')
95
def test_subdir_add(self):
96
"""Add in subdirectory should add only things from there down"""
97
from bzrlib.workingtree import WorkingTree
103
t = self.make_branch_and_tree('.')
105
self.build_tree(['src/', 'README'])
107
eq(sorted(t.unknowns()),
110
self.run_bzr('add', 'src')
112
self.build_tree(['src/foo.c'])
117
self.assertEquals(self.capture('unknowns'), 'README\n')
118
eq(len(t.read_working_inventory()), 3)
122
self.assertEquals(self.capture('unknowns'), '')
123
self.run_bzr('check')
125
def test_add_missing(self):
126
"""bzr add foo where foo is missing should error."""
127
self.make_branch_and_tree('.')
128
self.run_bzr('add', 'missing-file', retcode=3)