/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
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
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
19
from dulwich.repo import (
20
    Repo as GitRepo,
21
    )
22
0.200.89 by Jelmer Vernooij
Support sprouting branches.
23
import os
24
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
25
from bzrlib.branch import Branch
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
26
from bzrlib import (
27
    version_info as bzrlib_version,
28
    )
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
29
from bzrlib.bzrdir import (
30
    BzrDir,
31
    )
32
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
33
from bzrlib.tests.blackbox import ExternalBase
34
35
from bzrlib.plugins.git import (
36
    tests,
37
    )
38
39
40
class TestGitBlackBox(ExternalBase):
41
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
42
    def simple_commit(self):
43
        # Create a git repository with a revision.
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
44
        repo = GitRepo.init(self.test_dir)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
45
        builder = tests.GitBranchBuilder()
46
        builder.set_file('a', 'text for a\n', False)
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
47
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
48
        return repo, builder.finish()[r1]
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
49
0.200.294 by Jelmer Vernooij
Add test for nick.
50
    def test_nick(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
51
        GitRepo.init(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
52
        dir = BzrDir.open(self.test_dir)
53
        dir.create_branch()
0.200.294 by Jelmer Vernooij
Add test for nick.
54
        output, error = self.run_bzr(['nick'])
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
55
        self.assertEquals("master\n", output)
0.200.294 by Jelmer Vernooij
Add test for nick.
56
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
57
    def test_info(self):
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
58
        self.simple_commit()
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
59
        output, error = self.run_bzr(['info'])
60
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
61
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
62
0.200.89 by Jelmer Vernooij
Support sprouting branches.
63
    def test_branch(self):
64
        os.mkdir("gitbranch")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
65
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
66
        os.chdir('gitbranch')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
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>')
70
        builder.finish()
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
71
        os.chdir('..')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
72
73
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
74
        self.assertTrue(
75
            (error == 'Branched 1 revision(s).\n') or
76
            (error == 'Branched 1 revision.\n'),
77
            error)
0.200.89 by Jelmer Vernooij
Support sprouting branches.
78
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
79
    def test_checkout(self):
80
        os.mkdir("gitbranch")
81
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
82
        os.chdir('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>')
86
        builder.finish()
87
        os.chdir('..')
88
89
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
90
        self.assertEqual(error, '')
91
        self.assertEqual(output, '')
92
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
93
    def test_branch_ls(self):
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
94
        self.simple_commit()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
95
        output, error = self.run_bzr(['ls', '-r-1'])
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
96
        self.assertEqual(error, '')
97
        self.assertEqual(output, "a\n")
98
0.200.108 by Jelmer Vernooij
Support bzr init --git.
99
    def test_init(self):
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
100
        self.run_bzr("init --git repo")
0.200.108 by Jelmer Vernooij
Support bzr init --git.
101
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
102
    def test_info_verbose(self):
103
        self.simple_commit()
104
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
105
        if bzrlib_version < (2, 4):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
106
            self.knownFailure("bzr info uses inventory on bzr < 2.4")
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
107
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
108
        output, error = self.run_bzr(['info', '-v'])
109
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
110
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
111
        self.assertTrue("control: Local Git Repository" in output)
112
        self.assertTrue("branch: Git Branch" in output)
113
        self.assertTrue("repository: Git Repository" in output)
114
0.200.1325 by Jelmer Vernooij
More test fixes.
115
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
116
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
117
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
118
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
119
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
120
        self.run_bzr(['init', 'foo'])
121
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
122
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
123
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
124
        self.assertEquals("", output)
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
125
        self.assertTrue(error.endswith("Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
126
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
127
    def test_log(self):
128
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
129
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
130
131
        # Check that bzr log does not fail and includes the revision.
132
        output, error = self.run_bzr(['log'])
133
        self.assertEqual(error, '')
134
        self.assertTrue(
135
            '<The commit message>' in output,
136
            "Commit message was not found in output:\n%s" % (output,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
137
138
    def test_log_verbose(self):
139
        # Smoke test for "bzr log -v" in a git repository.
140
        self.simple_commit()
141
142
        # Check that bzr log does not fail and includes the revision.
143
        output, error = self.run_bzr(['log', '-v'])
144
 
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
145
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
146
        git_repo, commit_sha1 = self.simple_commit()
0.200.480 by Jelmer Vernooij
Cope with API changes in Dulwich.
147
        git_repo.refs["refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
148
149
        output, error = self.run_bzr(['tags'])
150
        self.assertEquals(error, '')
151
        self.assertEquals(output, "foo                  1\n")
152
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
153
    def test_tag(self):
154
        self.simple_commit()
155
156
        output, error = self.run_bzr(["tag", "bar"])
157
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
158
        # bzr <= 2.2 emits this message in the output stream
159
        # bzr => 2.3 emits this message in the error stream
160
        self.assertEquals(error + output, 'Created tag bar.\n')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
161
0.200.288 by Jelmer Vernooij
Add test for init-repo.
162
    def test_init_repo(self):
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
163
        output, error = self.run_bzr(["init", "--git", "bla.git"])
0.200.288 by Jelmer Vernooij
Add test for init-repo.
164
        self.assertEquals(error, '')
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
165
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
166
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
167
    def test_diff_format(self):
168
        tree = self.make_branch_and_tree('.')
169
        self.build_tree(['a'])
170
        tree.add(['a'])
171
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
172
        self.assertEqual(error, '')
173
        self.assertEqual(output,
174
            'diff --git /dev/null b/a\n'
175
            'old mode 0\n'
176
            'new mode 100644\n'
177
            'index 0000000..c197bd8 100644\n'
178
            '--- /dev/null\n'
179
            '+++ b/a\n'
180
            '@@ -1,0 +1,1 @@\n'
181
            '+contents of a\n')
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
182
183
    def test_git_import(self):
184
        r = GitRepo.init("a", mkdir=True)
185
        self.build_tree(["a/file"])
186
        r.stage("file")
187
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
188
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
189
        self.run_bzr(["git-import", "a", "b"])
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
190
        self.assertEquals(set(["abranch", "bbranch", ".bzr"]),
191
                set(os.listdir("b")))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
192
193
    def test_git_import_incremental(self):
194
        r = GitRepo.init("a", mkdir=True)
195
        self.build_tree(["a/file"])
196
        r.stage("file")
197
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
198
        self.run_bzr(["git-import", "a", "b"])
199
        self.run_bzr(["git-import", "a", "b"])
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
200
        self.assertEquals(set(["abranch", ".bzr"]), set(os.listdir("b")))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
201
202
    def test_git_import_tags(self):
203
        r = GitRepo.init("a", mkdir=True)
204
        self.build_tree(["a/file"])
205
        r.stage("file")
206
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
207
        r["refs/tags/atag"] = cid
208
        self.run_bzr(["git-import", "a", "b"])
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
209
        self.assertEquals(set(["abranch", ".bzr"]), set(os.listdir("b")))
210
        b = Branch.open("b/abranch")
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
211
        self.assertEquals(["atag"], b.tags.get_tag_dict().keys())
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
212
213
    def test_git_import_colo(self):
214
        r = GitRepo.init("a", mkdir=True)
215
        self.build_tree(["a/file"])
216
        r.stage("file")
217
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
218
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
219
        self.make_bzrdir("b", format="development-colo")
220
        self.run_bzr(["git-import", "a", "b"])
221
        self.assertEquals(
222
            [b.name for b in BzrDir.open("b").list_branches()],
223
            ["abranch", "bbranch"])