13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
"""Black-box tests for bzr-git."""
20
from __future__ import absolute_import
22
from dulwich.repo import (
21
from bzrlib.tests import KnownFailure
22
from bzrlib.tests.blackbox import ExternalBase
24
from bzrlib.plugins.git import (
28
from ...controldir import (
32
from ...tests.blackbox import ExternalBase
33
from ...workingtree import WorkingTree
38
from ...tests.features import PluginLoadedFeature
29
41
class TestGitBlackBox(ExternalBase):
31
43
def simple_commit(self):
32
44
# Create a git repository with a revision.
45
repo = GitRepo.init(self.test_dir)
34
46
builder = tests.GitBranchBuilder()
35
builder.set_file('a', 'text for a\n', False)
36
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
47
builder.set_file('a', b'text for a\n', False)
48
r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
49
return repo, builder.finish()[r1]
52
r = GitRepo.init(self.test_dir)
53
dir = ControlDir.open(self.test_dir)
55
output, error = self.run_bzr(['nick'])
56
self.assertEqual("master\n", output)
58
def test_branches(self):
60
output, error = self.run_bzr(['branches'])
61
self.assertEqual("* master\n", output)
39
63
def test_info(self):
40
64
self.simple_commit()
41
65
output, error = self.run_bzr(['info'])
42
66
self.assertEqual(error, '')
43
self.assertTrue("Repository tree (format: git)" in output)
69
'Standalone tree (format: git)\n'
71
' light checkout root: .\n'
72
' checkout of co-located branch: master\n')
74
def test_ignore(self):
76
output, error = self.run_bzr(['ignore', 'foo'])
77
self.assertEqual(error, '')
78
self.assertEqual(output, '')
79
self.assertFileEqual("foo\n", ".gitignore")
81
def test_cat_revision(self):
83
output, error = self.run_bzr(['cat-revision', '-r-1'], retcode=3)
84
self.assertContainsRe(
86
'brz: ERROR: Repository .* does not support access to raw '
88
self.assertEqual(output, '')
45
90
def test_branch(self):
46
91
os.mkdir("gitbranch")
92
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
49
94
builder = tests.GitBranchBuilder()
50
builder.set_file('a', 'text for a\n', False)
51
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
95
builder.set_file(b'a', b'text for a\n', False)
96
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
55
100
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
56
self.assertEqual(error, 'Branched 1 revision(s).\n')
102
(error == 'Branched 1 revision(s).\n') or
103
(error == 'Branched 1 revision.\n'),
106
def test_checkout(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(['checkout', 'gitbranch', 'bzrbranch'])
117
self.assertEqual(error,
118
'Fetching from Git to Bazaar repository. '
119
'For better performance, fetch into a Git repository.\n')
57
120
self.assertEqual(output, '')
59
122
def test_branch_ls(self):
63
126
self.assertEqual(output, "a\n")
65
128
def test_init(self):
66
self.run_bzr("init-repo --git repo")
129
self.run_bzr("init --format=git repo")
68
131
def test_info_verbose(self):
69
132
self.simple_commit()
71
134
output, error = self.run_bzr(['info', '-v'])
72
135
self.assertEqual(error, '')
73
self.assertTrue("Repository tree (format: git)" in output)
136
self.assertTrue("Standalone tree (format: git)" in output)
74
137
self.assertTrue("control: Local Git Repository" in output)
75
self.assertTrue("branch: Git Branch" in output)
138
self.assertTrue("branch: Local Git Branch" in output)
76
139
self.assertTrue("repository: Git Repository" in output)
141
def test_push_roundtripping(self):
142
self.knownFailure("roundtripping is not yet supported")
143
self.with_roundtripping()
145
GitRepo.init(os.path.join(self.test_dir, "bla"))
146
self.run_bzr(['init', 'foo'])
147
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
148
# when roundtripping is supported
149
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
150
self.assertEqual(b"", output)
151
self.assertTrue(error.endswith(b"Created new branch.\n"))
153
def test_push_lossy_non_mainline(self):
154
self.run_bzr(['init', '--git', 'bla'])
155
self.run_bzr(['init', 'foo'])
156
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
157
self.run_bzr(['branch', 'foo', 'foo1'])
158
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo1'])
159
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
160
self.run_bzr(['merge', '-d', 'foo', 'foo1'])
161
self.run_bzr(['commit', '--unchanged', '-m', 'merge', 'foo'])
162
output, error = self.run_bzr(['push', '--lossy', '-r1.1.1', '-d', 'foo', 'bla'])
163
self.assertEqual("", output)
165
'Pushing from a Bazaar to a Git repository. For better '
166
'performance, push into a Bazaar repository.\n'
167
'Pushed up to revision 2.\n', error)
78
169
def test_log(self):
79
170
# Smoke test for "bzr log" in a git repository.
80
171
self.simple_commit()
93
184
# Check that bzr log does not fail and includes the revision.
94
185
output, error = self.run_bzr(['log', '-v'])
96
187
def test_tags(self):
99
tests.run_git("tag", "foo")
188
git_repo, commit_sha1 = self.simple_commit()
189
git_repo.refs[b"refs/tags/foo"] = commit_sha1
101
191
output, error = self.run_bzr(['tags'])
102
self.assertEquals(error, '')
103
self.assertEquals(output, "foo 1\n")
192
self.assertEqual(error, '')
193
self.assertEqual(output, "foo 1\n")
105
195
def test_tag(self):
106
raise KnownFailure("setting tags not supported by git-python yet")
107
196
self.simple_commit()
109
198
output, error = self.run_bzr(["tag", "bar"])
111
self.assertEquals(error, '')
112
self.assertEquals(output, '')
200
# bzr <= 2.2 emits this message in the output stream
201
# bzr => 2.3 emits this message in the error stream
202
self.assertEqual(error + output, 'Created tag bar.\n')
204
def test_init_repo(self):
205
output, error = self.run_bzr(["init", "--format=git", "bla.git"])
206
self.assertEqual(error, '')
207
self.assertEqual(output, 'Created a standalone tree (format: git)\n')
209
def test_diff_format(self):
210
tree = self.make_branch_and_tree('.')
211
self.build_tree(['a'])
213
output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
214
self.assertEqual(error, '')
215
self.assertEqual(output,
216
'diff --git a/a b/a\n'
218
'new file mode 100644\n'
219
'index 0000000..c197bd8 100644\n'
225
def test_git_import_uncolocated(self):
226
r = GitRepo.init("a", mkdir=True)
227
self.build_tree(["a/file"])
229
r.do_commit(ref=b"refs/heads/abranch",
230
committer=b"Joe <joe@example.com>", message=b"Dummy")
231
r.do_commit(ref=b"refs/heads/bbranch",
232
committer=b"Joe <joe@example.com>", message=b"Dummy")
233
self.run_bzr(["git-import", "a", "b"])
235
set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
237
def test_git_import(self):
238
r = GitRepo.init("a", mkdir=True)
239
self.build_tree(["a/file"])
241
r.do_commit(ref=b"refs/heads/abranch",
242
committer=b"Joe <joe@example.com>", message=b"Dummy")
243
r.do_commit(ref=b"refs/heads/bbranch",
244
committer=b"Joe <joe@example.com>", message=b"Dummy")
245
self.run_bzr(["git-import", "--colocated", "a", "b"])
246
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
247
self.assertEqual(set(["abranch", "bbranch"]),
248
set(ControlDir.open("b").get_branches().keys()))
250
def test_git_import_incremental(self):
251
r = GitRepo.init("a", mkdir=True)
252
self.build_tree(["a/file"])
254
r.do_commit(ref=b"refs/heads/abranch",
255
committer=b"Joe <joe@example.com>", message=b"Dummy")
256
self.run_bzr(["git-import", "--colocated", "a", "b"])
257
self.run_bzr(["git-import", "--colocated", "a", "b"])
258
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
259
b = ControlDir.open("b")
260
self.assertEqual(["abranch"], list(b.get_branches().keys()))
262
def test_git_import_tags(self):
263
r = GitRepo.init("a", mkdir=True)
264
self.build_tree(["a/file"])
266
cid = r.do_commit(ref=b"refs/heads/abranch",
267
committer=b"Joe <joe@example.com>", message=b"Dummy")
268
r[b"refs/tags/atag"] = cid
269
self.run_bzr(["git-import", "--colocated", "a", "b"])
270
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
271
b = ControlDir.open("b")
272
self.assertEqual(["abranch"], list(b.get_branches().keys()))
273
self.assertEqual(["atag"],
274
list(b.open_branch("abranch").tags.get_tag_dict().keys()))
276
def test_git_import_colo(self):
277
r = GitRepo.init("a", mkdir=True)
278
self.build_tree(["a/file"])
280
r.do_commit(ref=b"refs/heads/abranch",
281
committer=b"Joe <joe@example.com>", message=b"Dummy")
282
r.do_commit(ref=b"refs/heads/bbranch",
283
committer=b"Joe <joe@example.com>", message=b"Dummy")
284
self.make_controldir("b", format="development-colo")
285
self.run_bzr(["git-import", "--colocated", "a", "b"])
287
set([b.name for b in ControlDir.open("b").list_branches()]),
288
set(["abranch", "bbranch"]))
290
def test_git_refs_from_git(self):
291
r = GitRepo.init("a", mkdir=True)
292
self.build_tree(["a/file"])
294
cid = r.do_commit(ref=b"refs/heads/abranch",
295
committer=b"Joe <joe@example.com>", message=b"Dummy")
296
r[b"refs/tags/atag"] = cid
297
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
298
self.assertEqual(stderr, "")
299
self.assertEqual(stdout,
300
'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
301
'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
303
def test_git_refs_from_bzr(self):
304
tree = self.make_branch_and_tree('a')
305
self.build_tree(["a/file"])
308
committer=b"Joe <joe@example.com>", message=b"Dummy")
309
tree.branch.tags.set_tag("atag", revid)
310
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
311
self.assertEqual(stderr, "")
312
self.assertTrue("refs/tags/atag -> " in stdout)
313
self.assertTrue("HEAD -> " in stdout)
315
def test_check(self):
316
r = GitRepo.init("gitr", mkdir=True)
317
self.build_tree_contents([("gitr/foo", b"hello from git")])
319
r.do_commit(b"message", committer=b"Somebody <user@example.com>")
320
out, err = self.run_bzr(["check", "gitr"])
322
self.assertEqual(out, '')
323
self.assertTrue(err.endswith, '3 objects\n')
326
class ShallowTests(ExternalBase):
329
super(ShallowTests, self).setUp()
330
# Smoke test for "bzr log" in a git repository with shallow depth.
331
self.repo = GitRepo.init('gitr', mkdir=True)
332
self.build_tree_contents([("gitr/foo", b"hello from git")])
333
self.repo.stage("foo")
335
b"message", committer=b"Somebody <user@example.com>",
336
author=b"Somebody <user@example.com>",
337
commit_timestamp=1526330165, commit_timezone=0,
338
author_timestamp=1526330165, author_timezone=0,
339
merge_heads=[b'aa' * 20])
341
def test_log_shallow(self):
342
# Check that bzr log does not fail and includes the revision.
343
output, error = self.run_bzr(['log', 'gitr'], retcode=3)
345
error, 'brz: ERROR: Further revision history missing.\n')
346
self.assertEqual(output,
347
'------------------------------------------------------------\n'
348
'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
349
'git commit: ' + self.repo.head().decode('ascii') + '\n'
350
'committer: Somebody <user@example.com>\n'
351
'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
355
def test_version_info_rio(self):
356
output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
357
self.assertEqual(error, '')
358
self.assertNotIn('revno:', output)
360
def test_version_info_python(self):
361
output, error = self.run_bzr(['version-info', '--python', 'gitr'])
362
self.assertEqual(error, '')
363
self.assertNotIn('revno:', output)
365
def test_version_info_custom_with_revno(self):
366
output, error = self.run_bzr(
367
['version-info', '--custom',
368
'--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
370
error, 'brz: ERROR: Variable {revno} is not available.\n')
371
self.assertEqual(output, 'VERSION_INFO r')
373
def test_version_info_custom_without_revno(self):
374
output, error = self.run_bzr(
375
['version-info', '--custom', '--template=VERSION_INFO \n',
377
self.assertEqual(error, '')
378
self.assertEqual(output, 'VERSION_INFO \n')
381
class SwitchTests(ExternalBase):
383
def test_switch_branch(self):
384
# Create a git repository with a revision.
385
repo = GitRepo.init(self.test_dir)
386
builder = tests.GitBranchBuilder()
387
builder.set_branch(b'refs/heads/oldbranch')
388
builder.set_file('a', b'text for a\n', False)
389
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
390
builder.set_branch(b'refs/heads/newbranch')
392
builder.set_file('a', b'text for new a\n', False)
393
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
396
repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
400
output, error = self.run_bzr('switch oldbranch')
401
self.assertEqual(output, '')
402
self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
404
self.assertFileEqual("text for a\n", 'a')
405
tree = WorkingTree.open('.')
406
with tree.lock_read():
407
basis_tree = tree.basis_tree()
408
with basis_tree.lock_read():
409
self.assertEqual([], list(tree.iter_changes(basis_tree)))
412
class GrepTests(ExternalBase):
414
def test_simple_grep(self):
415
tree = self.make_branch_and_tree('.', format='git')
416
self.build_tree_contents([('a', 'text for a\n')])
418
output, error = self.run_bzr('grep text')
419
self.assertEqual(output, 'a:text for a\n')
420
self.assertEqual(error, '')
423
class ReconcileTests(ExternalBase):
425
def test_simple_reconcile(self):
426
tree = self.make_branch_and_tree('.', format='git')
427
self.build_tree_contents([('a', 'text for a\n')])
429
output, error = self.run_bzr('reconcile')
430
self.assertContainsRe(
432
'Reconciling branch file://.*\n'
433
'Reconciling repository file://.*\n'
434
'Reconciliation complete.\n')
435
self.assertEqual(error, '')
438
class StatusTests(ExternalBase):
440
def test_empty_dir(self):
441
tree = self.make_branch_and_tree('.', format='git')
442
self.build_tree(['a/', 'a/foo'])
443
self.build_tree_contents([('.gitignore', 'foo\n')])
444
tree.add(['.gitignore'])
445
tree.commit('add ignore')
446
output, error = self.run_bzr('st')
447
self.assertEqual(output, '')
448
self.assertEqual(error, '')
451
class StatsTests(ExternalBase):
453
def test_simple_stats(self):
454
self.requireFeature(PluginLoadedFeature('stats'))
455
tree = self.make_branch_and_tree('.', format='git')
456
self.build_tree_contents([('a', 'text for a\n')])
458
tree.commit('a commit', committer='Somebody <somebody@example.com>')
459
output, error = self.run_bzr('stats')
460
self.assertEqual(output, ' 1 Somebody <somebody@example.com>\n')
463
class GitObjectsTests(ExternalBase):
465
def run_simple(self, format):
466
tree = self.make_branch_and_tree('.', format=format)
467
self.build_tree(['a/', 'a/foo'])
470
output, error = self.run_bzr('git-objects')
471
shas = list(output.splitlines())
472
self.assertEqual([40, 40], [len(s) for s in shas])
473
self.assertEqual(error, '')
475
output, error = self.run_bzr('git-object %s' % shas[0])
476
self.assertEqual('', error)
478
def test_in_native(self):
479
self.run_simple(format='git')
481
def test_in_bzr(self):
482
self.run_simple(format='2a')
485
class GitApplyTests(ExternalBase):
487
def test_apply(self):
488
b = self.make_branch_and_tree('.')
490
with open('foo.patch', 'w') as f:
492
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
493
From: Dmitry Bogatov <KAction@debian.org>
494
Date: Fri, 8 Feb 2019 23:28:30 +0000
495
Subject: [PATCH] Add fixed for out-of-date-standards-version
499
1 files changed, 14 insertions(+)
500
create mode 100644 message
502
diff --git a/message b/message
504
index 0000000..05ec0b1
508
+Update standards version, no changes needed.
510
+Fixed-Lintian-Tags: out-of-date-standards-version
512
output, error = self.run_bzr('git-apply foo.patch')
513
self.assertContainsRe(
515
'Committing to: .*\n'
516
'Committed revision 1.\n')