31
41
def simple_commit(self):
32
42
# Create a git repository with a revision.
43
repo = GitRepo.init(self.test_dir)
34
44
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>')
45
builder.set_file('a', b'text for a\n', False)
46
r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
47
return repo, builder.finish()[r1]
50
r = GitRepo.init(self.test_dir)
51
dir = ControlDir.open(self.test_dir)
53
output, error = self.run_bzr(['nick'])
54
self.assertEqual("master\n", output)
56
def test_branches(self):
58
output, error = self.run_bzr(['branches'])
59
self.assertEqual("* master\n", output)
39
61
def test_info(self):
40
62
self.simple_commit()
41
63
output, error = self.run_bzr(['info'])
42
64
self.assertEqual(error, '')
43
self.assertTrue("Repository tree (format: git)" in output)
65
self.assertTrue("Standalone tree (format: git)" in output)
45
67
def test_branch(self):
46
68
os.mkdir("gitbranch")
69
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
49
71
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>')
72
builder.set_file(b'a', b'text for a\n', False)
73
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
55
77
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
56
self.assertEqual(error, 'Branched 1 revision(s).\n')
79
(error == 'Branched 1 revision(s).\n') or
80
(error == 'Branched 1 revision.\n'),
83
def test_checkout(self):
85
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
87
builder = tests.GitBranchBuilder()
88
builder.set_file(b'a', b'text for a\n', False)
89
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
93
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
94
self.assertEqual(error,
95
'Fetching from Git to Bazaar repository. '
96
'For better performance, fetch into a Git repository.\n')
57
97
self.assertEqual(output, '')
59
99
def test_branch_ls(self):
93
145
# Check that bzr log does not fail and includes the revision.
94
146
output, error = self.run_bzr(['log', '-v'])
96
148
def test_tags(self):
99
tests.run_git("tag", "foo")
149
git_repo, commit_sha1 = self.simple_commit()
150
git_repo.refs[b"refs/tags/foo"] = commit_sha1
101
152
output, error = self.run_bzr(['tags'])
102
self.assertEquals(error, '')
103
self.assertEquals(output, "foo 1\n")
153
self.assertEqual(error, '')
154
self.assertEqual(output, "foo 1\n")
105
156
def test_tag(self):
106
raise KnownFailure("setting tags not supported by git-python yet")
107
157
self.simple_commit()
109
159
output, error = self.run_bzr(["tag", "bar"])
111
self.assertEquals(error, '')
112
self.assertEquals(output, '')
161
# bzr <= 2.2 emits this message in the output stream
162
# bzr => 2.3 emits this message in the error stream
163
self.assertEqual(error + output, 'Created tag bar.\n')
165
def test_init_repo(self):
166
output, error = self.run_bzr(["init", "--format=git", "bla.git"])
167
self.assertEqual(error, '')
168
self.assertEqual(output, 'Created a standalone tree (format: git)\n')
170
def test_diff_format(self):
171
tree = self.make_branch_and_tree('.')
172
self.build_tree(['a'])
174
output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
175
self.assertEqual(error, '')
176
self.assertEqual(output,
177
'diff --git /dev/null b/a\n'
180
'index 0000000..c197bd8 100644\n'
186
def test_git_import_uncolocated(self):
187
r = GitRepo.init("a", mkdir=True)
188
self.build_tree(["a/file"])
190
r.do_commit(ref=b"refs/heads/abranch",
191
committer=b"Joe <joe@example.com>", message=b"Dummy")
192
r.do_commit(ref=b"refs/heads/bbranch",
193
committer=b"Joe <joe@example.com>", message=b"Dummy")
194
self.run_bzr(["git-import", "a", "b"])
196
set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
198
def test_git_import(self):
199
r = GitRepo.init("a", mkdir=True)
200
self.build_tree(["a/file"])
202
r.do_commit(ref=b"refs/heads/abranch",
203
committer=b"Joe <joe@example.com>", message=b"Dummy")
204
r.do_commit(ref=b"refs/heads/bbranch",
205
committer=b"Joe <joe@example.com>", message=b"Dummy")
206
self.run_bzr(["git-import", "--colocated", "a", "b"])
207
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
208
self.assertEqual(set(["abranch", "bbranch"]),
209
set(ControlDir.open("b").get_branches().keys()))
211
def test_git_import_incremental(self):
212
r = GitRepo.init("a", mkdir=True)
213
self.build_tree(["a/file"])
215
r.do_commit(ref=b"refs/heads/abranch",
216
committer=b"Joe <joe@example.com>", message=b"Dummy")
217
self.run_bzr(["git-import", "--colocated", "a", "b"])
218
self.run_bzr(["git-import", "--colocated", "a", "b"])
219
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
220
b = ControlDir.open("b")
221
self.assertEqual(["abranch"], list(b.get_branches().keys()))
223
def test_git_import_tags(self):
224
r = GitRepo.init("a", mkdir=True)
225
self.build_tree(["a/file"])
227
cid = r.do_commit(ref=b"refs/heads/abranch",
228
committer=b"Joe <joe@example.com>", message=b"Dummy")
229
r[b"refs/tags/atag"] = cid
230
self.run_bzr(["git-import", "--colocated", "a", "b"])
231
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
232
b = ControlDir.open("b")
233
self.assertEqual(["abranch"], list(b.get_branches().keys()))
234
self.assertEqual(["atag"],
235
list(b.open_branch("abranch").tags.get_tag_dict().keys()))
237
def test_git_import_colo(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.make_controldir("b", format="development-colo")
246
self.run_bzr(["git-import", "--colocated", "a", "b"])
248
set([b.name for b in ControlDir.open("b").list_branches()]),
249
set(["abranch", "bbranch"]))
251
def test_git_refs_from_git(self):
252
r = GitRepo.init("a", mkdir=True)
253
self.build_tree(["a/file"])
255
cid = r.do_commit(ref=b"refs/heads/abranch",
256
committer=b"Joe <joe@example.com>", message=b"Dummy")
257
r[b"refs/tags/atag"] = cid
258
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
259
self.assertEqual(stderr, "")
260
self.assertEqual(stdout,
261
'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
262
'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
264
def test_git_refs_from_bzr(self):
265
tree = self.make_branch_and_tree('a')
266
self.build_tree(["a/file"])
269
committer=b"Joe <joe@example.com>", message=b"Dummy")
270
tree.branch.tags.set_tag("atag", revid)
271
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
272
self.assertEqual(stderr, "")
273
self.assertTrue("refs/tags/atag -> " in stdout)
274
self.assertTrue("HEAD -> " in stdout)
276
def test_check(self):
277
r = GitRepo.init("gitr", mkdir=True)
278
self.build_tree_contents([("gitr/foo", b"hello from git")])
280
r.do_commit(b"message", committer=b"Somebody <user@example.com>")
281
out, err = self.run_bzr(["check", "gitr"])
283
self.assertEqual(out, '')
284
self.assertTrue(err.endswith, '3 objects\n')
287
class ShallowTests(ExternalBase):
290
super(ShallowTests, self).setUp()
291
# Smoke test for "bzr log" in a git repository with shallow depth.
292
self.repo = GitRepo.init('gitr', mkdir=True)
293
self.build_tree_contents([("gitr/foo", b"hello from git")])
294
self.repo.stage("foo")
296
b"message", committer=b"Somebody <user@example.com>",
297
commit_timestamp=1526330165, commit_timezone=0,
298
author_timestamp=1526330165, author_timezone=0,
299
merge_heads=[b'aa' * 20])
301
def test_log_shallow(self):
302
# Check that bzr log does not fail and includes the revision.
303
output, error = self.run_bzr(['log', 'gitr'], retcode=3)
305
error, 'brz: ERROR: Further revision history missing.\n')
306
self.assertEqual(output,
307
'------------------------------------------------------------\n'
308
'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
309
'git commit: ' + self.repo.head().decode('ascii') + '\n'
310
'committer: Somebody <user@example.com>\n'
311
'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
315
def test_version_info_rio(self):
316
output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
317
self.assertEqual(error, '')
318
self.assertNotIn('revno:', output)
320
def test_version_info_python(self):
321
output, error = self.run_bzr(['version-info', '--python', 'gitr'])
322
self.assertEqual(error, '')
323
self.assertNotIn('revno:', output)
325
def test_version_info_custom_with_revno(self):
326
output, error = self.run_bzr(
327
['version-info', '--custom',
328
'--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
330
error, 'brz: ERROR: Variable {revno} is not available.\n')
331
self.assertEqual(output, 'VERSION_INFO r')
333
def test_version_info_custom_without_revno(self):
334
output, error = self.run_bzr(
335
['version-info', '--custom', '--template=VERSION_INFO \n',
337
self.assertEqual(error, '')
338
self.assertEqual(output, 'VERSION_INFO \n')