/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-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
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")
69
80
 
70
81
    def test_branch(self):
71
82
        os.mkdir("gitbranch")
95
106
 
96
107
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
97
108
        self.assertEqual(error,
98
 
                'Fetching from Git to Bazaar repository. '
99
 
                'For better performance, fetch into a Git repository.\n')
 
109
                         'Fetching from Git to Bazaar repository. '
 
110
                         'For better performance, fetch into a Git repository.\n')
100
111
        self.assertEqual(output, '')
101
112
 
102
113
    def test_branch_ls(self):
177
188
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
178
189
        self.assertEqual(error, '')
179
190
        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')
 
191
                         'diff --git /dev/null b/a\n'
 
192
                         'old mode 0\n'
 
193
                         'new mode 100644\n'
 
194
                         'index 0000000..c197bd8 100644\n'
 
195
                         '--- /dev/null\n'
 
196
                         '+++ b/a\n'
 
197
                         '@@ -0,0 +1 @@\n'
 
198
                         '+contents of a\n')
188
199
 
189
200
    def test_git_import_uncolocated(self):
190
201
        r = GitRepo.init("a", mkdir=True)
191
202
        self.build_tree(["a/file"])
192
203
        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")
 
204
        r.do_commit(ref=b"refs/heads/abranch",
 
205
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
206
        r.do_commit(ref=b"refs/heads/bbranch",
 
207
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
195
208
        self.run_bzr(["git-import", "a", "b"])
196
 
        self.assertEqual(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
 
209
        self.assertEqual(
 
210
            set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
197
211
 
198
212
    def test_git_import(self):
199
213
        r = GitRepo.init("a", mkdir=True)
200
214
        self.build_tree(["a/file"])
201
215
        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")
 
216
        r.do_commit(ref=b"refs/heads/abranch",
 
217
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
218
        r.do_commit(ref=b"refs/heads/bbranch",
 
219
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
204
220
        self.run_bzr(["git-import", "--colocated", "a", "b"])
205
221
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
206
222
        self.assertEqual(set(["abranch", "bbranch"]),
207
 
                set(ControlDir.open("b").get_branches().keys()))
 
223
                         set(ControlDir.open("b").get_branches().keys()))
208
224
 
209
225
    def test_git_import_incremental(self):
210
226
        r = GitRepo.init("a", mkdir=True)
211
227
        self.build_tree(["a/file"])
212
228
        r.stage("file")
213
 
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
229
        r.do_commit(ref=b"refs/heads/abranch",
 
230
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
214
231
        self.run_bzr(["git-import", "--colocated", "a", "b"])
215
232
        self.run_bzr(["git-import", "--colocated", "a", "b"])
216
233
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
221
238
        r = GitRepo.init("a", mkdir=True)
222
239
        self.build_tree(["a/file"])
223
240
        r.stage("file")
224
 
        cid = r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
241
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
242
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
225
243
        r[b"refs/tags/atag"] = cid
226
244
        self.run_bzr(["git-import", "--colocated", "a", "b"])
227
245
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
228
246
        b = ControlDir.open("b")
229
247
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
230
248
        self.assertEqual(["atag"],
231
 
                list(b.open_branch("abranch").tags.get_tag_dict().keys()))
 
249
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
232
250
 
233
251
    def test_git_import_colo(self):
234
252
        r = GitRepo.init("a", mkdir=True)
235
253
        self.build_tree(["a/file"])
236
254
        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")
 
255
        r.do_commit(ref=b"refs/heads/abranch",
 
256
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
257
        r.do_commit(ref=b"refs/heads/bbranch",
 
258
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
239
259
        self.make_controldir("b", format="development-colo")
240
260
        self.run_bzr(["git-import", "--colocated", "a", "b"])
241
261
        self.assertEqual(
246
266
        r = GitRepo.init("a", mkdir=True)
247
267
        self.build_tree(["a/file"])
248
268
        r.stage("file")
249
 
        cid = r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
269
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
270
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
250
271
        r[b"refs/tags/atag"] = cid
251
272
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
252
273
        self.assertEqual(stderr, "")
253
274
        self.assertEqual(stdout,
254
 
            'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
255
 
            'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
 
275
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
 
276
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
256
277
 
257
278
    def test_git_refs_from_bzr(self):
258
279
        tree = self.make_branch_and_tree('a')
259
280
        self.build_tree(["a/file"])
260
281
        tree.add(["file"])
261
 
        revid = tree.commit(committer=b"Joe <joe@example.com>", message=b"Dummy")
 
282
        revid = tree.commit(
 
283
            committer=b"Joe <joe@example.com>", message=b"Dummy")
262
284
        tree.branch.tags.set_tag("atag", revid)
263
285
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
264
286
        self.assertEqual(stderr, "")
285
307
        self.build_tree_contents([("gitr/foo", b"hello from git")])
286
308
        self.repo.stage("foo")
287
309
        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])
 
310
            b"message", committer=b"Somebody <user@example.com>",
 
311
            author=b"Somebody <user@example.com>",
 
312
            commit_timestamp=1526330165, commit_timezone=0,
 
313
            author_timestamp=1526330165, author_timezone=0,
 
314
            merge_heads=[b'aa' * 20])
292
315
 
293
316
    def test_log_shallow(self):
294
317
        # Check that bzr log does not fail and includes the revision.
295
318
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
296
 
        self.assertEqual(error, 'brz: ERROR: Further revision history missing.\n')
 
319
        self.assertEqual(
 
320
            error, 'brz: ERROR: Further revision history missing.\n')
297
321
        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')
 
322
                         '------------------------------------------------------------\n'
 
323
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
 
324
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
 
325
                         'committer: Somebody <user@example.com>\n'
 
326
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
 
327
                         'message:\n'
 
328
                         '  message\n')
305
329
 
306
330
    def test_version_info_rio(self):
307
331
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
315
339
 
316
340
    def test_version_info_custom_with_revno(self):
317
341
        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')
 
342
            ['version-info', '--custom',
 
343
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
 
344
        self.assertEqual(
 
345
            error, 'brz: ERROR: Variable {revno} is not available.\n')
321
346
        self.assertEqual(output, 'VERSION_INFO r')
322
347
 
323
348
    def test_version_info_custom_without_revno(self):
324
349
        output, error = self.run_bzr(
325
 
                ['version-info', '--custom', '--template=VERSION_INFO \n',
326
 
                 'gitr'])
 
350
            ['version-info', '--custom', '--template=VERSION_INFO \n',
 
351
             'gitr'])
327
352
        self.assertEqual(error, '')
328
353
        self.assertEqual(output, 'VERSION_INFO \n')
 
354
 
 
355
 
 
356
class SwitchTests(ExternalBase):
 
357
 
 
358
    def test_switch_branch(self):
 
359
        # Create a git repository with a revision.
 
360
        repo = GitRepo.init(self.test_dir)
 
361
        builder = tests.GitBranchBuilder()
 
362
        builder.set_branch(b'refs/heads/oldbranch')
 
363
        builder.set_file('a', b'text for a\n', False)
 
364
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
365
        builder.set_branch(b'refs/heads/newbranch')
 
366
        builder.reset()
 
367
        builder.set_file('a', b'text for new a\n', False)
 
368
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
369
        builder.finish()
 
370
 
 
371
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
 
372
 
 
373
        repo.reset_index()
 
374
 
 
375
        output, error = self.run_bzr('switch oldbranch')
 
376
        self.assertEqual(output, '')
 
377
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
 
378
 
 
379
        self.assertFileEqual("text for a\n", 'a')
 
380
        tree = WorkingTree.open('.')
 
381
        with tree.lock_read():
 
382
            basis_tree = tree.basis_tree()
 
383
            with basis_tree.lock_read():
 
384
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
 
385
 
 
386
 
 
387
class GrepTests(ExternalBase):
 
388
 
 
389
    def test_simple_grep(self):
 
390
        tree = self.make_branch_and_tree('.', format='git')
 
391
        self.build_tree_contents([('a', 'text for a\n')])
 
392
        tree.add(['a'])
 
393
        output, error = self.run_bzr('grep text')
 
394
        self.assertEqual(output, 'a:text for a\n')
 
395
        self.assertEqual(error, '')
 
396
 
 
397
 
 
398
class ReconcileTests(ExternalBase):
 
399
 
 
400
    def test_simple_reconcile(self):
 
401
        tree = self.make_branch_and_tree('.', format='git')
 
402
        self.build_tree_contents([('a', 'text for a\n')])
 
403
        tree.add(['a'])
 
404
        output, error = self.run_bzr('reconcile')
 
405
        self.assertContainsRe(
 
406
            output,
 
407
            'Reconciling branch file://.*\n'
 
408
            'Reconciling repository file://.*\n'
 
409
            'Reconciliation complete.\n')
 
410
        self.assertEqual(error, '')
 
411
 
 
412
 
 
413
class StatusTests(ExternalBase):
 
414
 
 
415
    def test_empty_dir(self):
 
416
        tree = self.make_branch_and_tree('.', format='git')
 
417
        self.build_tree(['a/', 'a/foo'])
 
418
        self.build_tree_contents([('.gitignore', 'foo\n')])
 
419
        tree.add(['.gitignore'])
 
420
        tree.commit('add ignore')
 
421
        output, error = self.run_bzr('st')
 
422
        self.assertEqual(output, '')
 
423
        self.assertEqual(error, '')
 
424
 
 
425
 
 
426
class StatsTests(ExternalBase):
 
427
 
 
428
    def test_simple_stats(self):
 
429
        self.requireFeature(PluginLoadedFeature('stats'))
 
430
        tree = self.make_branch_and_tree('.', format='git')
 
431
        self.build_tree_contents([('a', 'text for a\n')])
 
432
        tree.add(['a'])
 
433
        tree.commit('a commit', committer='Somebody <somebody@example.com>')
 
434
        output, error = self.run_bzr('stats')
 
435
        self.assertEqual(output, '   1 Somebody <somebody@example.com>\n')
 
436
 
 
437
 
 
438
class GitObjectsTests(ExternalBase):
 
439
 
 
440
    def run_simple(self, format):
 
441
        tree = self.make_branch_and_tree('.', format=format)
 
442
        self.build_tree(['a/', 'a/foo'])
 
443
        tree.add(['a'])
 
444
        tree.commit('add a')
 
445
        output, error = self.run_bzr('git-objects')
 
446
        shas = list(output.splitlines())
 
447
        self.assertEqual([40, 40], [len(s) for s in shas])
 
448
        self.assertEqual(error, '')
 
449
 
 
450
        output, error = self.run_bzr('git-object %s' % shas[0])
 
451
        self.assertEqual('', error)
 
452
 
 
453
    def test_in_native(self):
 
454
        self.run_simple(format='git')
 
455
 
 
456
    def test_in_bzr(self):
 
457
        self.run_simple(format='2a')
 
458
 
 
459
 
 
460
class GitApplyTests(ExternalBase):
 
461
 
 
462
    def test_apply(self):
 
463
        b = self.make_branch_and_tree('.')
 
464
 
 
465
        with open('foo.patch', 'w') as f:
 
466
            f.write("""\
 
467
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
 
468
From: Dmitry Bogatov <KAction@debian.org>
 
469
Date: Fri, 8 Feb 2019 23:28:30 +0000
 
470
Subject: [PATCH] Add fixed for out-of-date-standards-version
 
471
 
 
472
---
 
473
 message           | 3 +++
 
474
 1 files changed, 14 insertions(+)
 
475
 create mode 100644 message
 
476
 
 
477
diff --git a/message b/message
 
478
new file mode 100644
 
479
index 0000000..05ec0b1
 
480
--- /dev/null
 
481
+++ b/message
 
482
@@ -0,0 +1,3 @@
 
483
+Update standards version, no changes needed.
 
484
+Certainty: certain
 
485
+Fixed-Lintian-Tags: out-of-date-standards-version
 
486
""")
 
487
        output, error = self.run_bzr('git-apply foo.patch')
 
488
        self.assertContainsRe(
 
489
            error,
 
490
            'Committing to: .*\n'
 
491
            'Committed revision 1.\n')