/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)
51
        del r["HEAD"]
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
52
        dir = ControlDir.open(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
53
        dir.create_branch()
0.200.294 by Jelmer Vernooij
Add test for nick.
54
        output, error = self.run_bzr(['nick'])
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
55
        self.assertEquals("HEAD\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.1653 by Jelmer Vernooij
--git is now --format=git.
100
        self.run_bzr("init --format=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
105
        output, error = self.run_bzr(['info', '-v'])
106
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
107
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
108
        self.assertTrue("control: Local Git Repository" in output)
109
        self.assertTrue("branch: Git Branch" in output)
110
        self.assertTrue("repository: Git Repository" in output)
111
0.200.1325 by Jelmer Vernooij
More test fixes.
112
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
113
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
114
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
115
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
116
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
117
        self.run_bzr(['init', 'foo'])
118
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
119
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
120
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
121
        self.assertEquals("", output)
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
122
        self.assertTrue(error.endswith("Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
123
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
124
    def test_log(self):
125
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
126
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
127
128
        # Check that bzr log does not fail and includes the revision.
129
        output, error = self.run_bzr(['log'])
130
        self.assertEqual(error, '')
131
        self.assertTrue(
132
            '<The commit message>' in output,
133
            "Commit message was not found in output:\n%s" % (output,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
134
135
    def test_log_verbose(self):
136
        # Smoke test for "bzr log -v" in a git repository.
137
        self.simple_commit()
138
139
        # Check that bzr log does not fail and includes the revision.
140
        output, error = self.run_bzr(['log', '-v'])
141
 
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
142
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
143
        git_repo, commit_sha1 = self.simple_commit()
0.200.480 by Jelmer Vernooij
Cope with API changes in Dulwich.
144
        git_repo.refs["refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
145
146
        output, error = self.run_bzr(['tags'])
147
        self.assertEquals(error, '')
148
        self.assertEquals(output, "foo                  1\n")
149
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
150
    def test_tag(self):
151
        self.simple_commit()
152
153
        output, error = self.run_bzr(["tag", "bar"])
154
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
155
        # bzr <= 2.2 emits this message in the output stream
156
        # bzr => 2.3 emits this message in the error stream
157
        self.assertEquals(error + output, 'Created tag bar.\n')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
158
0.200.288 by Jelmer Vernooij
Add test for init-repo.
159
    def test_init_repo(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
160
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
0.200.288 by Jelmer Vernooij
Add test for init-repo.
161
        self.assertEquals(error, '')
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
162
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
163
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
164
    def test_diff_format(self):
165
        tree = self.make_branch_and_tree('.')
166
        self.build_tree(['a'])
167
        tree.add(['a'])
168
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
169
        self.assertEqual(error, '')
170
        self.assertEqual(output,
171
            'diff --git /dev/null b/a\n'
172
            'old mode 0\n'
173
            'new mode 100644\n'
174
            'index 0000000..c197bd8 100644\n'
175
            '--- /dev/null\n'
176
            '+++ b/a\n'
0.200.1666 by Jelmer Vernooij
Fix some tests.
177
            '@@ -0,0 +1 @@\n'
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
178
            '+contents of a\n')
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
179
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
180
    def test_git_import_uncolocated(self):
181
        r = GitRepo.init("a", mkdir=True)
182
        self.build_tree(["a/file"])
183
        r.stage("file")
184
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
185
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
186
        self.run_bzr(["git-import", "a", "b"])
187
        self.assertEquals(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
188
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
189
    def test_git_import(self):
190
        r = GitRepo.init("a", mkdir=True)
191
        self.build_tree(["a/file"])
192
        r.stage("file")
193
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
194
        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.
195
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
196
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
197
        self.assertEquals(set(["abranch", "bbranch"]),
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
198
                set(ControlDir.open("b").get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
199
200
    def test_git_import_incremental(self):
201
        r = GitRepo.init("a", mkdir=True)
202
        self.build_tree(["a/file"])
203
        r.stage("file")
204
        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.
205
        self.run_bzr(["git-import", "--colocated", "a", "b"])
206
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
207
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
208
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
209
        self.assertEquals(["abranch"], b.get_branches().keys())
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
210
211
    def test_git_import_tags(self):
212
        r = GitRepo.init("a", mkdir=True)
213
        self.build_tree(["a/file"])
214
        r.stage("file")
215
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
216
        r["refs/tags/atag"] = cid
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
217
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
218
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
219
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
220
        self.assertEquals(["abranch"], b.get_branches().keys())
221
        self.assertEquals(["atag"],
222
                b.open_branch("abranch").tags.get_tag_dict().keys())
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
223
224
    def test_git_import_colo(self):
225
        r = GitRepo.init("a", mkdir=True)
226
        self.build_tree(["a/file"])
227
        r.stage("file")
228
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
229
        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.
230
        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.
231
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
232
        self.assertEquals(
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
233
            set([b.name for b in ControlDir.open("b").list_branches()]),
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
234
            set(["abranch", "bbranch"]))
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
235
236
    def test_git_refs_from_git(self):
237
        r = GitRepo.init("a", mkdir=True)
238
        self.build_tree(["a/file"])
239
        r.stage("file")
240
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
241
        r["refs/tags/atag"] = cid
242
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
243
        self.assertEquals(stderr, "")
244
        self.assertEquals(stdout,
245
            'refs/tags/atag -> ' + cid + '\n'
246
            'refs/heads/abranch -> ' + cid + '\n')
247
248
    def test_git_refs_from_bzr(self):
249
        tree = self.make_branch_and_tree('a')
250
        self.build_tree(["a/file"])
251
        tree.add(["file"])
252
        revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
253
        tree.branch.tags.set_tag("atag", revid)
254
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
255
        self.assertEquals(stderr, "")
256
        self.assertTrue("refs/tags/atag -> " in stdout)
257
        self.assertTrue("HEAD -> " in stdout)
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
258
259
    def test_dpush(self):
260
        r = GitRepo.init("gitr", mkdir=True)
261
        self.build_tree_contents([("gitr/foo", "hello from git")])
262
        r.stage("foo")
263
        r.do_commit("message", committer="Somebody <user@example.com>")
264
        self.run_bzr(["branch", "gitr", "bzrb"])
265
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
266
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
267
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])
0.200.1592 by Jelmer Vernooij
Add test demonstrating bug #949557.
268
269
    def test_dpush_from_bound(self):
270
        r = GitRepo.init("gitr", mkdir=True)
271
        self.build_tree_contents([("gitr/foo", "hello from git")])
272
        r.stage("foo")
273
        r.do_commit("message", committer="Somebody <user@example.com>")
274
        self.run_bzr(["branch", "gitr", "bzrm"])
275
        self.run_bzr(["checkout", "bzrm", "bzrb"])
276
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
277
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
278
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])