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 (
29
version_info as breezy_version,
31
from ....controldir import (
35
from ....tests.blackbox import ExternalBase
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', 'text for a\n', False)
49
r1 = builder.commit('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
output, error = self.run_bzr(['nick'])
57
self.assertEquals("master\n", output)
59
def test_branches(self):
61
output, error = self.run_bzr(['branches'])
62
self.assertEquals("* master\n", output)
66
output, error = self.run_bzr(['info'])
67
self.assertEqual(error, '')
68
self.assertTrue("Standalone tree (format: git)" in output)
70
def test_branch(self):
72
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
74
builder = tests.GitBranchBuilder()
75
builder.set_file('a', 'text for a\n', False)
76
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
80
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
82
(error == 'Branched 1 revision(s).\n') or
83
(error == 'Branched 1 revision.\n'),
86
def test_checkout(self):
88
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
90
builder = tests.GitBranchBuilder()
91
builder.set_file('a', 'text for a\n', False)
92
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
96
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
97
self.assertEqual(error,
98
'Fetching from Git to Bazaar repository. '
99
'For better performance, fetch into a Git repository.\n')
100
self.assertEqual(output, '')
102
def test_branch_ls(self):
104
output, error = self.run_bzr(['ls', '-r-1'])
105
self.assertEqual(error, '')
106
self.assertEqual(output, "a\n")
109
self.run_bzr("init --format=git repo")
111
def test_info_verbose(self):
114
output, error = self.run_bzr(['info', '-v'])
115
self.assertEqual(error, '')
116
self.assertTrue("Standalone tree (format: git)" in output)
117
self.assertTrue("control: Local Git Repository" in output)
118
self.assertTrue("branch: Local Git Branch" in output)
119
self.assertTrue("repository: Git Repository" in output)
121
def test_push_roundtripping(self):
122
self.knownFailure("roundtripping is not yet supported")
123
self.with_roundtripping()
125
GitRepo.init(os.path.join(self.test_dir, "bla"))
126
self.run_bzr(['init', 'foo'])
127
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
128
# when roundtripping is supported
129
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
130
self.assertEquals("", output)
131
self.assertTrue(error.endswith("Created new branch.\n"))
134
# Smoke test for "bzr log" in a git repository.
137
# Check that bzr log does not fail and includes the revision.
138
output, error = self.run_bzr(['log'])
139
self.assertEqual(error, '')
141
'<The commit message>' in output,
142
"Commit message was not found in output:\n%s" % (output,))
144
def test_log_verbose(self):
145
# Smoke test for "bzr log -v" in a git repository.
148
# Check that bzr log does not fail and includes the revision.
149
output, error = self.run_bzr(['log', '-v'])
152
git_repo, commit_sha1 = self.simple_commit()
153
git_repo.refs["refs/tags/foo"] = commit_sha1
155
output, error = self.run_bzr(['tags'])
156
self.assertEquals(error, '')
157
self.assertEquals(output, "foo 1\n")
162
output, error = self.run_bzr(["tag", "bar"])
164
# bzr <= 2.2 emits this message in the output stream
165
# bzr => 2.3 emits this message in the error stream
166
self.assertEquals(error + output, 'Created tag bar.\n')
168
def test_init_repo(self):
169
output, error = self.run_bzr(["init", "--format=git", "bla.git"])
170
self.assertEquals(error, '')
171
self.assertEquals(output, 'Created a standalone tree (format: git)\n')
173
def test_diff_format(self):
174
tree = self.make_branch_and_tree('.')
175
self.build_tree(['a'])
177
output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
178
self.assertEqual(error, '')
179
self.assertEqual(output,
180
'diff --git /dev/null b/a\n'
183
'index 0000000..c197bd8 100644\n'
189
def test_git_import_uncolocated(self):
190
r = GitRepo.init("a", mkdir=True)
191
self.build_tree(["a/file"])
193
r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
194
r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
195
self.run_bzr(["git-import", "a", "b"])
196
self.assertEquals(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="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
203
r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
204
self.run_bzr(["git-import", "--colocated", "a", "b"])
205
self.assertEquals(set([".bzr"]), set(os.listdir("b")))
206
self.assertEquals(set(["abranch", "bbranch"]),
207
set(ControlDir.open("b").get_branches().keys()))
209
def test_git_import_incremental(self):
210
r = GitRepo.init("a", mkdir=True)
211
self.build_tree(["a/file"])
213
r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
214
self.run_bzr(["git-import", "--colocated", "a", "b"])
215
self.run_bzr(["git-import", "--colocated", "a", "b"])
216
self.assertEquals(set([".bzr"]), set(os.listdir("b")))
217
b = ControlDir.open("b")
218
self.assertEquals(["abranch"], b.get_branches().keys())
220
def test_git_import_tags(self):
221
r = GitRepo.init("a", mkdir=True)
222
self.build_tree(["a/file"])
224
cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
225
r["refs/tags/atag"] = cid
226
self.run_bzr(["git-import", "--colocated", "a", "b"])
227
self.assertEquals(set([".bzr"]), set(os.listdir("b")))
228
b = ControlDir.open("b")
229
self.assertEquals(["abranch"], b.get_branches().keys())
230
self.assertEquals(["atag"],
231
b.open_branch("abranch").tags.get_tag_dict().keys())
233
def test_git_import_colo(self):
234
r = GitRepo.init("a", mkdir=True)
235
self.build_tree(["a/file"])
237
r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
238
r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
239
self.make_controldir("b", format="development-colo")
240
self.run_bzr(["git-import", "--colocated", "a", "b"])
242
set([b.name for b in ControlDir.open("b").list_branches()]),
243
set(["abranch", "bbranch"]))
245
def test_git_refs_from_git(self):
246
r = GitRepo.init("a", mkdir=True)
247
self.build_tree(["a/file"])
249
cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
250
r["refs/tags/atag"] = cid
251
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
252
self.assertEquals(stderr, "")
253
self.assertEquals(stdout,
254
'refs/tags/atag -> ' + cid + '\n'
255
'refs/heads/abranch -> ' + cid + '\n')
257
def test_git_refs_from_bzr(self):
258
tree = self.make_branch_and_tree('a')
259
self.build_tree(["a/file"])
261
revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
262
tree.branch.tags.set_tag("atag", revid)
263
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
264
self.assertEquals(stderr, "")
265
self.assertTrue("refs/tags/atag -> " in stdout)
266
self.assertTrue("HEAD -> " in stdout)
268
def test_dpush(self):
269
r = GitRepo.init("gitr", mkdir=True)
270
self.build_tree_contents([("gitr/foo", "hello from git")])
272
r.do_commit("message", committer="Somebody <user@example.com>")
273
self.run_bzr(["init", "--format=default", "bzrb"])
274
self.run_bzr(["pull", "gitr", "-d", "bzrb"])
275
self.build_tree_contents([("bzrb/foo", "hello from bzr")])
276
self.run_bzr(["commit", "-m", "msg", "bzrb"])
277
self.run_bzr(["dpush", "-d", "bzrb", "gitr"])
279
def test_dpush_from_bound(self):
280
r = GitRepo.init("gitr", mkdir=True)
281
self.build_tree_contents([("gitr/foo", "hello from git")])
283
r.do_commit("message", committer="Somebody <user@example.com>")
284
self.run_bzr(["init", "--format=default", "bzrm"])
285
self.run_bzr(["pull", "gitr", "-d", "bzrm"])
286
self.run_bzr(["checkout", "bzrm", "bzrb"])
287
self.build_tree_contents([("bzrb/foo", "hello from bzr")])
288
self.run_bzr(["commit", "-m", "msg", "bzrb"])
289
self.run_bzr(["dpush", "-d", "bzrb", "gitr"])