1
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
2
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for bzr-git."""
20
from dulwich.repo import (
26
from ...controldir import (
30
from ...tests.blackbox import ExternalBase
31
from ...workingtree import WorkingTree
36
from ...tests.script import TestCaseWithTransportAndScript
37
from ...tests.features import PluginLoadedFeature
40
class TestGitBlackBox(ExternalBase):
42
def simple_commit(self):
43
# Create a git repository with a revision.
44
repo = GitRepo.init(self.test_dir)
45
builder = tests.GitBranchBuilder()
46
builder.set_file('a', b'text for a\n', False)
47
r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
48
return repo, builder.finish()[r1]
51
r = GitRepo.init(self.test_dir)
52
dir = ControlDir.open(self.test_dir)
54
self.build_tree(['a', 'b'])
55
output, error = self.run_bzr(['add', 'a'])
56
self.assertEqual('adding a\n', output)
57
self.assertEqual('', error)
58
output, error = self.run_bzr(
59
['add', '--file-ids-from=../othertree', 'b'])
60
self.assertEqual('adding b\n', output)
62
'Ignoring --file-ids-from, since the tree does not support '
63
'setting file ids.\n', error)
66
r = GitRepo.init(self.test_dir)
67
dir = ControlDir.open(self.test_dir)
69
output, error = self.run_bzr(['nick'])
70
self.assertEqual("master\n", output)
72
def test_branches(self):
74
output, error = self.run_bzr(['branches'])
75
self.assertEqual("* master\n", output)
79
output, error = self.run_bzr(['info'])
80
self.assertEqual(error, '')
83
'Standalone tree (format: git)\n'
85
' light checkout root: .\n'
86
' checkout of co-located branch: master\n')
88
def test_ignore(self):
90
output, error = self.run_bzr(['ignore', 'foo'])
91
self.assertEqual(error, '')
92
self.assertEqual(output, '')
93
self.assertFileEqual("foo\n", ".gitignore")
95
def test_cat_revision(self):
97
output, error = self.run_bzr(['cat-revision', '-r-1'], retcode=3)
98
self.assertContainsRe(
100
'brz: ERROR: Repository .* does not support access to raw '
102
self.assertEqual(output, '')
104
def test_branch(self):
105
os.mkdir("gitbranch")
106
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
107
os.chdir('gitbranch')
108
builder = tests.GitBranchBuilder()
109
builder.set_file(b'a', b'text for a\n', False)
110
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
114
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
116
(error == 'Branched 1 revision(s).\n') or
117
(error == 'Branched 1 revision.\n'),
120
def test_checkout(self):
121
os.mkdir("gitbranch")
122
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
123
os.chdir('gitbranch')
124
builder = tests.GitBranchBuilder()
125
builder.set_file(b'a', b'text for a\n', False)
126
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
130
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
131
self.assertEqual(error,
132
'Fetching from Git to Bazaar repository. '
133
'For better performance, fetch into a Git repository.\n')
134
self.assertEqual(output, '')
136
def test_branch_ls(self):
138
output, error = self.run_bzr(['ls', '-r-1'])
139
self.assertEqual(error, '')
140
self.assertEqual(output, "a\n")
143
self.run_bzr("init --format=git repo")
145
def test_info_verbose(self):
148
output, error = self.run_bzr(['info', '-v'])
149
self.assertEqual(error, '')
150
self.assertTrue("Standalone tree (format: git)" in output)
151
self.assertTrue("control: Local Git Repository" in output)
152
self.assertTrue("branch: Local Git Branch" in output)
153
self.assertTrue("repository: Git Repository" in output)
155
def test_push_roundtripping(self):
156
self.knownFailure("roundtripping is not yet supported")
157
self.with_roundtripping()
159
GitRepo.init(os.path.join(self.test_dir, "bla"))
160
self.run_bzr(['init', 'foo'])
161
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
162
# when roundtripping is supported
163
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
164
self.assertEqual(b"", output)
165
self.assertTrue(error.endswith(b"Created new branch.\n"))
167
def test_push_without_calculate_revnos(self):
168
self.run_bzr(['init', '--git', 'bla'])
169
self.run_bzr(['init', '--git', 'foo'])
170
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
171
output, error = self.run_bzr(
172
['push', '-Ocalculate_revnos=no', '-d', 'foo', 'bla'])
173
self.assertEqual("", output)
174
self.assertContainsRe(
176
'Pushed up to revision id git(.*).\n')
178
def test_push_lossy_non_mainline(self):
179
self.run_bzr(['init', '--git', 'bla'])
180
self.run_bzr(['init', 'foo'])
181
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
182
self.run_bzr(['branch', 'foo', 'foo1'])
183
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo1'])
184
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
185
self.run_bzr(['merge', '-d', 'foo', 'foo1'])
186
self.run_bzr(['commit', '--unchanged', '-m', 'merge', 'foo'])
187
output, error = self.run_bzr(['push', '--lossy', '-r1.1.1', '-d', 'foo', 'bla'])
188
self.assertEqual("", output)
190
'Pushing from a Bazaar to a Git repository. For better '
191
'performance, push into a Bazaar repository.\n'
192
'All changes applied successfully.\n'
193
'Pushed up to revision 2.\n', error)
195
def test_push_lossy_non_mainline_incremental(self):
196
self.run_bzr(['init', '--git', 'bla'])
197
self.run_bzr(['init', 'foo'])
198
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
199
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
200
output, error = self.run_bzr(['push', '--lossy', '-d', 'foo', 'bla'])
201
self.assertEqual("", output)
203
'Pushing from a Bazaar to a Git repository. For better '
204
'performance, push into a Bazaar repository.\n'
205
'All changes applied successfully.\n'
206
'Pushed up to revision 2.\n', error)
207
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
208
output, error = self.run_bzr(['push', '--lossy', '-d', 'foo', 'bla'])
209
self.assertEqual("", output)
211
'Pushing from a Bazaar to a Git repository. For better '
212
'performance, push into a Bazaar repository.\n'
213
'All changes applied successfully.\n'
214
'Pushed up to revision 3.\n', error)
217
# Smoke test for "bzr log" in a git repository.
220
# Check that bzr log does not fail and includes the revision.
221
output, error = self.run_bzr(['log'])
222
self.assertEqual(error, '')
224
'<The commit message>' in output,
225
"Commit message was not found in output:\n%s" % (output,))
227
def test_log_verbose(self):
228
# Smoke test for "bzr log -v" in a git repository.
231
# Check that bzr log does not fail and includes the revision.
232
output, error = self.run_bzr(['log', '-v'])
233
self.assertContainsRe(output, 'revno: 1')
235
def test_log_without_revno(self):
236
# Smoke test for "bzr log -v" in a git repository.
239
# Check that bzr log does not fail and includes the revision.
240
output, error = self.run_bzr(['log', '-Ocalculate_revnos=no'])
241
self.assertNotContainsRe(output, 'revno: 1')
243
def test_commit_without_revno(self):
244
repo = GitRepo.init(self.test_dir)
245
output, error = self.run_bzr(
246
['commit', '-Ocalculate_revnos=yes', '--unchanged', '-m', 'one'])
247
self.assertContainsRe(error, 'Committed revision 1.')
248
output, error = self.run_bzr(
249
['commit', '-Ocalculate_revnos=no', '--unchanged', '-m', 'two'])
250
self.assertNotContainsRe(error, 'Committed revision 2.')
251
self.assertContainsRe(error, 'Committed revid .*.')
253
def test_log_file(self):
254
# Smoke test for "bzr log" in a git repository.
255
repo = GitRepo.init(self.test_dir)
256
builder = tests.GitBranchBuilder()
257
builder.set_file('a', b'text for a\n', False)
258
r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'First')
259
builder.set_file('a', b'text 3a for a\n', False)
260
r2a = builder.commit(b'Joe Foo <joe@foo.com>', u'Second a', base=r1)
261
builder.set_file('a', b'text 3b for a\n', False)
262
r2b = builder.commit(b'Joe Foo <joe@foo.com>', u'Second b', base=r1)
263
builder.set_file('a', b'text 4 for a\n', False)
264
builder.commit(b'Joe Foo <joe@foo.com>', u'Third', merge=[r2a], base=r2b)
267
# Check that bzr log does not fail and includes the revision.
268
output, error = self.run_bzr(['log', '-n2', 'a'])
269
self.assertEqual(error, '')
270
self.assertIn('Second a', output)
271
self.assertIn('Second b', output)
272
self.assertIn('First', output)
273
self.assertIn('Third', output)
276
git_repo, commit_sha1 = self.simple_commit()
277
git_repo.refs[b"refs/tags/foo"] = commit_sha1
279
output, error = self.run_bzr(['tags'])
280
self.assertEqual(error, '')
281
self.assertEqual(output, "foo 1\n")
286
output, error = self.run_bzr(["tag", "bar"])
288
# bzr <= 2.2 emits this message in the output stream
289
# bzr => 2.3 emits this message in the error stream
290
self.assertEqual(error + output, 'Created tag bar.\n')
292
def test_init_repo(self):
293
output, error = self.run_bzr(["init", "--format=git", "bla.git"])
294
self.assertEqual(error, '')
295
self.assertEqual(output, 'Created a standalone tree (format: git)\n')
297
def test_diff_format(self):
298
tree = self.make_branch_and_tree('.')
299
self.build_tree(['a'])
301
output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
302
self.assertEqual(error, '')
303
# Some older versions of Dulwich (< 0.19.12) formatted diffs slightly
305
from dulwich import __version__ as dulwich_version
306
if dulwich_version < (0, 19, 12):
307
self.assertEqual(output,
308
'diff --git /dev/null b/a\n'
311
'index 0000000..c197bd8 100644\n'
317
self.assertEqual(output,
318
'diff --git a/a b/a\n'
320
'new file mode 100644\n'
321
'index 0000000..c197bd8 100644\n'
327
def test_git_import_uncolocated(self):
328
r = GitRepo.init("a", mkdir=True)
329
self.build_tree(["a/file"])
331
r.do_commit(ref=b"refs/heads/abranch",
332
committer=b"Joe <joe@example.com>", message=b"Dummy")
333
r.do_commit(ref=b"refs/heads/bbranch",
334
committer=b"Joe <joe@example.com>", message=b"Dummy")
335
self.run_bzr(["git-import", "a", "b"])
337
set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
339
def test_git_import(self):
340
r = GitRepo.init("a", mkdir=True)
341
self.build_tree(["a/file"])
343
r.do_commit(ref=b"refs/heads/abranch",
344
committer=b"Joe <joe@example.com>", message=b"Dummy")
345
r.do_commit(ref=b"refs/heads/bbranch",
346
committer=b"Joe <joe@example.com>", message=b"Dummy")
347
self.run_bzr(["git-import", "--colocated", "a", "b"])
348
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
349
self.assertEqual(set(["abranch", "bbranch"]),
350
set(ControlDir.open("b").get_branches().keys()))
352
def test_git_import_incremental(self):
353
r = GitRepo.init("a", mkdir=True)
354
self.build_tree(["a/file"])
356
r.do_commit(ref=b"refs/heads/abranch",
357
committer=b"Joe <joe@example.com>", message=b"Dummy")
358
self.run_bzr(["git-import", "--colocated", "a", "b"])
359
self.run_bzr(["git-import", "--colocated", "a", "b"])
360
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
361
b = ControlDir.open("b")
362
self.assertEqual(["abranch"], list(b.get_branches().keys()))
364
def test_git_import_tags(self):
365
r = GitRepo.init("a", mkdir=True)
366
self.build_tree(["a/file"])
368
cid = r.do_commit(ref=b"refs/heads/abranch",
369
committer=b"Joe <joe@example.com>", message=b"Dummy")
370
r[b"refs/tags/atag"] = cid
371
self.run_bzr(["git-import", "--colocated", "a", "b"])
372
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
373
b = ControlDir.open("b")
374
self.assertEqual(["abranch"], list(b.get_branches().keys()))
375
self.assertEqual(["atag"],
376
list(b.open_branch("abranch").tags.get_tag_dict().keys()))
378
def test_git_import_colo(self):
379
r = GitRepo.init("a", mkdir=True)
380
self.build_tree(["a/file"])
382
r.do_commit(ref=b"refs/heads/abranch",
383
committer=b"Joe <joe@example.com>", message=b"Dummy")
384
r.do_commit(ref=b"refs/heads/bbranch",
385
committer=b"Joe <joe@example.com>", message=b"Dummy")
386
self.make_controldir("b", format="development-colo")
387
self.run_bzr(["git-import", "--colocated", "a", "b"])
389
set([b.name for b in ControlDir.open("b").list_branches()]),
390
set(["abranch", "bbranch"]))
392
def test_git_refs_from_git(self):
393
r = GitRepo.init("a", mkdir=True)
394
self.build_tree(["a/file"])
396
cid = r.do_commit(ref=b"refs/heads/abranch",
397
committer=b"Joe <joe@example.com>", message=b"Dummy")
398
r[b"refs/tags/atag"] = cid
399
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
400
self.assertEqual(stderr, "")
401
self.assertEqual(stdout,
402
'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
403
'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
405
def test_git_refs_from_bzr(self):
406
tree = self.make_branch_and_tree('a')
407
self.build_tree(["a/file"])
410
committer=b"Joe <joe@example.com>", message=b"Dummy")
411
tree.branch.tags.set_tag("atag", revid)
412
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
413
self.assertEqual(stderr, "")
414
self.assertTrue("refs/tags/atag -> " in stdout)
415
self.assertTrue("HEAD -> " in stdout)
417
def test_check(self):
418
r = GitRepo.init("gitr", mkdir=True)
419
self.build_tree_contents([("gitr/foo", b"hello from git")])
421
r.do_commit(b"message", committer=b"Somebody <user@example.com>")
422
out, err = self.run_bzr(["check", "gitr"])
424
self.assertEqual(out, '')
425
self.assertTrue(err.endswith, '3 objects\n')
428
class ShallowTests(ExternalBase):
431
super(ShallowTests, self).setUp()
432
# Smoke test for "bzr log" in a git repository with shallow depth.
433
self.repo = GitRepo.init('gitr', mkdir=True)
434
self.build_tree_contents([("gitr/foo", b"hello from git")])
435
self.repo.stage("foo")
437
b"message", committer=b"Somebody <user@example.com>",
438
author=b"Somebody <user@example.com>",
439
commit_timestamp=1526330165, commit_timezone=0,
440
author_timestamp=1526330165, author_timezone=0,
441
merge_heads=[b'aa' * 20])
443
def test_log_shallow(self):
444
# Check that bzr log does not fail and includes the revision.
445
output, error = self.run_bzr(['log', 'gitr'], retcode=3)
447
error, 'brz: ERROR: Further revision history missing.\n')
448
self.assertEqual(output,
449
'------------------------------------------------------------\n'
450
'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
451
'git commit: ' + self.repo.head().decode('ascii') + '\n'
452
'committer: Somebody <user@example.com>\n'
453
'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
457
def test_version_info_rio(self):
458
output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
459
self.assertEqual(error, '')
460
self.assertNotIn('revno:', output)
462
def test_version_info_python(self):
463
output, error = self.run_bzr(['version-info', '--python', 'gitr'])
464
self.assertEqual(error, '')
465
self.assertNotIn('revno:', output)
467
def test_version_info_custom_with_revno(self):
468
output, error = self.run_bzr(
469
['version-info', '--custom',
470
'--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
472
error, 'brz: ERROR: Variable {revno} is not available.\n')
473
self.assertEqual(output, 'VERSION_INFO r')
475
def test_version_info_custom_without_revno(self):
476
output, error = self.run_bzr(
477
['version-info', '--custom', '--template=VERSION_INFO \n',
479
self.assertEqual(error, '')
480
self.assertEqual(output, 'VERSION_INFO \n')
483
class SwitchTests(ExternalBase):
485
def test_switch_branch(self):
486
# Create a git repository with a revision.
487
repo = GitRepo.init(self.test_dir)
488
builder = tests.GitBranchBuilder()
489
builder.set_branch(b'refs/heads/oldbranch')
490
builder.set_file('a', b'text for a\n', False)
491
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
492
builder.set_branch(b'refs/heads/newbranch')
494
builder.set_file('a', b'text for new a\n', False)
495
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
498
repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
502
output, error = self.run_bzr('switch oldbranch')
503
self.assertEqual(output, '')
504
self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
506
self.assertFileEqual("text for a\n", 'a')
507
tree = WorkingTree.open('.')
508
with tree.lock_read():
509
basis_tree = tree.basis_tree()
510
with basis_tree.lock_read():
511
self.assertEqual([], list(tree.iter_changes(basis_tree)))
513
def test_branch_with_nested_trees(self):
514
orig = self.make_branch_and_tree('source', format='git')
515
subtree = self.make_branch_and_tree('source/subtree', format='git')
516
self.build_tree(['source/subtree/a'])
517
self.build_tree_contents([('source/.gitmodules', """\
518
[submodule "subtree"]
521
""" % subtree.user_url)])
523
subtree.commit('add subtree contents')
524
orig.add_reference(subtree)
525
orig.add(['.gitmodules'])
526
orig.commit('add subtree')
528
self.run_bzr('branch source target')
530
target = WorkingTree.open('target')
531
target_subtree = WorkingTree.open('target/subtree')
532
self.assertTreesEqual(orig, target)
533
self.assertTreesEqual(subtree, target_subtree)
536
class SwitchScriptTests(TestCaseWithTransportAndScript):
538
def test_switch_preserves(self):
539
# See https://bugs.launchpad.net/brz/+bug/1820606
542
Created a standalone tree (format: git)
544
$ echo original > file.txt
547
$ brz ci -q -m "Initial"
548
$ echo "entered on master branch" > file.txt
552
$ brz switch -b other
553
2>Tree is up to date at revision 1.
554
2>Switched to branch other
556
entered on master branch
560
class GrepTests(ExternalBase):
562
def test_simple_grep(self):
563
tree = self.make_branch_and_tree('.', format='git')
564
self.build_tree_contents([('a', 'text for a\n')])
566
output, error = self.run_bzr('grep text')
567
self.assertEqual(output, 'a:text for a\n')
568
self.assertEqual(error, '')
571
class ReconcileTests(ExternalBase):
573
def test_simple_reconcile(self):
574
tree = self.make_branch_and_tree('.', format='git')
575
self.build_tree_contents([('a', 'text for a\n')])
577
output, error = self.run_bzr('reconcile')
578
self.assertContainsRe(
580
'Reconciling branch file://.*\n'
581
'Reconciling repository file://.*\n'
582
'Reconciliation complete.\n')
583
self.assertEqual(error, '')
586
class StatusTests(ExternalBase):
588
def test_empty_dir(self):
589
tree = self.make_branch_and_tree('.', format='git')
590
self.build_tree(['a/', 'a/foo'])
591
self.build_tree_contents([('.gitignore', 'foo\n')])
592
tree.add(['.gitignore'])
593
tree.commit('add ignore')
594
output, error = self.run_bzr('st')
595
self.assertEqual(output, '')
596
self.assertEqual(error, '')
599
class StatsTests(ExternalBase):
601
def test_simple_stats(self):
602
self.requireFeature(PluginLoadedFeature('stats'))
603
tree = self.make_branch_and_tree('.', format='git')
604
self.build_tree_contents([('a', 'text for a\n')])
606
tree.commit('a commit', committer='Somebody <somebody@example.com>')
607
output, error = self.run_bzr('stats')
608
self.assertEqual(output, ' 1 Somebody <somebody@example.com>\n')
611
class GitObjectsTests(ExternalBase):
613
def run_simple(self, format):
614
tree = self.make_branch_and_tree('.', format=format)
615
self.build_tree(['a/', 'a/foo'])
618
output, error = self.run_bzr('git-objects')
619
shas = list(output.splitlines())
620
self.assertEqual([40, 40], [len(s) for s in shas])
621
self.assertEqual(error, '')
623
output, error = self.run_bzr('git-object %s' % shas[0])
624
self.assertEqual('', error)
626
def test_in_native(self):
627
self.run_simple(format='git')
629
def test_in_bzr(self):
630
self.run_simple(format='2a')
633
class GitApplyTests(ExternalBase):
635
def test_apply(self):
636
b = self.make_branch_and_tree('.')
638
with open('foo.patch', 'w') as f:
640
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
641
From: Dmitry Bogatov <KAction@debian.org>
642
Date: Fri, 8 Feb 2019 23:28:30 +0000
643
Subject: [PATCH] Add fixed for out-of-date-standards-version
647
1 files changed, 14 insertions(+)
648
create mode 100644 message
650
diff --git a/message b/message
652
index 0000000..05ec0b1
656
+Update standards version, no changes needed.
658
+Fixed-Lintian-Tags: out-of-date-standards-version
660
output, error = self.run_bzr('git-apply foo.patch')
661
self.assertContainsRe(
663
'Committing to: .*\n'
664
'Committed revision 1.\n')