/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_blackbox.py

TranslateĀ moreĀ strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
"""Black-box tests for bzr-git."""
 
18
 
 
19
from dulwich.repo import (
 
20
    Repo as GitRepo,
 
21
    )
 
22
 
 
23
import os
 
24
 
 
25
from bzrlib.branch import Branch
 
26
from bzrlib import (
 
27
    version_info as bzrlib_version,
 
28
    )
 
29
from bzrlib.bzrdir import (
 
30
    BzrDir,
 
31
    )
 
32
from bzrlib.tests import TestSkipped
 
33
 
 
34
from bzrlib.tests.blackbox import ExternalBase
 
35
 
 
36
from bzrlib.plugins.git import (
 
37
    tests,
 
38
    )
 
39
 
 
40
 
 
41
class TestGitBlackBox(ExternalBase):
 
42
 
 
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]
 
50
 
 
51
    def test_nick(self):
 
52
        GitRepo.init(self.test_dir)
 
53
        dir = BzrDir.open(self.test_dir)
 
54
        dir.create_branch()
 
55
        output, error = self.run_bzr(['nick'])
 
56
        self.assertEquals("master\n", output)
 
57
 
 
58
    def test_info(self):
 
59
        self.simple_commit()
 
60
        output, error = self.run_bzr(['info'])
 
61
        self.assertEqual(error, '')
 
62
        self.assertTrue("Standalone tree (format: git)" in output)
 
63
 
 
64
    def test_branch(self):
 
65
        os.mkdir("gitbranch")
 
66
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
 
67
        os.chdir('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>')
 
71
        builder.finish()
 
72
        os.chdir('..')
 
73
 
 
74
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
 
75
        self.assertTrue(
 
76
            (error == 'Branched 1 revision(s).\n') or
 
77
            (error == 'Branched 1 revision.\n'),
 
78
            error)
 
79
 
 
80
    def test_checkout(self):
 
81
        os.mkdir("gitbranch")
 
82
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
 
83
        os.chdir('gitbranch')
 
84
        builder = tests.GitBranchBuilder()
 
85
        builder.set_file('a', 'text for a\n', False)
 
86
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
 
87
        builder.finish()
 
88
        os.chdir('..')
 
89
 
 
90
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
 
91
        self.assertEqual(error, '')
 
92
        self.assertEqual(output, '')
 
93
 
 
94
    def test_branch_ls(self):
 
95
        self.simple_commit()
 
96
        output, error = self.run_bzr(['ls', '-r-1'])
 
97
        self.assertEqual(error, '')
 
98
        self.assertEqual(output, "a\n")
 
99
 
 
100
    def test_init(self):
 
101
        self.run_bzr("init --git repo")
 
102
 
 
103
    def test_info_verbose(self):
 
104
        self.simple_commit()
 
105
 
 
106
        if bzrlib_version < (2, 4):
 
107
            self.knownFailure("bzr info uses inventory on bzr < 2.4")
 
108
 
 
109
        output, error = self.run_bzr(['info', '-v'])
 
110
        self.assertEqual(error, '')
 
111
        self.assertTrue("Standalone tree (format: git)" in output)
 
112
        self.assertTrue("control: Local Git Repository" in output)
 
113
        self.assertTrue("branch: Git Branch" in output)
 
114
        self.assertTrue("repository: Git Repository" in output)
 
115
 
 
116
    def test_push_roundtripping(self):
 
117
        self.knownFailure("roundtripping is not yet supported")
 
118
        self.with_roundtripping()
 
119
        os.mkdir("bla")
 
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"))
 
127
 
 
128
    def test_log(self):
 
129
        # Smoke test for "bzr log" in a git repository.
 
130
        self.simple_commit()
 
131
 
 
132
        # Check that bzr log does not fail and includes the revision.
 
133
        output, error = self.run_bzr(['log'])
 
134
        self.assertEqual(error, '')
 
135
        self.assertTrue(
 
136
            '<The commit message>' in output,
 
137
            "Commit message was not found in output:\n%s" % (output,))
 
138
 
 
139
    def test_log_verbose(self):
 
140
        # Smoke test for "bzr log -v" in a git repository.
 
141
        self.simple_commit()
 
142
 
 
143
        # Check that bzr log does not fail and includes the revision.
 
144
        output, error = self.run_bzr(['log', '-v'])
 
145
 
 
146
    def test_tags(self):
 
147
        git_repo, commit_sha1 = self.simple_commit()
 
148
        git_repo.refs["refs/tags/foo"] = commit_sha1
 
149
 
 
150
        output, error = self.run_bzr(['tags'])
 
151
        self.assertEquals(error, '')
 
152
        self.assertEquals(output, "foo                  1\n")
 
153
 
 
154
    def test_tag(self):
 
155
        self.simple_commit()
 
156
 
 
157
        output, error = self.run_bzr(["tag", "bar"])
 
158
 
 
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')
 
162
 
 
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')
 
167
 
 
168
    def test_diff_format(self):
 
169
        tree = self.make_branch_and_tree('.')
 
170
        self.build_tree(['a'])
 
171
        tree.add(['a'])
 
172
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
 
173
        self.assertEqual(error, '')
 
174
        self.assertEqual(output,
 
175
            'diff --git /dev/null b/a\n'
 
176
            'old mode 0\n'
 
177
            'new mode 100644\n'
 
178
            'index 0000000..c197bd8 100644\n'
 
179
            '--- /dev/null\n'
 
180
            '+++ b/a\n'
 
181
            '@@ -1,0 +1,1 @@\n'
 
182
            '+contents of a\n')
 
183
 
 
184
    def test_git_import(self):
 
185
        r = GitRepo.init("a", mkdir=True)
 
186
        self.build_tree(["a/file"])
 
187
        r.stage("file")
 
188
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
 
189
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
 
190
        self.run_bzr(["git-import", "a", "b"])
 
191
        self.assertEquals(set(["abranch", "bbranch", ".bzr"]),
 
192
                set(os.listdir("b")))
 
193
 
 
194
    def test_git_import_incremental(self):
 
195
        r = GitRepo.init("a", mkdir=True)
 
196
        self.build_tree(["a/file"])
 
197
        r.stage("file")
 
198
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
 
199
        self.run_bzr(["git-import", "a", "b"])
 
200
        self.run_bzr(["git-import", "a", "b"])
 
201
        self.assertEquals(set(["abranch", ".bzr"]), set(os.listdir("b")))
 
202
 
 
203
    def test_git_import_tags(self):
 
204
        r = GitRepo.init("a", mkdir=True)
 
205
        self.build_tree(["a/file"])
 
206
        r.stage("file")
 
207
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
 
208
        r["refs/tags/atag"] = cid
 
209
        self.run_bzr(["git-import", "a", "b"])
 
210
        self.assertEquals(set(["abranch", ".bzr"]), set(os.listdir("b")))
 
211
        b = Branch.open("b/abranch")
 
212
        self.assertEquals(["atag"], b.tags.get_tag_dict().keys())
 
213
 
 
214
    def test_git_import_colo(self):
 
215
        if bzrlib_version < (2, 5, 0):
 
216
            raise TestSkipped("colocated branches not supported with bzr < 2.5")
 
217
        r = GitRepo.init("a", mkdir=True)
 
218
        self.build_tree(["a/file"])
 
219
        r.stage("file")
 
220
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
 
221
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
 
222
        self.make_bzrdir("b", format="development-colo")
 
223
        self.run_bzr(["git-import", "a", "b"])
 
224
        self.assertEquals(
 
225
            [b.name for b in BzrDir.open("b").list_branches()],
 
226
            ["abranch", "bbranch"])