39
40
from bzrlib.clone import copy_branch
40
41
from bzrlib.errors import BzrCommandError
41
42
from bzrlib.osutils import has_symlinks
42
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
43
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
43
from bzrlib.tests import TestCaseInTempDir, BzrTestBase
44
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
46
47
class ExternalBase(TestCaseInTempDir):
170
171
self.runbzr('commit -m newstuff branch')
171
172
self.runbzr('commit -m newstuff branch', retcode=3)
174
174
def test_ignore_patterns(self):
175
175
from bzrlib.branch import Branch
177
b = Branch.initialize('.')
178
self.assertEquals(list(b.unknowns()), [])
176
Branch.initialize('.')
177
self.assertEquals(self.capture('unknowns'), '')
180
179
file('foo.tmp', 'wt').write('tmp files are ignored')
181
self.assertEquals(list(b.unknowns()), [])
182
180
self.assertEquals(self.capture('unknowns'), '')
184
182
file('foo.c', 'wt').write('int main() {}')
185
self.assertEquals(list(b.unknowns()), ['foo.c'])
186
183
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
188
185
self.runbzr(['add', 'foo.c'])
191
188
# 'ignore' works when creating the .bzignore file
192
189
file('foo.blah', 'wt').write('blah')
193
self.assertEquals(list(b.unknowns()), ['foo.blah'])
190
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
194
191
self.runbzr('ignore *.blah')
195
self.assertEquals(list(b.unknowns()), [])
192
self.assertEquals(self.capture('unknowns'), '')
196
193
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
198
195
# 'ignore' works when then .bzrignore file already exists
199
196
file('garh', 'wt').write('garh')
200
self.assertEquals(list(b.unknowns()), ['garh'])
201
197
self.assertEquals(self.capture('unknowns'), 'garh\n')
202
198
self.runbzr('ignore garh')
203
self.assertEquals(list(b.unknowns()), [])
199
self.assertEquals(self.capture('unknowns'), '')
204
200
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
206
202
def test_revert(self):
315
311
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
316
312
self.runbzr('export ../first.bz2 -r 1')
317
313
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
315
from tarfile import TarFile
318
316
self.runbzr('export ../first.tar -r 1')
319
317
self.assert_(os.path.isfile('../first.tar'))
320
from tarfile import TarFile
321
318
tf = TarFile('../first.tar')
322
319
self.assert_('first/hello' in tf.getnames(), tf.getnames())
323
320
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
338
336
tf = TarFile('../first2.tar')
339
337
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
339
from zipfile import ZipFile
340
self.runbzr('export ../first.zip -r 1')
341
self.failUnlessExists('../first.zip')
342
zf = ZipFile('../first.zip')
343
self.assert_('first/hello' in zf.namelist(), zf.namelist())
344
self.assertEqual(zf.read('first/hello'), 'foo')
346
self.runbzr('export ../first2.zip -r 1 --root pizza')
347
zf = ZipFile('../first2.zip')
348
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
350
self.runbzr('export ../first-zip --format=zip -r 1')
351
zf = ZipFile('../first-zip')
352
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
341
354
def test_diff(self):
342
355
self.example_branch()
343
356
file('hello', 'wt').write('hello world!')
354
367
def test_diff_branches(self):
355
368
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
356
369
branch = Branch.initialize('branch1')
370
branch.working_tree().add(['file'])
358
371
branch.working_tree().commit('add file')
359
372
copy_branch(branch, 'branch2')
360
373
print >> open('branch2/file', 'wb'), 'new content'
737
750
results = sorted(out.rstrip('\n').split('\n'))
738
751
self.assertEquals([''], results)
753
def test_add_in_unversioned(self):
754
"""Try to add a file in an unversioned directory.
756
"bzr add" should add the parent(s) as necessary.
758
from bzrlib.branch import Branch
759
Branch.initialize('.')
760
self.build_tree(['inertiatic/', 'inertiatic/esp'])
761
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
762
self.run_bzr('add', 'inertiatic/esp')
763
self.assertEquals(self.capture('unknowns'), '')
765
# Multiple unversioned parents
766
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
767
self.assertEquals(self.capture('unknowns'), 'veil\n')
768
self.run_bzr('add', 'veil/cerpin/taxt')
769
self.assertEquals(self.capture('unknowns'), '')
771
# Check whacky paths work
772
self.build_tree(['cicatriz/', 'cicatriz/esp'])
773
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
774
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
775
self.assertEquals(self.capture('unknowns'), '')
777
def test_add_in_versioned(self):
778
"""Try to add a file in a versioned directory.
780
"bzr add" should do this happily.
782
from bzrlib.branch import Branch
783
Branch.initialize('.')
784
self.build_tree(['inertiatic/', 'inertiatic/esp'])
785
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
786
self.run_bzr('add', '--no-recurse', 'inertiatic')
787
self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
788
self.run_bzr('add', 'inertiatic/esp')
789
self.assertEquals(self.capture('unknowns'), '')
791
def test_subdir_add(self):
792
"""Add in subdirectory should add only things from there down"""
793
from bzrlib.branch import Branch
795
eq = self.assertEqual
799
b = Branch.initialize('.')
801
self.build_tree(['src/', 'README'])
803
eq(sorted(t.unknowns()),
806
self.run_bzr('add', 'src')
808
self.build_tree(['src/foo.c'])
813
self.assertEquals(self.capture('unknowns'), 'README\n')
814
eq(len(t.read_working_inventory()), 3)
818
self.assertEquals(self.capture('unknowns'), '')
819
self.run_bzr('check')
740
821
def test_unknown_command(self):
741
822
"""Handling of unknown command."""
742
823
out, err = self.run_bzr_captured(['fluffy-badger'],
1260
1341
def test_check(self):
1261
1342
self.build_tree(['branch/', 'branch/file'])
1262
1343
branch = Branch.initialize('branch')
1263
branch.add(['file'])
1344
branch.working_tree().add(['file'])
1264
1345
branch.working_tree().commit('add file', rev_id='A')
1265
url = self.get_remote_url('branch/file')
1346
url = self.get_remote_url('branch/')
1266
1347
self.run_bzr('check', url)