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 __future__ import absolute_import
22
from dulwich.repo import (
28
from ...controldir import (
32
from ...tests.blackbox import ExternalBase
33
from ...workingtree import WorkingTree
38
from ...tests.script import TestCaseWithTransportAndScript
39
from ...tests.features import PluginLoadedFeature
42
class TestGitBlackBox(ExternalBase):
44
def simple_commit(self):
45
# Create a git repository with a revision.
46
repo = GitRepo.init(self.test_dir)
47
builder = tests.GitBranchBuilder()
48
builder.set_file('a', b'text for a\n', False)
49
r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
50
return repo, builder.finish()[r1]
53
r = GitRepo.init(self.test_dir)
54
dir = ControlDir.open(self.test_dir)
56
self.build_tree(['a', 'b'])
57
output, error = self.run_bzr(['add', 'a'])
58
self.assertEqual('adding a\n', output)
59
self.assertEqual('', error)
60
output, error = self.run_bzr(
61
['add', '--file-ids-from=../othertree', 'b'])
62
self.assertEqual('adding b\n', output)
64
'Ignoring --file-ids-from, since the tree does not support '
65
'setting file ids.\n', error)
68
r = GitRepo.init(self.test_dir)
69
dir = ControlDir.open(self.test_dir)
71
output, error = self.run_bzr(['nick'])
72
self.assertEqual("master\n", output)
74
def test_branches(self):
76
output, error = self.run_bzr(['branches'])
77
self.assertEqual("* master\n", output)
81
output, error = self.run_bzr(['info'])
82
self.assertEqual(error, '')
85
'Standalone tree (format: git)\n'
87
' light checkout root: .\n'
88
' checkout of co-located branch: master\n')
90
def test_ignore(self):
92
output, error = self.run_bzr(['ignore', 'foo'])
93
self.assertEqual(error, '')
94
self.assertEqual(output, '')
95
self.assertFileEqual("foo\n", ".gitignore")
97
def test_cat_revision(self):
99
output, error = self.run_bzr(['cat-revision', '-r-1'], retcode=3)
100
self.assertContainsRe(
102
'brz: ERROR: Repository .* does not support access to raw '
104
self.assertEqual(output, '')
106
def test_branch(self):
107
os.mkdir("gitbranch")
108
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
109
os.chdir('gitbranch')
110
builder = tests.GitBranchBuilder()
111
builder.set_file(b'a', b'text for a\n', False)
112
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
116
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
118
(error == 'Branched 1 revision(s).\n') or
119
(error == 'Branched 1 revision.\n'),
122
def test_checkout(self):
123
os.mkdir("gitbranch")
124
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
125
os.chdir('gitbranch')
126
builder = tests.GitBranchBuilder()
127
builder.set_file(b'a', b'text for a\n', False)
128
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
132
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
133
self.assertEqual(error,
134
'Fetching from Git to Bazaar repository. '
135
'For better performance, fetch into a Git repository.\n')
136
self.assertEqual(output, '')
138
def test_branch_ls(self):
140
output, error = self.run_bzr(['ls', '-r-1'])
141
self.assertEqual(error, '')
142
self.assertEqual(output, "a\n")
145
self.run_bzr("init --format=git repo")
147
def test_info_verbose(self):
150
output, error = self.run_bzr(['info', '-v'])
151
self.assertEqual(error, '')
152
self.assertTrue("Standalone tree (format: git)" in output)
153
self.assertTrue("control: Local Git Repository" in output)
154
self.assertTrue("branch: Local Git Branch" in output)
155
self.assertTrue("repository: Git Repository" in output)
157
def test_push_roundtripping(self):
158
self.knownFailure("roundtripping is not yet supported")
159
self.with_roundtripping()
161
GitRepo.init(os.path.join(self.test_dir, "bla"))
162
self.run_bzr(['init', 'foo'])
163
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
164
# when roundtripping is supported
165
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
166
self.assertEqual(b"", output)
167
self.assertTrue(error.endswith(b"Created new branch.\n"))
169
def test_push_without_calculate_revnos(self):
170
self.run_bzr(['init', '--git', 'bla'])
171
self.run_bzr(['init', '--git', 'foo'])
172
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
173
output, error = self.run_bzr(
174
['push', '-Ocalculate_revnos=no', '-d', 'foo', 'bla'])
175
self.assertEqual("", output)
176
self.assertContainsRe(
178
'Pushed up to revision id git(.*).\n')
180
def test_push_lossy_non_mainline(self):
181
self.run_bzr(['init', '--git', 'bla'])
182
self.run_bzr(['init', 'foo'])
183
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
184
self.run_bzr(['branch', 'foo', 'foo1'])
185
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo1'])
186
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
187
self.run_bzr(['merge', '-d', 'foo', 'foo1'])
188
self.run_bzr(['commit', '--unchanged', '-m', 'merge', 'foo'])
189
output, error = self.run_bzr(['push', '--lossy', '-r1.1.1', '-d', 'foo', 'bla'])
190
self.assertEqual("", output)
192
'Pushing from a Bazaar to a Git repository. For better '
193
'performance, push into a Bazaar repository.\n'
194
'All changes applied successfully.\n'
195
'Pushed up to revision 2.\n', error)
197
def test_push_lossy_non_mainline_incremental(self):
198
self.run_bzr(['init', '--git', 'bla'])
199
self.run_bzr(['init', 'foo'])
200
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
201
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
202
output, error = self.run_bzr(['push', '--lossy', '-d', 'foo', 'bla'])
203
self.assertEqual("", output)
205
'Pushing from a Bazaar to a Git repository. For better '
206
'performance, push into a Bazaar repository.\n'
207
'All changes applied successfully.\n'
208
'Pushed up to revision 2.\n', error)
209
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
210
output, error = self.run_bzr(['push', '--lossy', '-d', 'foo', 'bla'])
211
self.assertEqual("", output)
213
'Pushing from a Bazaar to a Git repository. For better '
214
'performance, push into a Bazaar repository.\n'
215
'All changes applied successfully.\n'
216
'Pushed up to revision 3.\n', error)
219
# Smoke test for "bzr log" in a git repository.
222
# Check that bzr log does not fail and includes the revision.
223
output, error = self.run_bzr(['log'])
224
self.assertEqual(error, '')
226
'<The commit message>' in output,
227
"Commit message was not found in output:\n%s" % (output,))
229
def test_log_verbose(self):
230
# Smoke test for "bzr log -v" in a git repository.
233
# Check that bzr log does not fail and includes the revision.
234
output, error = self.run_bzr(['log', '-v'])
235
self.assertContainsRe(output, 'revno: 1')
237
def test_log_without_revno(self):
238
# Smoke test for "bzr log -v" in a git repository.
241
# Check that bzr log does not fail and includes the revision.
242
output, error = self.run_bzr(['log', '-Ocalculate_revnos=no'])
243
self.assertNotContainsRe(output, 'revno: 1')
245
def test_commit_without_revno(self):
246
repo = GitRepo.init(self.test_dir)
247
output, error = self.run_bzr(
248
['commit', '-Ocalculate_revnos=yes', '--unchanged', '-m', 'one'])
249
self.assertContainsRe(error, 'Committed revision 1.')
250
output, error = self.run_bzr(
251
['commit', '-Ocalculate_revnos=no', '--unchanged', '-m', 'two'])
252
self.assertNotContainsRe(error, 'Committed revision 2.')
253
self.assertContainsRe(error, 'Committed revid .*.')
255
def test_log_file(self):
256
# Smoke test for "bzr log" in a git repository.
257
repo = GitRepo.init(self.test_dir)
258
builder = tests.GitBranchBuilder()
259
builder.set_file('a', b'text for a\n', False)
260
r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'First')
261
builder.set_file('a', b'text 3a for a\n', False)
262
r2a = builder.commit(b'Joe Foo <joe@foo.com>', u'Second a', base=r1)
263
builder.set_file('a', b'text 3b for a\n', False)
264
r2b = builder.commit(b'Joe Foo <joe@foo.com>', u'Second b', base=r1)
265
builder.set_file('a', b'text 4 for a\n', False)
266
builder.commit(b'Joe Foo <joe@foo.com>', u'Third', merge=[r2a], base=r2b)
269
# Check that bzr log does not fail and includes the revision.
270
output, error = self.run_bzr(['log', '-n2', 'a'])
271
self.assertEqual(error, '')
272
self.assertIn('Second a', output)
273
self.assertIn('Second b', output)
274
self.assertIn('First', output)
275
self.assertIn('Third', output)
278
git_repo, commit_sha1 = self.simple_commit()
279
git_repo.refs[b"refs/tags/foo"] = commit_sha1
281
output, error = self.run_bzr(['tags'])
282
self.assertEqual(error, '')
283
self.assertEqual(output, "foo 1\n")
288
output, error = self.run_bzr(["tag", "bar"])
290
# bzr <= 2.2 emits this message in the output stream
291
# bzr => 2.3 emits this message in the error stream
292
self.assertEqual(error + output, 'Created tag bar.\n')
294
def test_init_repo(self):
295
output, error = self.run_bzr(["init", "--format=git", "bla.git"])
296
self.assertEqual(error, '')
297
self.assertEqual(output, 'Created a standalone tree (format: git)\n')
299
def test_diff_format(self):
300
tree = self.make_branch_and_tree('.')
301
self.build_tree(['a'])
303
output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
304
self.assertEqual(error, '')
305
# Some older versions of Dulwich (< 0.19.12) formatted diffs slightly
307
from dulwich import __version__ as dulwich_version
308
if dulwich_version < (0, 19, 12):
309
self.assertEqual(output,
310
'diff --git /dev/null b/a\n'
313
'index 0000000..c197bd8 100644\n'
319
self.assertEqual(output,
320
'diff --git a/a b/a\n'
322
'new file mode 100644\n'
323
'index 0000000..c197bd8 100644\n'
329
def test_git_import_uncolocated(self):
330
r = GitRepo.init("a", mkdir=True)
331
self.build_tree(["a/file"])
333
r.do_commit(ref=b"refs/heads/abranch",
334
committer=b"Joe <joe@example.com>", message=b"Dummy")
335
r.do_commit(ref=b"refs/heads/bbranch",
336
committer=b"Joe <joe@example.com>", message=b"Dummy")
337
self.run_bzr(["git-import", "a", "b"])
339
set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
341
def test_git_import(self):
342
r = GitRepo.init("a", mkdir=True)
343
self.build_tree(["a/file"])
345
r.do_commit(ref=b"refs/heads/abranch",
346
committer=b"Joe <joe@example.com>", message=b"Dummy")
347
r.do_commit(ref=b"refs/heads/bbranch",
348
committer=b"Joe <joe@example.com>", message=b"Dummy")
349
self.run_bzr(["git-import", "--colocated", "a", "b"])
350
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
351
self.assertEqual(set(["abranch", "bbranch"]),
352
set(ControlDir.open("b").get_branches().keys()))
354
def test_git_import_incremental(self):
355
r = GitRepo.init("a", mkdir=True)
356
self.build_tree(["a/file"])
358
r.do_commit(ref=b"refs/heads/abranch",
359
committer=b"Joe <joe@example.com>", message=b"Dummy")
360
self.run_bzr(["git-import", "--colocated", "a", "b"])
361
self.run_bzr(["git-import", "--colocated", "a", "b"])
362
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
363
b = ControlDir.open("b")
364
self.assertEqual(["abranch"], list(b.get_branches().keys()))
366
def test_git_import_tags(self):
367
r = GitRepo.init("a", mkdir=True)
368
self.build_tree(["a/file"])
370
cid = r.do_commit(ref=b"refs/heads/abranch",
371
committer=b"Joe <joe@example.com>", message=b"Dummy")
372
r[b"refs/tags/atag"] = cid
373
self.run_bzr(["git-import", "--colocated", "a", "b"])
374
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
375
b = ControlDir.open("b")
376
self.assertEqual(["abranch"], list(b.get_branches().keys()))
377
self.assertEqual(["atag"],
378
list(b.open_branch("abranch").tags.get_tag_dict().keys()))
380
def test_git_import_colo(self):
381
r = GitRepo.init("a", mkdir=True)
382
self.build_tree(["a/file"])
384
r.do_commit(ref=b"refs/heads/abranch",
385
committer=b"Joe <joe@example.com>", message=b"Dummy")
386
r.do_commit(ref=b"refs/heads/bbranch",
387
committer=b"Joe <joe@example.com>", message=b"Dummy")
388
self.make_controldir("b", format="development-colo")
389
self.run_bzr(["git-import", "--colocated", "a", "b"])
391
set([b.name for b in ControlDir.open("b").list_branches()]),
392
set(["abranch", "bbranch"]))
394
def test_git_refs_from_git(self):
395
r = GitRepo.init("a", mkdir=True)
396
self.build_tree(["a/file"])
398
cid = r.do_commit(ref=b"refs/heads/abranch",
399
committer=b"Joe <joe@example.com>", message=b"Dummy")
400
r[b"refs/tags/atag"] = cid
401
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
402
self.assertEqual(stderr, "")
403
self.assertEqual(stdout,
404
'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
405
'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
407
def test_git_refs_from_bzr(self):
408
tree = self.make_branch_and_tree('a')
409
self.build_tree(["a/file"])
412
committer=b"Joe <joe@example.com>", message=b"Dummy")
413
tree.branch.tags.set_tag("atag", revid)
414
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
415
self.assertEqual(stderr, "")
416
self.assertTrue("refs/tags/atag -> " in stdout)
417
self.assertTrue("HEAD -> " in stdout)
419
def test_check(self):
420
r = GitRepo.init("gitr", mkdir=True)
421
self.build_tree_contents([("gitr/foo", b"hello from git")])
423
r.do_commit(b"message", committer=b"Somebody <user@example.com>")
424
out, err = self.run_bzr(["check", "gitr"])
426
self.assertEqual(out, '')
427
self.assertTrue(err.endswith, '3 objects\n')
430
class ShallowTests(ExternalBase):
433
super(ShallowTests, self).setUp()
434
# Smoke test for "bzr log" in a git repository with shallow depth.
435
self.repo = GitRepo.init('gitr', mkdir=True)
436
self.build_tree_contents([("gitr/foo", b"hello from git")])
437
self.repo.stage("foo")
439
b"message", committer=b"Somebody <user@example.com>",
440
author=b"Somebody <user@example.com>",
441
commit_timestamp=1526330165, commit_timezone=0,
442
author_timestamp=1526330165, author_timezone=0,
443
merge_heads=[b'aa' * 20])
445
def test_log_shallow(self):
446
# Check that bzr log does not fail and includes the revision.
447
output, error = self.run_bzr(['log', 'gitr'], retcode=3)
449
error, 'brz: ERROR: Further revision history missing.\n')
450
self.assertEqual(output,
451
'------------------------------------------------------------\n'
452
'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
453
'git commit: ' + self.repo.head().decode('ascii') + '\n'
454
'committer: Somebody <user@example.com>\n'
455
'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
459
def test_version_info_rio(self):
460
output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
461
self.assertEqual(error, '')
462
self.assertNotIn('revno:', output)
464
def test_version_info_python(self):
465
output, error = self.run_bzr(['version-info', '--python', 'gitr'])
466
self.assertEqual(error, '')
467
self.assertNotIn('revno:', output)
469
def test_version_info_custom_with_revno(self):
470
output, error = self.run_bzr(
471
['version-info', '--custom',
472
'--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
474
error, 'brz: ERROR: Variable {revno} is not available.\n')
475
self.assertEqual(output, 'VERSION_INFO r')
477
def test_version_info_custom_without_revno(self):
478
output, error = self.run_bzr(
479
['version-info', '--custom', '--template=VERSION_INFO \n',
481
self.assertEqual(error, '')
482
self.assertEqual(output, 'VERSION_INFO \n')
485
class SwitchTests(ExternalBase):
487
def test_switch_branch(self):
488
# Create a git repository with a revision.
489
repo = GitRepo.init(self.test_dir)
490
builder = tests.GitBranchBuilder()
491
builder.set_branch(b'refs/heads/oldbranch')
492
builder.set_file('a', b'text for a\n', False)
493
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
494
builder.set_branch(b'refs/heads/newbranch')
496
builder.set_file('a', b'text for new a\n', False)
497
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
500
repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
504
output, error = self.run_bzr('switch oldbranch')
505
self.assertEqual(output, '')
506
self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
508
self.assertFileEqual("text for a\n", 'a')
509
tree = WorkingTree.open('.')
510
with tree.lock_read():
511
basis_tree = tree.basis_tree()
512
with basis_tree.lock_read():
513
self.assertEqual([], list(tree.iter_changes(basis_tree)))
515
def test_branch_with_nested_trees(self):
516
orig = self.make_branch_and_tree('source', format='git')
517
subtree = self.make_branch_and_tree('source/subtree', format='git')
518
self.build_tree(['source/subtree/a'])
519
self.build_tree_contents([('source/.gitmodules', """\
520
[submodule "subtree"]
523
""" % subtree.user_url)])
525
subtree.commit('add subtree contents')
526
orig.add_reference(subtree)
527
orig.add(['.gitmodules'])
528
orig.commit('add subtree')
530
self.run_bzr('branch source target')
532
target = WorkingTree.open('target')
533
target_subtree = WorkingTree.open('target/subtree')
534
self.assertTreesEqual(orig, target)
535
self.assertTreesEqual(subtree, target_subtree)
538
class SwitchScriptTests(TestCaseWithTransportAndScript):
540
def test_switch_preserves(self):
541
# See https://bugs.launchpad.net/brz/+bug/1820606
544
Created a standalone tree (format: git)
546
$ echo original > file.txt
549
$ brz ci -q -m "Initial"
550
$ echo "entered on master branch" > file.txt
554
$ brz switch -b other
555
2>Tree is up to date at revision 1.
556
2>Switched to branch other
558
entered on master branch
562
class GrepTests(ExternalBase):
564
def test_simple_grep(self):
565
tree = self.make_branch_and_tree('.', format='git')
566
self.build_tree_contents([('a', 'text for a\n')])
568
output, error = self.run_bzr('grep text')
569
self.assertEqual(output, 'a:text for a\n')
570
self.assertEqual(error, '')
573
class ReconcileTests(ExternalBase):
575
def test_simple_reconcile(self):
576
tree = self.make_branch_and_tree('.', format='git')
577
self.build_tree_contents([('a', 'text for a\n')])
579
output, error = self.run_bzr('reconcile')
580
self.assertContainsRe(
582
'Reconciling branch file://.*\n'
583
'Reconciling repository file://.*\n'
584
'Reconciliation complete.\n')
585
self.assertEqual(error, '')
588
class StatusTests(ExternalBase):
590
def test_empty_dir(self):
591
tree = self.make_branch_and_tree('.', format='git')
592
self.build_tree(['a/', 'a/foo'])
593
self.build_tree_contents([('.gitignore', 'foo\n')])
594
tree.add(['.gitignore'])
595
tree.commit('add ignore')
596
output, error = self.run_bzr('st')
597
self.assertEqual(output, '')
598
self.assertEqual(error, '')
601
class StatsTests(ExternalBase):
603
def test_simple_stats(self):
604
self.requireFeature(PluginLoadedFeature('stats'))
605
tree = self.make_branch_and_tree('.', format='git')
606
self.build_tree_contents([('a', 'text for a\n')])
608
tree.commit('a commit', committer='Somebody <somebody@example.com>')
609
output, error = self.run_bzr('stats')
610
self.assertEqual(output, ' 1 Somebody <somebody@example.com>\n')
613
class GitObjectsTests(ExternalBase):
615
def run_simple(self, format):
616
tree = self.make_branch_and_tree('.', format=format)
617
self.build_tree(['a/', 'a/foo'])
620
output, error = self.run_bzr('git-objects')
621
shas = list(output.splitlines())
622
self.assertEqual([40, 40], [len(s) for s in shas])
623
self.assertEqual(error, '')
625
output, error = self.run_bzr('git-object %s' % shas[0])
626
self.assertEqual('', error)
628
def test_in_native(self):
629
self.run_simple(format='git')
631
def test_in_bzr(self):
632
self.run_simple(format='2a')
635
class GitApplyTests(ExternalBase):
637
def test_apply(self):
638
b = self.make_branch_and_tree('.')
640
with open('foo.patch', 'w') as f:
642
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
643
From: Dmitry Bogatov <KAction@debian.org>
644
Date: Fri, 8 Feb 2019 23:28:30 +0000
645
Subject: [PATCH] Add fixed for out-of-date-standards-version
649
1 files changed, 14 insertions(+)
650
create mode 100644 message
652
diff --git a/message b/message
654
index 0000000..05ec0b1
658
+Update standards version, no changes needed.
660
+Fixed-Lintian-Tags: out-of-date-standards-version
662
output, error = self.run_bzr('git-apply foo.patch')
663
self.assertContainsRe(
665
'Committing to: .*\n'
666
'Committed revision 1.\n')