31
42
def simple_commit(self):
32
43
# Create a git repository with a revision.
44
repo = GitRepo.init(self.test_dir)
34
45
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>')
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
output, error = self.run_bzr(['nick'])
55
self.assertEqual("master\n", output)
57
def test_branches(self):
59
output, error = self.run_bzr(['branches'])
60
self.assertEqual("* master\n", output)
39
62
def test_info(self):
40
63
self.simple_commit()
41
64
output, error = self.run_bzr(['info'])
42
65
self.assertEqual(error, '')
43
self.assertTrue("Repository tree (format: git)" in output)
66
self.assertTrue("Standalone tree (format: git)" in output)
45
68
def test_branch(self):
46
69
os.mkdir("gitbranch")
70
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
49
72
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>')
73
builder.set_file(b'a', b'text for a\n', False)
74
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
55
78
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
56
self.assertEqual(error, 'Branched 1 revision(s).\n')
80
(error == 'Branched 1 revision(s).\n') or
81
(error == 'Branched 1 revision.\n'),
84
def test_checkout(self):
86
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
88
builder = tests.GitBranchBuilder()
89
builder.set_file(b'a', b'text for a\n', False)
90
builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
94
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
95
self.assertEqual(error,
96
'Fetching from Git to Bazaar repository. '
97
'For better performance, fetch into a Git repository.\n')
57
98
self.assertEqual(output, '')
59
100
def test_branch_ls(self):
93
146
# Check that bzr log does not fail and includes the revision.
94
147
output, error = self.run_bzr(['log', '-v'])
96
149
def test_tags(self):
99
tests.run_git("tag", "foo")
150
git_repo, commit_sha1 = self.simple_commit()
151
git_repo.refs[b"refs/tags/foo"] = commit_sha1
101
153
output, error = self.run_bzr(['tags'])
102
self.assertEquals(error, '')
103
self.assertEquals(output, "foo 1\n")
154
self.assertEqual(error, '')
155
self.assertEqual(output, "foo 1\n")
105
157
def test_tag(self):
106
raise KnownFailure("setting tags not supported by git-python yet")
107
158
self.simple_commit()
109
160
output, error = self.run_bzr(["tag", "bar"])
111
self.assertEquals(error, '')
112
self.assertEquals(output, '')
162
# bzr <= 2.2 emits this message in the output stream
163
# bzr => 2.3 emits this message in the error stream
164
self.assertEqual(error + output, 'Created tag bar.\n')
166
def test_init_repo(self):
167
output, error = self.run_bzr(["init", "--format=git", "bla.git"])
168
self.assertEqual(error, '')
169
self.assertEqual(output, 'Created a standalone tree (format: git)\n')
171
def test_diff_format(self):
172
tree = self.make_branch_and_tree('.')
173
self.build_tree(['a'])
175
output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
176
self.assertEqual(error, '')
177
self.assertEqual(output,
178
'diff --git /dev/null b/a\n'
181
'index 0000000..c197bd8 100644\n'
187
def test_git_import_uncolocated(self):
188
r = GitRepo.init("a", mkdir=True)
189
self.build_tree(["a/file"])
191
r.do_commit(ref=b"refs/heads/abranch",
192
committer=b"Joe <joe@example.com>", message=b"Dummy")
193
r.do_commit(ref=b"refs/heads/bbranch",
194
committer=b"Joe <joe@example.com>", message=b"Dummy")
195
self.run_bzr(["git-import", "a", "b"])
197
set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
199
def test_git_import(self):
200
r = GitRepo.init("a", mkdir=True)
201
self.build_tree(["a/file"])
203
r.do_commit(ref=b"refs/heads/abranch",
204
committer=b"Joe <joe@example.com>", message=b"Dummy")
205
r.do_commit(ref=b"refs/heads/bbranch",
206
committer=b"Joe <joe@example.com>", message=b"Dummy")
207
self.run_bzr(["git-import", "--colocated", "a", "b"])
208
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
209
self.assertEqual(set(["abranch", "bbranch"]),
210
set(ControlDir.open("b").get_branches().keys()))
212
def test_git_import_incremental(self):
213
r = GitRepo.init("a", mkdir=True)
214
self.build_tree(["a/file"])
216
r.do_commit(ref=b"refs/heads/abranch",
217
committer=b"Joe <joe@example.com>", message=b"Dummy")
218
self.run_bzr(["git-import", "--colocated", "a", "b"])
219
self.run_bzr(["git-import", "--colocated", "a", "b"])
220
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
221
b = ControlDir.open("b")
222
self.assertEqual(["abranch"], list(b.get_branches().keys()))
224
def test_git_import_tags(self):
225
r = GitRepo.init("a", mkdir=True)
226
self.build_tree(["a/file"])
228
cid = r.do_commit(ref=b"refs/heads/abranch",
229
committer=b"Joe <joe@example.com>", message=b"Dummy")
230
r[b"refs/tags/atag"] = cid
231
self.run_bzr(["git-import", "--colocated", "a", "b"])
232
self.assertEqual(set([".bzr"]), set(os.listdir("b")))
233
b = ControlDir.open("b")
234
self.assertEqual(["abranch"], list(b.get_branches().keys()))
235
self.assertEqual(["atag"],
236
list(b.open_branch("abranch").tags.get_tag_dict().keys()))
238
def test_git_import_colo(self):
239
r = GitRepo.init("a", mkdir=True)
240
self.build_tree(["a/file"])
242
r.do_commit(ref=b"refs/heads/abranch",
243
committer=b"Joe <joe@example.com>", message=b"Dummy")
244
r.do_commit(ref=b"refs/heads/bbranch",
245
committer=b"Joe <joe@example.com>", message=b"Dummy")
246
self.make_controldir("b", format="development-colo")
247
self.run_bzr(["git-import", "--colocated", "a", "b"])
249
set([b.name for b in ControlDir.open("b").list_branches()]),
250
set(["abranch", "bbranch"]))
252
def test_git_refs_from_git(self):
253
r = GitRepo.init("a", mkdir=True)
254
self.build_tree(["a/file"])
256
cid = r.do_commit(ref=b"refs/heads/abranch",
257
committer=b"Joe <joe@example.com>", message=b"Dummy")
258
r[b"refs/tags/atag"] = cid
259
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
260
self.assertEqual(stderr, "")
261
self.assertEqual(stdout,
262
'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
263
'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
265
def test_git_refs_from_bzr(self):
266
tree = self.make_branch_and_tree('a')
267
self.build_tree(["a/file"])
270
committer=b"Joe <joe@example.com>", message=b"Dummy")
271
tree.branch.tags.set_tag("atag", revid)
272
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
273
self.assertEqual(stderr, "")
274
self.assertTrue("refs/tags/atag -> " in stdout)
275
self.assertTrue("HEAD -> " in stdout)
277
def test_check(self):
278
r = GitRepo.init("gitr", mkdir=True)
279
self.build_tree_contents([("gitr/foo", b"hello from git")])
281
r.do_commit(b"message", committer=b"Somebody <user@example.com>")
282
out, err = self.run_bzr(["check", "gitr"])
284
self.assertEqual(out, '')
285
self.assertTrue(err.endswith, '3 objects\n')
288
class ShallowTests(ExternalBase):
291
super(ShallowTests, self).setUp()
292
# Smoke test for "bzr log" in a git repository with shallow depth.
293
self.repo = GitRepo.init('gitr', mkdir=True)
294
self.build_tree_contents([("gitr/foo", b"hello from git")])
295
self.repo.stage("foo")
297
b"message", committer=b"Somebody <user@example.com>",
298
commit_timestamp=1526330165, commit_timezone=0,
299
author_timestamp=1526330165, author_timezone=0,
300
merge_heads=[b'aa' * 20])
302
def test_log_shallow(self):
303
# Check that bzr log does not fail and includes the revision.
304
output, error = self.run_bzr(['log', 'gitr'], retcode=3)
306
error, 'brz: ERROR: Further revision history missing.\n')
307
self.assertEqual(output,
308
'------------------------------------------------------------\n'
309
'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
310
'git commit: ' + self.repo.head().decode('ascii') + '\n'
311
'committer: Somebody <user@example.com>\n'
312
'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
316
def test_version_info_rio(self):
317
output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
318
self.assertEqual(error, '')
319
self.assertNotIn('revno:', output)
321
def test_version_info_python(self):
322
output, error = self.run_bzr(['version-info', '--python', 'gitr'])
323
self.assertEqual(error, '')
324
self.assertNotIn('revno:', output)
326
def test_version_info_custom_with_revno(self):
327
output, error = self.run_bzr(
328
['version-info', '--custom',
329
'--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
331
error, 'brz: ERROR: Variable {revno} is not available.\n')
332
self.assertEqual(output, 'VERSION_INFO r')
334
def test_version_info_custom_without_revno(self):
335
output, error = self.run_bzr(
336
['version-info', '--custom', '--template=VERSION_INFO \n',
338
self.assertEqual(error, '')
339
self.assertEqual(output, 'VERSION_INFO \n')
342
class SwitchTests(ExternalBase):
344
def test_switch_branch(self):
345
# Create a git repository with a revision.
346
repo = GitRepo.init(self.test_dir)
347
builder = tests.GitBranchBuilder()
348
builder.set_branch(b'refs/heads/oldbranch')
349
builder.set_file('a', b'text for a\n', False)
350
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
351
builder.set_branch(b'refs/heads/newbranch')
353
builder.set_file('a', b'text for new a\n', False)
354
builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
357
repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
361
output, error = self.run_bzr('switch oldbranch')
362
self.assertEqual(output, '')
363
self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
365
self.assertFileEqual("text for a\n", 'a')
366
tree = WorkingTree.open('.')
367
with tree.lock_read():
368
basis_tree = tree.basis_tree()
369
with basis_tree.lock_read():
370
self.assertEqual([], list(tree.iter_changes(basis_tree)))
373
class GrepTests(ExternalBase):
375
def test_simple_grep(self):
376
tree = self.make_branch_and_tree('.', format='git')
377
self.build_tree_contents([('a', 'text for a\n')])
379
output, error = self.run_bzr('grep text')
380
self.assertEqual(output, 'a:text for a\n')
381
self.assertEqual(error, '')