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 (
25
from bzrlib.bzrdir import (
29
from bzrlib.tests.blackbox import ExternalBase
30
from bzrlib.tests import KnownFailure
32
from bzrlib.plugins.git import (
37
class TestGitBlackBox(ExternalBase):
39
def simple_commit(self):
40
# Create a git repository with a revision.
41
repo = GitRepo.init(self.test_dir)
42
builder = tests.GitBranchBuilder()
43
builder.set_file('a', 'text for a\n', False)
44
r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
45
return repo, builder.finish()[r1]
48
GitRepo.init(self.test_dir)
49
dir = BzrDir.open(self.test_dir)
51
output, error = self.run_bzr(['nick'])
52
self.assertEquals("HEAD\n", output)
56
output, error = self.run_bzr(['info'])
57
self.assertEqual(error, '')
58
self.assertTrue("Standalone tree (format: git)" in output)
60
def test_branch(self):
62
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
64
builder = tests.GitBranchBuilder()
65
builder.set_file('a', 'text for a\n', False)
66
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
70
output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
71
self.assertEqual(error, 'Branched 1 revision(s).\n')
73
def test_checkout(self):
75
GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
77
builder = tests.GitBranchBuilder()
78
builder.set_file('a', 'text for a\n', False)
79
builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
83
output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
84
self.assertEqual(error, '')
85
self.assertEqual(output, '')
87
def test_branch_ls(self):
89
output, error = self.run_bzr(['ls', '-r-1'])
90
self.assertEqual(error, '')
91
self.assertEqual(output, "a\n")
94
self.run_bzr("init --git repo")
96
def test_info_verbose(self):
99
output, error = self.run_bzr(['info', '-v'])
100
self.assertEqual(error, '')
101
self.assertTrue("Standalone tree (format: git)" in output)
102
self.assertTrue("control: Local Git Repository" in output)
103
self.assertTrue("branch: Git Branch" in output)
104
self.assertTrue("repository: Git Repository" in output)
108
GitRepo.init(os.path.join(self.test_dir, "bla"))
109
self.run_bzr(['init', 'foo'])
110
self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
111
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'], retcode=3)
112
raise KnownFailure("roundtripping is not supported")
114
# when roundtripping is supported
115
output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
116
self.assertEquals("", output)
117
self.assertTrue(error.endswith("Created new branch.\n"))
120
# Smoke test for "bzr log" in a git repository.
123
# Check that bzr log does not fail and includes the revision.
124
output, error = self.run_bzr(['log'])
125
self.assertEqual(error, '')
127
'<The commit message>' in output,
128
"Commit message was not found in output:\n%s" % (output,))
130
def test_log_verbose(self):
131
# Smoke test for "bzr log -v" in a git repository.
134
# Check that bzr log does not fail and includes the revision.
135
output, error = self.run_bzr(['log', '-v'])
138
git_repo, commit_sha1 = self.simple_commit()
139
git_repo.refs["refs/tags/foo"] = commit_sha1
141
output, error = self.run_bzr(['tags'])
142
self.assertEquals(error, '')
143
self.assertEquals(output, "foo 1\n")
148
output, error = self.run_bzr(["tag", "bar"])
150
# bzr <= 2.2 emits this message in the output stream
151
# bzr => 2.3 emits this message in the error stream
152
self.assertEquals(error + output, 'Created tag bar.\n')
154
def test_init_repo(self):
155
output, error = self.run_bzr(["init", "--git", "bla.git"])
156
self.assertEquals(error, '')
157
self.assertEquals(output, 'Created a standalone tree (format: git)\n')