/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_blackbox.py

  • Committer: Jelmer Vernooij
  • Date: 2019-05-29 03:22:34 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7306.
  • Revision ID: jelmer@jelmer.uk-20190529032234-mt3fuws8gq03tapi
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import os
27
27
 
28
 
from ... import (
29
 
    version_info as breezy_version,
30
 
    )
31
28
from ...controldir import (
32
29
    ControlDir,
33
30
    )
34
31
 
35
32
from ...tests.blackbox import ExternalBase
 
33
from ...workingtree import WorkingTree
36
34
 
37
35
from .. import (
38
36
    tests,
39
37
    )
 
38
from ...tests.features import PluginLoadedFeature
40
39
 
41
40
 
42
41
class TestGitBlackBox(ExternalBase):
65
64
        self.simple_commit()
66
65
        output, error = self.run_bzr(['info'])
67
66
        self.assertEqual(error, '')
68
 
        self.assertTrue("Standalone tree (format: git)" in output)
 
67
        self.assertEqual(
 
68
            output,
 
69
            'Standalone tree (format: git)\n'
 
70
            'Location:\n'
 
71
            '            light checkout root: .\n'
 
72
            '  checkout of co-located branch: master\n')
 
73
 
 
74
    def test_ignore(self):
 
75
        self.simple_commit()
 
76
        output, error = self.run_bzr(['ignore', 'foo'])
 
77
        self.assertEqual(error, '')
 
78
        self.assertEqual(output, '')
 
79
        self.assertFileEqual("foo\n", ".gitignore")
 
80
 
 
81
    def test_cat_revision(self):
 
82
        self.simple_commit()
 
83
        output, error = self.run_bzr(['cat-revision', '-r-1'], retcode=3)
 
84
        self.assertContainsRe(
 
85
            error,
 
86
            'brz: ERROR: Repository .* does not support access to raw '
 
87
            'revision texts')
 
88
        self.assertEqual(output, '')
69
89
 
70
90
    def test_branch(self):
71
91
        os.mkdir("gitbranch")
95
115
 
96
116
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
97
117
        self.assertEqual(error,
98
 
                'Fetching from Git to Bazaar repository. '
99
 
                'For better performance, fetch into a Git repository.\n')
 
118
                         'Fetching from Git to Bazaar repository. '
 
119
                         'For better performance, fetch into a Git repository.\n')
100
120
        self.assertEqual(output, '')
101
121
 
102
122
    def test_branch_ls(self):
177
197
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
178
198
        self.assertEqual(error, '')
179
199
        self.assertEqual(output,
180
 
            'diff --git /dev/null b/a\n'
181
 
            'old mode 0\n'
182
 
            'new mode 100644\n'
183
 
            'index 0000000..c197bd8 100644\n'
184
 
            '--- /dev/null\n'
185
 
            '+++ b/a\n'
186
 
            '@@ -0,0 +1 @@\n'
187
 
            '+contents of a\n')
 
200
                         'diff --git a/a b/a\n'
 
201
                         'old file mode 0\n'
 
202
                         'new file mode 100644\n'
 
203
                         'index 0000000..c197bd8 100644\n'
 
204
                         '--- /dev/null\n'
 
205
                         '+++ b/a\n'
 
206
                         '@@ -0,0 +1 @@\n'
 
207
                         '+contents of a\n')
188
208
 
189
209
    def test_git_import_uncolocated(self):
190
210
        r = GitRepo.init("a", mkdir=True)
191
211
        self.build_tree(["a/file"])
192
212
        r.stage("file")
193
 
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
194
 
        r.do_commit(ref=b"refs/heads/bbranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
213
        r.do_commit(ref=b"refs/heads/abranch",
 
214
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
215
        r.do_commit(ref=b"refs/heads/bbranch",
 
216
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
195
217
        self.run_bzr(["git-import", "a", "b"])
196
 
        self.assertEqual(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
 
218
        self.assertEqual(
 
219
            set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
197
220
 
198
221
    def test_git_import(self):
199
222
        r = GitRepo.init("a", mkdir=True)
200
223
        self.build_tree(["a/file"])
201
224
        r.stage("file")
202
 
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
203
 
        r.do_commit(ref=b"refs/heads/bbranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
225
        r.do_commit(ref=b"refs/heads/abranch",
 
226
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
227
        r.do_commit(ref=b"refs/heads/bbranch",
 
228
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
204
229
        self.run_bzr(["git-import", "--colocated", "a", "b"])
205
230
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
206
231
        self.assertEqual(set(["abranch", "bbranch"]),
207
 
                set(ControlDir.open("b").get_branches().keys()))
 
232
                         set(ControlDir.open("b").get_branches().keys()))
208
233
 
209
234
    def test_git_import_incremental(self):
210
235
        r = GitRepo.init("a", mkdir=True)
211
236
        self.build_tree(["a/file"])
212
237
        r.stage("file")
213
 
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
238
        r.do_commit(ref=b"refs/heads/abranch",
 
239
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
214
240
        self.run_bzr(["git-import", "--colocated", "a", "b"])
215
241
        self.run_bzr(["git-import", "--colocated", "a", "b"])
216
242
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
221
247
        r = GitRepo.init("a", mkdir=True)
222
248
        self.build_tree(["a/file"])
223
249
        r.stage("file")
224
 
        cid = r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
250
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
251
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
225
252
        r[b"refs/tags/atag"] = cid
226
253
        self.run_bzr(["git-import", "--colocated", "a", "b"])
227
254
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
228
255
        b = ControlDir.open("b")
229
256
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
230
257
        self.assertEqual(["atag"],
231
 
                list(b.open_branch("abranch").tags.get_tag_dict().keys()))
 
258
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
232
259
 
233
260
    def test_git_import_colo(self):
234
261
        r = GitRepo.init("a", mkdir=True)
235
262
        self.build_tree(["a/file"])
236
263
        r.stage("file")
237
 
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
238
 
        r.do_commit(ref=b"refs/heads/bbranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
264
        r.do_commit(ref=b"refs/heads/abranch",
 
265
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
266
        r.do_commit(ref=b"refs/heads/bbranch",
 
267
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
239
268
        self.make_controldir("b", format="development-colo")
240
269
        self.run_bzr(["git-import", "--colocated", "a", "b"])
241
270
        self.assertEqual(
246
275
        r = GitRepo.init("a", mkdir=True)
247
276
        self.build_tree(["a/file"])
248
277
        r.stage("file")
249
 
        cid = r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
278
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
279
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
250
280
        r[b"refs/tags/atag"] = cid
251
281
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
252
282
        self.assertEqual(stderr, "")
253
283
        self.assertEqual(stdout,
254
 
            'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
255
 
            'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
 
284
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
 
285
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
256
286
 
257
287
    def test_git_refs_from_bzr(self):
258
288
        tree = self.make_branch_and_tree('a')
259
289
        self.build_tree(["a/file"])
260
290
        tree.add(["file"])
261
 
        revid = tree.commit(committer=b"Joe <joe@example.com>", message=b"Dummy")
 
291
        revid = tree.commit(
 
292
            committer=b"Joe <joe@example.com>", message=b"Dummy")
262
293
        tree.branch.tags.set_tag("atag", revid)
263
294
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
264
295
        self.assertEqual(stderr, "")
285
316
        self.build_tree_contents([("gitr/foo", b"hello from git")])
286
317
        self.repo.stage("foo")
287
318
        self.repo.do_commit(
288
 
                b"message", committer=b"Somebody <user@example.com>",
289
 
                commit_timestamp=1526330165, commit_timezone=0,
290
 
                author_timestamp=1526330165, author_timezone=0,
291
 
                merge_heads=[b'aa' * 20])
 
319
            b"message", committer=b"Somebody <user@example.com>",
 
320
            author=b"Somebody <user@example.com>",
 
321
            commit_timestamp=1526330165, commit_timezone=0,
 
322
            author_timestamp=1526330165, author_timezone=0,
 
323
            merge_heads=[b'aa' * 20])
292
324
 
293
325
    def test_log_shallow(self):
294
326
        # Check that bzr log does not fail and includes the revision.
295
327
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
296
 
        self.assertEqual(error, 'brz: ERROR: Further revision history missing.\n')
 
328
        self.assertEqual(
 
329
            error, 'brz: ERROR: Further revision history missing.\n')
297
330
        self.assertEqual(output,
298
 
                '------------------------------------------------------------\n'
299
 
                'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
300
 
                'git commit: ' + self.repo.head().decode('ascii') + '\n'
301
 
                'committer: Somebody <user@example.com>\n'
302
 
                'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
303
 
                'message:\n'
304
 
                '  message\n')
 
331
                         '------------------------------------------------------------\n'
 
332
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
 
333
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
 
334
                         'committer: Somebody <user@example.com>\n'
 
335
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
 
336
                         'message:\n'
 
337
                         '  message\n')
305
338
 
306
339
    def test_version_info_rio(self):
307
340
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
315
348
 
316
349
    def test_version_info_custom_with_revno(self):
317
350
        output, error = self.run_bzr(
318
 
                ['version-info', '--custom',
319
 
                 '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
320
 
        self.assertEqual(error, 'brz: ERROR: Variable {revno} is not available.\n')
 
351
            ['version-info', '--custom',
 
352
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
 
353
        self.assertEqual(
 
354
            error, 'brz: ERROR: Variable {revno} is not available.\n')
321
355
        self.assertEqual(output, 'VERSION_INFO r')
322
356
 
323
357
    def test_version_info_custom_without_revno(self):
324
358
        output, error = self.run_bzr(
325
 
                ['version-info', '--custom', '--template=VERSION_INFO \n',
326
 
                 'gitr'])
 
359
            ['version-info', '--custom', '--template=VERSION_INFO \n',
 
360
             'gitr'])
327
361
        self.assertEqual(error, '')
328
362
        self.assertEqual(output, 'VERSION_INFO \n')
 
363
 
 
364
 
 
365
class SwitchTests(ExternalBase):
 
366
 
 
367
    def test_switch_branch(self):
 
368
        # Create a git repository with a revision.
 
369
        repo = GitRepo.init(self.test_dir)
 
370
        builder = tests.GitBranchBuilder()
 
371
        builder.set_branch(b'refs/heads/oldbranch')
 
372
        builder.set_file('a', b'text for a\n', False)
 
373
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
374
        builder.set_branch(b'refs/heads/newbranch')
 
375
        builder.reset()
 
376
        builder.set_file('a', b'text for new a\n', False)
 
377
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
378
        builder.finish()
 
379
 
 
380
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
 
381
 
 
382
        repo.reset_index()
 
383
 
 
384
        output, error = self.run_bzr('switch oldbranch')
 
385
        self.assertEqual(output, '')
 
386
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
 
387
 
 
388
        self.assertFileEqual("text for a\n", 'a')
 
389
        tree = WorkingTree.open('.')
 
390
        with tree.lock_read():
 
391
            basis_tree = tree.basis_tree()
 
392
            with basis_tree.lock_read():
 
393
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
 
394
 
 
395
 
 
396
class GrepTests(ExternalBase):
 
397
 
 
398
    def test_simple_grep(self):
 
399
        tree = self.make_branch_and_tree('.', format='git')
 
400
        self.build_tree_contents([('a', 'text for a\n')])
 
401
        tree.add(['a'])
 
402
        output, error = self.run_bzr('grep text')
 
403
        self.assertEqual(output, 'a:text for a\n')
 
404
        self.assertEqual(error, '')
 
405
 
 
406
 
 
407
class ReconcileTests(ExternalBase):
 
408
 
 
409
    def test_simple_reconcile(self):
 
410
        tree = self.make_branch_and_tree('.', format='git')
 
411
        self.build_tree_contents([('a', 'text for a\n')])
 
412
        tree.add(['a'])
 
413
        output, error = self.run_bzr('reconcile')
 
414
        self.assertContainsRe(
 
415
            output,
 
416
            'Reconciling branch file://.*\n'
 
417
            'Reconciling repository file://.*\n'
 
418
            'Reconciliation complete.\n')
 
419
        self.assertEqual(error, '')
 
420
 
 
421
 
 
422
class StatusTests(ExternalBase):
 
423
 
 
424
    def test_empty_dir(self):
 
425
        tree = self.make_branch_and_tree('.', format='git')
 
426
        self.build_tree(['a/', 'a/foo'])
 
427
        self.build_tree_contents([('.gitignore', 'foo\n')])
 
428
        tree.add(['.gitignore'])
 
429
        tree.commit('add ignore')
 
430
        output, error = self.run_bzr('st')
 
431
        self.assertEqual(output, '')
 
432
        self.assertEqual(error, '')
 
433
 
 
434
 
 
435
class StatsTests(ExternalBase):
 
436
 
 
437
    def test_simple_stats(self):
 
438
        self.requireFeature(PluginLoadedFeature('stats'))
 
439
        tree = self.make_branch_and_tree('.', format='git')
 
440
        self.build_tree_contents([('a', 'text for a\n')])
 
441
        tree.add(['a'])
 
442
        tree.commit('a commit', committer='Somebody <somebody@example.com>')
 
443
        output, error = self.run_bzr('stats')
 
444
        self.assertEqual(output, '   1 Somebody <somebody@example.com>\n')
 
445
 
 
446
 
 
447
class GitObjectsTests(ExternalBase):
 
448
 
 
449
    def run_simple(self, format):
 
450
        tree = self.make_branch_and_tree('.', format=format)
 
451
        self.build_tree(['a/', 'a/foo'])
 
452
        tree.add(['a'])
 
453
        tree.commit('add a')
 
454
        output, error = self.run_bzr('git-objects')
 
455
        shas = list(output.splitlines())
 
456
        self.assertEqual([40, 40], [len(s) for s in shas])
 
457
        self.assertEqual(error, '')
 
458
 
 
459
        output, error = self.run_bzr('git-object %s' % shas[0])
 
460
        self.assertEqual('', error)
 
461
 
 
462
    def test_in_native(self):
 
463
        self.run_simple(format='git')
 
464
 
 
465
    def test_in_bzr(self):
 
466
        self.run_simple(format='2a')
 
467
 
 
468
 
 
469
class GitApplyTests(ExternalBase):
 
470
 
 
471
    def test_apply(self):
 
472
        b = self.make_branch_and_tree('.')
 
473
 
 
474
        with open('foo.patch', 'w') as f:
 
475
            f.write("""\
 
476
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
 
477
From: Dmitry Bogatov <KAction@debian.org>
 
478
Date: Fri, 8 Feb 2019 23:28:30 +0000
 
479
Subject: [PATCH] Add fixed for out-of-date-standards-version
 
480
 
 
481
---
 
482
 message           | 3 +++
 
483
 1 files changed, 14 insertions(+)
 
484
 create mode 100644 message
 
485
 
 
486
diff --git a/message b/message
 
487
new file mode 100644
 
488
index 0000000..05ec0b1
 
489
--- /dev/null
 
490
+++ b/message
 
491
@@ -0,0 +1,3 @@
 
492
+Update standards version, no changes needed.
 
493
+Certainty: certain
 
494
+Fixed-Lintian-Tags: out-of-date-standards-version
 
495
""")
 
496
        output, error = self.run_bzr('git-apply foo.patch')
 
497
        self.assertContainsRe(
 
498
            error,
 
499
            'Committing to: .*\n'
 
500
            'Committed revision 1.\n')