/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.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from .... import (
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
26
    version_info as breezy_version,
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
27
    )
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
28
from ....controldir import (
29
    ControlDir,
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
30
    )
31
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
32
from ....tests.blackbox import ExternalBase
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
33
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
34
from .. import (
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
35
    tests,
36
    )
37
38
39
class TestGitBlackBox(ExternalBase):
40
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
41
    def simple_commit(self):
42
        # Create a git repository with a revision.
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
43
        repo = GitRepo.init(self.test_dir)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
44
        builder = tests.GitBranchBuilder()
45
        builder.set_file('a', 'text for a\n', False)
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
46
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
47
        return repo, builder.finish()[r1]
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
48
0.200.294 by Jelmer Vernooij
Add test for nick.
49
    def test_nick(self):
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
50
        r = GitRepo.init(self.test_dir)
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
51
        dir = ControlDir.open(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
52
        dir.create_branch()
0.200.294 by Jelmer Vernooij
Add test for nick.
53
        output, error = self.run_bzr(['nick'])
0.310.9 by Jelmer Vernooij
Some controldir fixes.
54
        self.assertEquals("master\n", output)
0.200.294 by Jelmer Vernooij
Add test for nick.
55
0.327.1 by Jelmer Vernooij
Add test for branches command.
56
    def test_branches(self):
57
        self.simple_commit()
58
        output, error = self.run_bzr(['branches'])
59
        self.assertEquals("* master\n", output)
60
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
61
    def test_info(self):
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
62
        self.simple_commit()
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
63
        output, error = self.run_bzr(['info'])
64
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
65
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
66
0.200.89 by Jelmer Vernooij
Support sprouting branches.
67
    def test_branch(self):
68
        os.mkdir("gitbranch")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
69
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
70
        os.chdir('gitbranch')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
71
        builder = tests.GitBranchBuilder()
72
        builder.set_file('a', 'text for a\n', False)
73
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
74
        builder.finish()
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
75
        os.chdir('..')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
76
77
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
78
        self.assertTrue(
79
            (error == 'Branched 1 revision(s).\n') or
80
            (error == 'Branched 1 revision.\n'),
81
            error)
0.200.89 by Jelmer Vernooij
Support sprouting branches.
82
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
83
    def test_checkout(self):
84
        os.mkdir("gitbranch")
85
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
86
        os.chdir('gitbranch')
87
        builder = tests.GitBranchBuilder()
88
        builder.set_file('a', 'text for a\n', False)
89
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
90
        builder.finish()
91
        os.chdir('..')
92
93
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
94
        self.assertEqual(error, '')
95
        self.assertEqual(output, '')
96
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
97
    def test_branch_ls(self):
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
98
        self.simple_commit()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
99
        output, error = self.run_bzr(['ls', '-r-1'])
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
100
        self.assertEqual(error, '')
101
        self.assertEqual(output, "a\n")
102
0.200.108 by Jelmer Vernooij
Support bzr init --git.
103
    def test_init(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
104
        self.run_bzr("init --format=git repo")
0.200.108 by Jelmer Vernooij
Support bzr init --git.
105
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
106
    def test_info_verbose(self):
107
        self.simple_commit()
108
109
        output, error = self.run_bzr(['info', '-v'])
110
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
111
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
112
        self.assertTrue("control: Local Git Repository" in output)
0.295.1 by Jelmer Vernooij
Split up branch formats.
113
        self.assertTrue("branch: Local Git Branch" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
114
        self.assertTrue("repository: Git Repository" in output)
115
0.200.1325 by Jelmer Vernooij
More test fixes.
116
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
117
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
118
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
119
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
120
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
121
        self.run_bzr(['init', 'foo'])
122
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
123
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
124
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
125
        self.assertEquals("", output)
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
126
        self.assertTrue(error.endswith("Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
127
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
128
    def test_log(self):
129
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
130
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
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,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
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
 
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
146
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
147
        git_repo, commit_sha1 = self.simple_commit()
0.200.480 by Jelmer Vernooij
Cope with API changes in Dulwich.
148
        git_repo.refs["refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
149
150
        output, error = self.run_bzr(['tags'])
151
        self.assertEquals(error, '')
152
        self.assertEquals(output, "foo                  1\n")
153
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
154
    def test_tag(self):
155
        self.simple_commit()
156
157
        output, error = self.run_bzr(["tag", "bar"])
158
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
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')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
162
0.200.288 by Jelmer Vernooij
Add test for init-repo.
163
    def test_init_repo(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
164
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
0.200.288 by Jelmer Vernooij
Add test for init-repo.
165
        self.assertEquals(error, '')
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
166
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
167
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
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'
0.200.1666 by Jelmer Vernooij
Fix some tests.
181
            '@@ -0,0 +1 @@\n'
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
182
            '+contents of a\n')
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
183
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
184
    def test_git_import_uncolocated(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([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
192
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
193
    def test_git_import(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
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
199
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
200
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
201
        self.assertEquals(set(["abranch", "bbranch"]),
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
202
                set(ControlDir.open("b").get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
203
204
    def test_git_import_incremental(self):
205
        r = GitRepo.init("a", mkdir=True)
206
        self.build_tree(["a/file"])
207
        r.stage("file")
208
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
209
        self.run_bzr(["git-import", "--colocated", "a", "b"])
210
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
211
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
212
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
213
        self.assertEquals(["abranch"], b.get_branches().keys())
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
214
215
    def test_git_import_tags(self):
216
        r = GitRepo.init("a", mkdir=True)
217
        self.build_tree(["a/file"])
218
        r.stage("file")
219
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
220
        r["refs/tags/atag"] = cid
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
221
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
222
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
223
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
224
        self.assertEquals(["abranch"], b.get_branches().keys())
225
        self.assertEquals(["atag"],
226
                b.open_branch("abranch").tags.get_tag_dict().keys())
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
227
228
    def test_git_import_colo(self):
229
        r = GitRepo.init("a", mkdir=True)
230
        self.build_tree(["a/file"])
231
        r.stage("file")
232
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
233
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
234
        self.make_controldir("b", format="development-colo")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
235
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
236
        self.assertEquals(
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
237
            set([b.name for b in ControlDir.open("b").list_branches()]),
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
238
            set(["abranch", "bbranch"]))
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
239
240
    def test_git_refs_from_git(self):
241
        r = GitRepo.init("a", mkdir=True)
242
        self.build_tree(["a/file"])
243
        r.stage("file")
244
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
245
        r["refs/tags/atag"] = cid
246
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
247
        self.assertEquals(stderr, "")
248
        self.assertEquals(stdout,
249
            'refs/tags/atag -> ' + cid + '\n'
250
            'refs/heads/abranch -> ' + cid + '\n')
251
252
    def test_git_refs_from_bzr(self):
253
        tree = self.make_branch_and_tree('a')
254
        self.build_tree(["a/file"])
255
        tree.add(["file"])
256
        revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
257
        tree.branch.tags.set_tag("atag", revid)
258
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
259
        self.assertEquals(stderr, "")
260
        self.assertTrue("refs/tags/atag -> " in stdout)
261
        self.assertTrue("HEAD -> " in stdout)
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
262
263
    def test_dpush(self):
264
        r = GitRepo.init("gitr", mkdir=True)
265
        self.build_tree_contents([("gitr/foo", "hello from git")])
266
        r.stage("foo")
267
        r.do_commit("message", committer="Somebody <user@example.com>")
0.288.4 by Jelmer Vernooij
Fix blackbox tests.
268
        self.run_bzr(["init", "--format=default", "bzrb"])
269
        self.run_bzr(["pull", "gitr", "-d", "bzrb"])
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
270
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
271
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
272
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])
0.200.1592 by Jelmer Vernooij
Add test demonstrating bug #949557.
273
274
    def test_dpush_from_bound(self):
275
        r = GitRepo.init("gitr", mkdir=True)
276
        self.build_tree_contents([("gitr/foo", "hello from git")])
277
        r.stage("foo")
278
        r.do_commit("message", committer="Somebody <user@example.com>")
0.288.4 by Jelmer Vernooij
Fix blackbox tests.
279
        self.run_bzr(["init", "--format=default", "bzrm"])
280
        self.run_bzr(["pull", "gitr", "-d", "bzrm"])
0.200.1592 by Jelmer Vernooij
Add test demonstrating bug #949557.
281
        self.run_bzr(["checkout", "bzrm", "bzrb"])
282
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
283
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
284
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])