1
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Black-box tests for bzr-git."""
19
from dulwich.repo import (
26
version_info as breezy_version,
28
from ....controldir import (
32
from ....tests.blackbox import ExternalBase
39
class TestGitBlackBox(ExternalBase):
41
def simple_commit(self):
42
# Create a git repository with a revision.
43
repo = GitRepo.init(self.test_dir)
44
builder = tests.GitBranchBuilder()
45
builder.set_file('a', 'text for a\n', False)
46
r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
47
return repo, builder.finish()[r1]
50
r = GitRepo.init(self.test_dir)
52
dir = ControlDir.open(self.test_dir)
54
output, error = self.run_bzr(['nick'])
55
self.assertEquals("HEAD\n", output)
59
output, error = self.run_bzr(['info'])
60
self.assertEqual(error, '')
61
self.assertTrue("Standalone tree (format: git)" in output)
63
def test_branch(self):
65
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
67
builder = tests.GitBranchBuilder()
68
builder.set_file('a', 'text for a\n', False)
69
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
73
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
75
(error == 'Branched 1 revision(s).\n') or
76
(error == 'Branched 1 revision.\n'),
79
def test_checkout(self):
81
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
83
builder = tests.GitBranchBuilder()
84
builder.set_file('a', 'text for a\n', False)
85
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
89
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
90
self.assertEqual(error, '')
91
self.assertEqual(output, '')
93
def test_branch_ls(self):
95
output, error = self.run_bzr(['ls', '-r-1'])
96
self.assertEqual(error, '')
97
self.assertEqual(output, "a\n")
100
self.run_bzr("init --format=git repo")
102
def test_info_verbose(self):
105
output, error = self.run_bzr(['info', '-v'])
106
self.assertEqual(error, '')
107
self.assertTrue("Standalone tree (format: git)" in output)
108
self.assertTrue("control: Local Git Repository" in output)
109
self.assertTrue("branch: Git Branch" in output)
110
self.assertTrue("repository: Git Repository" in output)
112
def test_push_roundtripping(self):
113
self.knownFailure("roundtripping is not yet supported")
114
self.with_roundtripping()
116
GitRepo.init(os.path.join(self.test_dir, "bla"))
117
self.run_bzr(['init', 'foo'])
118
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
119
# when roundtripping is supported
120
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
121
self.assertEquals("", output)
122
self.assertTrue(error.endswith("Created new branch.\n"))
125
# Smoke test for "bzr log" in a git repository.
128
# Check that bzr log does not fail and includes the revision.
129
output, error = self.run_bzr(['log'])
130
self.assertEqual(error, '')
132
'<The commit message>' in output,
133
"Commit message was not found in output:\n%s" % (output,))
135
def test_log_verbose(self):
136
# Smoke test for "bzr log -v" in a git repository.
139
# Check that bzr log does not fail and includes the revision.
140
output, error = self.run_bzr(['log', '-v'])
143
git_repo, commit_sha1 = self.simple_commit()
144
git_repo.refs["refs/tags/foo"] = commit_sha1
146
output, error = self.run_bzr(['tags'])
147
self.assertEquals(error, '')
148
self.assertEquals(output, "foo 1\n")
153
output, error = self.run_bzr(["tag", "bar"])
155
# bzr <= 2.2 emits this message in the output stream
156
# bzr => 2.3 emits this message in the error stream
157
self.assertEquals(error + output, 'Created tag bar.\n')
159
def test_init_repo(self):
160
output, error = self.run_bzr(["init", "--format=git", "bla.git"])
161
self.assertEquals(error, '')
162
self.assertEquals(output, 'Created a standalone tree (format: git)\n')
164
def test_diff_format(self):
165
tree = self.make_branch_and_tree('.')
166
self.build_tree(['a'])
168
output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
169
self.assertEqual(error, '')
170
self.assertEqual(output,
171
'diff --git /dev/null b/a\n'
174
'index 0000000..c197bd8 100644\n'
180
def test_git_import_uncolocated(self):
181
r = GitRepo.init("a", mkdir=True)
182
self.build_tree(["a/file"])
184
r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
185
r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
186
self.run_bzr(["git-import", "a", "b"])
187
self.assertEquals(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
189
def test_git_import(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", "--colocated", "a", "b"])
196
self.assertEquals(set([".bzr"]), set(os.listdir("b")))
197
self.assertEquals(set(["abranch", "bbranch"]),
198
set(ControlDir.open("b").get_branches().keys()))
200
def test_git_import_incremental(self):
201
r = GitRepo.init("a", mkdir=True)
202
self.build_tree(["a/file"])
204
r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
205
self.run_bzr(["git-import", "--colocated", "a", "b"])
206
self.run_bzr(["git-import", "--colocated", "a", "b"])
207
self.assertEquals(set([".bzr"]), set(os.listdir("b")))
208
b = ControlDir.open("b")
209
self.assertEquals(["abranch"], b.get_branches().keys())
211
def test_git_import_tags(self):
212
r = GitRepo.init("a", mkdir=True)
213
self.build_tree(["a/file"])
215
cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
216
r["refs/tags/atag"] = cid
217
self.run_bzr(["git-import", "--colocated", "a", "b"])
218
self.assertEquals(set([".bzr"]), set(os.listdir("b")))
219
b = ControlDir.open("b")
220
self.assertEquals(["abranch"], b.get_branches().keys())
221
self.assertEquals(["atag"],
222
b.open_branch("abranch").tags.get_tag_dict().keys())
224
def test_git_import_colo(self):
225
r = GitRepo.init("a", mkdir=True)
226
self.build_tree(["a/file"])
228
r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
229
r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
230
self.make_controldir("b", format="development-colo")
231
self.run_bzr(["git-import", "--colocated", "a", "b"])
233
set([b.name for b in ControlDir.open("b").list_branches()]),
234
set(["abranch", "bbranch"]))
236
def test_git_refs_from_git(self):
237
r = GitRepo.init("a", mkdir=True)
238
self.build_tree(["a/file"])
240
cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
241
r["refs/tags/atag"] = cid
242
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
243
self.assertEquals(stderr, "")
244
self.assertEquals(stdout,
245
'refs/tags/atag -> ' + cid + '\n'
246
'refs/heads/abranch -> ' + cid + '\n')
248
def test_git_refs_from_bzr(self):
249
tree = self.make_branch_and_tree('a')
250
self.build_tree(["a/file"])
252
revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
253
tree.branch.tags.set_tag("atag", revid)
254
(stdout, stderr) = self.run_bzr(["git-refs", "a"])
255
self.assertEquals(stderr, "")
256
self.assertTrue("refs/tags/atag -> " in stdout)
257
self.assertTrue("HEAD -> " in stdout)
259
def test_dpush(self):
260
r = GitRepo.init("gitr", mkdir=True)
261
self.build_tree_contents([("gitr/foo", "hello from git")])
263
r.do_commit("message", committer="Somebody <user@example.com>")
264
self.run_bzr(["branch", "gitr", "bzrb"])
265
self.build_tree_contents([("bzrb/foo", "hello from bzr")])
266
self.run_bzr(["commit", "-m", "msg", "bzrb"])
267
self.run_bzr(["dpush", "-d", "bzrb", "gitr"])
269
def test_dpush_from_bound(self):
270
r = GitRepo.init("gitr", mkdir=True)
271
self.build_tree_contents([("gitr/foo", "hello from git")])
273
r.do_commit("message", committer="Somebody <user@example.com>")
274
self.run_bzr(["branch", "gitr", "bzrm"])
275
self.run_bzr(["checkout", "bzrm", "bzrb"])
276
self.build_tree_contents([("bzrb/foo", "hello from bzr")])
277
self.run_bzr(["commit", "-m", "msg", "bzrb"])
278
self.run_bzr(["dpush", "-d", "bzrb", "gitr"])