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 bzrlib_version,
28
from bzrlib.bzrdir import (
32
from bzrlib.tests.blackbox import ExternalBase
33
from bzrlib.tests import KnownFailure
35
from bzrlib.plugins.git.mapping import mapping_registry
36
from bzrlib.plugins.git import (
41
class TestGitBlackBox(ExternalBase):
43
def simple_commit(self):
44
# Create a git repository with a revision.
45
repo = GitRepo.init(self.test_dir)
46
builder = tests.GitBranchBuilder()
47
builder.set_file('a', 'text for a\n', False)
48
r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
49
return repo, builder.finish()[r1]
52
GitRepo.init(self.test_dir)
53
dir = BzrDir.open(self.test_dir)
55
output, error = self.run_bzr(['nick'])
56
self.assertEquals("master\n", output)
60
output, error = self.run_bzr(['info'])
61
self.assertEqual(error, '')
62
self.assertTrue("Standalone tree (format: git)" in output)
64
def test_branch(self):
66
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
68
builder = tests.GitBranchBuilder()
69
builder.set_file('a', 'text for a\n', False)
70
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
74
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
75
self.assertEqual(error, 'Branched 1 revision(s).\n')
77
def test_checkout(self):
79
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
81
builder = tests.GitBranchBuilder()
82
builder.set_file('a', 'text for a\n', False)
83
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
87
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
88
self.assertEqual(error, '')
89
self.assertEqual(output, '')
91
def test_branch_ls(self):
93
output, error = self.run_bzr(['ls', '-r-1'])
94
self.assertEqual(error, '')
95
self.assertEqual(output, "a\n")
98
self.run_bzr("init --git repo")
100
def test_info_verbose(self):
103
if bzrlib_version < (2, 4):
104
raise KnownFailure("bzr info uses inventory on bzr < 2.4")
106
output, error = self.run_bzr(['info', '-v'])
107
self.assertEqual(error, '')
108
self.assertTrue("Standalone tree (format: git)" in output)
109
self.assertTrue("control: Local Git Repository" in output)
110
self.assertTrue("branch: Git Branch" in output)
111
self.assertTrue("repository: Git Repository" in output)
113
def with_roundtripping(self):
114
self.addCleanup(mapping_registry.set_default, mapping_registry.get().revid_prefix)
115
mapping_registry.set_default('git-experimental')
117
def test_push_roundtripping(self):
118
self.with_roundtripping()
120
GitRepo.init(os.path.join(self.test_dir, "bla"))
121
self.run_bzr(['init', 'foo'])
122
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
123
# when roundtripping is supported
124
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
125
self.assertEquals("", output)
126
self.assertTrue(error.endswith("Created new branch.\n"))
129
# Smoke test for "bzr log" in a git repository.
132
# Check that bzr log does not fail and includes the revision.
133
output, error = self.run_bzr(['log'])
134
self.assertEqual(error, '')
136
'<The commit message>' in output,
137
"Commit message was not found in output:\n%s" % (output,))
139
def test_log_verbose(self):
140
# Smoke test for "bzr log -v" in a git repository.
143
# Check that bzr log does not fail and includes the revision.
144
output, error = self.run_bzr(['log', '-v'])
147
git_repo, commit_sha1 = self.simple_commit()
148
git_repo.refs["refs/tags/foo"] = commit_sha1
150
output, error = self.run_bzr(['tags'])
151
self.assertEquals(error, '')
152
self.assertEquals(output, "foo 1\n")
157
output, error = self.run_bzr(["tag", "bar"])
159
# bzr <= 2.2 emits this message in the output stream
160
# bzr => 2.3 emits this message in the error stream
161
self.assertEquals(error + output, 'Created tag bar.\n')
163
def test_init_repo(self):
164
output, error = self.run_bzr(["init", "--git", "bla.git"])
165
self.assertEquals(error, '')
166
self.assertEquals(output, 'Created a standalone tree (format: git)\n')