/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>
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
2
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
17
18
"""Black-box tests for bzr-git."""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
22
from dulwich.repo import (
23
    Repo as GitRepo,
24
    )
25
0.200.89 by Jelmer Vernooij
Support sprouting branches.
26
import os
27
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
28
from .... import (
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
29
    version_info as breezy_version,
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
30
    )
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
31
from ....controldir import (
32
    ControlDir,
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
33
    )
34
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
35
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.
36
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
37
from .. import (
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
38
    tests,
39
    )
40
41
42
class TestGitBlackBox(ExternalBase):
43
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
44
    def simple_commit(self):
45
        # Create a git repository with a revision.
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
46
        repo = GitRepo.init(self.test_dir)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
47
        builder = tests.GitBranchBuilder()
48
        builder.set_file('a', 'text for a\n', False)
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
49
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
50
        return repo, builder.finish()[r1]
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
51
0.200.294 by Jelmer Vernooij
Add test for nick.
52
    def test_nick(self):
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
53
        r = GitRepo.init(self.test_dir)
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
54
        dir = ControlDir.open(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
55
        dir.create_branch()
0.200.294 by Jelmer Vernooij
Add test for nick.
56
        output, error = self.run_bzr(['nick'])
0.310.9 by Jelmer Vernooij
Some controldir fixes.
57
        self.assertEquals("master\n", output)
0.200.294 by Jelmer Vernooij
Add test for nick.
58
0.327.1 by Jelmer Vernooij
Add test for branches command.
59
    def test_branches(self):
60
        self.simple_commit()
61
        output, error = self.run_bzr(['branches'])
62
        self.assertEquals("* master\n", output)
63
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
64
    def test_info(self):
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
65
        self.simple_commit()
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
66
        output, error = self.run_bzr(['info'])
67
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
68
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
69
0.200.89 by Jelmer Vernooij
Support sprouting branches.
70
    def test_branch(self):
71
        os.mkdir("gitbranch")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
72
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
73
        os.chdir('gitbranch')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
74
        builder = tests.GitBranchBuilder()
75
        builder.set_file('a', 'text for a\n', False)
76
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
77
        builder.finish()
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
78
        os.chdir('..')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
79
80
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
81
        self.assertTrue(
82
            (error == 'Branched 1 revision(s).\n') or
83
            (error == 'Branched 1 revision.\n'),
84
            error)
0.200.89 by Jelmer Vernooij
Support sprouting branches.
85
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
86
    def test_checkout(self):
87
        os.mkdir("gitbranch")
88
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
89
        os.chdir('gitbranch')
90
        builder = tests.GitBranchBuilder()
91
        builder.set_file('a', 'text for a\n', False)
92
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
93
        builder.finish()
94
        os.chdir('..')
95
96
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
97
        self.assertEqual(error, '')
98
        self.assertEqual(output, '')
99
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
100
    def test_branch_ls(self):
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
101
        self.simple_commit()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
102
        output, error = self.run_bzr(['ls', '-r-1'])
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
103
        self.assertEqual(error, '')
104
        self.assertEqual(output, "a\n")
105
0.200.108 by Jelmer Vernooij
Support bzr init --git.
106
    def test_init(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
107
        self.run_bzr("init --format=git repo")
0.200.108 by Jelmer Vernooij
Support bzr init --git.
108
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
109
    def test_info_verbose(self):
110
        self.simple_commit()
111
112
        output, error = self.run_bzr(['info', '-v'])
113
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
114
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
115
        self.assertTrue("control: Local Git Repository" in output)
0.295.1 by Jelmer Vernooij
Split up branch formats.
116
        self.assertTrue("branch: Local Git Branch" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
117
        self.assertTrue("repository: Git Repository" in output)
118
0.200.1325 by Jelmer Vernooij
More test fixes.
119
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
120
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
121
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
122
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
123
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
124
        self.run_bzr(['init', 'foo'])
125
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
126
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
127
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
128
        self.assertEquals("", output)
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
129
        self.assertTrue(error.endswith("Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
130
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
131
    def test_log(self):
132
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
133
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
134
135
        # Check that bzr log does not fail and includes the revision.
136
        output, error = self.run_bzr(['log'])
137
        self.assertEqual(error, '')
138
        self.assertTrue(
139
            '<The commit message>' in output,
140
            "Commit message was not found in output:\n%s" % (output,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
141
142
    def test_log_verbose(self):
143
        # Smoke test for "bzr log -v" in a git repository.
144
        self.simple_commit()
145
146
        # Check that bzr log does not fail and includes the revision.
147
        output, error = self.run_bzr(['log', '-v'])
148
 
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
149
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
150
        git_repo, commit_sha1 = self.simple_commit()
0.200.480 by Jelmer Vernooij
Cope with API changes in Dulwich.
151
        git_repo.refs["refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
152
153
        output, error = self.run_bzr(['tags'])
154
        self.assertEquals(error, '')
155
        self.assertEquals(output, "foo                  1\n")
156
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
157
    def test_tag(self):
158
        self.simple_commit()
159
160
        output, error = self.run_bzr(["tag", "bar"])
161
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
162
        # bzr <= 2.2 emits this message in the output stream
163
        # bzr => 2.3 emits this message in the error stream
164
        self.assertEquals(error + output, 'Created tag bar.\n')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
165
0.200.288 by Jelmer Vernooij
Add test for init-repo.
166
    def test_init_repo(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
167
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
0.200.288 by Jelmer Vernooij
Add test for init-repo.
168
        self.assertEquals(error, '')
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
169
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
170
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
171
    def test_diff_format(self):
172
        tree = self.make_branch_and_tree('.')
173
        self.build_tree(['a'])
174
        tree.add(['a'])
175
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
176
        self.assertEqual(error, '')
177
        self.assertEqual(output,
178
            'diff --git /dev/null b/a\n'
179
            'old mode 0\n'
180
            'new mode 100644\n'
181
            'index 0000000..c197bd8 100644\n'
182
            '--- /dev/null\n'
183
            '+++ b/a\n'
0.200.1666 by Jelmer Vernooij
Fix some tests.
184
            '@@ -0,0 +1 @@\n'
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
185
            '+contents of a\n')
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
186
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
187
    def test_git_import_uncolocated(self):
188
        r = GitRepo.init("a", mkdir=True)
189
        self.build_tree(["a/file"])
190
        r.stage("file")
191
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
192
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
193
        self.run_bzr(["git-import", "a", "b"])
194
        self.assertEquals(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
195
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
196
    def test_git_import(self):
197
        r = GitRepo.init("a", mkdir=True)
198
        self.build_tree(["a/file"])
199
        r.stage("file")
200
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
201
        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.
202
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
203
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
204
        self.assertEquals(set(["abranch", "bbranch"]),
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
205
                set(ControlDir.open("b").get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
206
207
    def test_git_import_incremental(self):
208
        r = GitRepo.init("a", mkdir=True)
209
        self.build_tree(["a/file"])
210
        r.stage("file")
211
        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.
212
        self.run_bzr(["git-import", "--colocated", "a", "b"])
213
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
214
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
215
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
216
        self.assertEquals(["abranch"], b.get_branches().keys())
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
217
218
    def test_git_import_tags(self):
219
        r = GitRepo.init("a", mkdir=True)
220
        self.build_tree(["a/file"])
221
        r.stage("file")
222
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
223
        r["refs/tags/atag"] = cid
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
224
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
225
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
226
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
227
        self.assertEquals(["abranch"], b.get_branches().keys())
228
        self.assertEquals(["atag"],
229
                b.open_branch("abranch").tags.get_tag_dict().keys())
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
230
231
    def test_git_import_colo(self):
232
        r = GitRepo.init("a", mkdir=True)
233
        self.build_tree(["a/file"])
234
        r.stage("file")
235
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
236
        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.
237
        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.
238
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
239
        self.assertEquals(
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
240
            set([b.name for b in ControlDir.open("b").list_branches()]),
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
241
            set(["abranch", "bbranch"]))
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
242
243
    def test_git_refs_from_git(self):
244
        r = GitRepo.init("a", mkdir=True)
245
        self.build_tree(["a/file"])
246
        r.stage("file")
247
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
248
        r["refs/tags/atag"] = cid
249
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
250
        self.assertEquals(stderr, "")
251
        self.assertEquals(stdout,
252
            'refs/tags/atag -> ' + cid + '\n'
253
            'refs/heads/abranch -> ' + cid + '\n')
254
255
    def test_git_refs_from_bzr(self):
256
        tree = self.make_branch_and_tree('a')
257
        self.build_tree(["a/file"])
258
        tree.add(["file"])
259
        revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
260
        tree.branch.tags.set_tag("atag", revid)
261
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
262
        self.assertEquals(stderr, "")
263
        self.assertTrue("refs/tags/atag -> " in stdout)
264
        self.assertTrue("HEAD -> " in stdout)
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
265
266
    def test_dpush(self):
267
        r = GitRepo.init("gitr", mkdir=True)
268
        self.build_tree_contents([("gitr/foo", "hello from git")])
269
        r.stage("foo")
270
        r.do_commit("message", committer="Somebody <user@example.com>")
0.288.4 by Jelmer Vernooij
Fix blackbox tests.
271
        self.run_bzr(["init", "--format=default", "bzrb"])
272
        self.run_bzr(["pull", "gitr", "-d", "bzrb"])
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
273
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
274
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
275
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])
0.200.1592 by Jelmer Vernooij
Add test demonstrating bug #949557.
276
277
    def test_dpush_from_bound(self):
278
        r = GitRepo.init("gitr", mkdir=True)
279
        self.build_tree_contents([("gitr/foo", "hello from git")])
280
        r.stage("foo")
281
        r.do_commit("message", committer="Somebody <user@example.com>")
0.288.4 by Jelmer Vernooij
Fix blackbox tests.
282
        self.run_bzr(["init", "--format=default", "bzrm"])
283
        self.run_bzr(["pull", "gitr", "-d", "bzrm"])
0.200.1592 by Jelmer Vernooij
Add test demonstrating bug #949557.
284
        self.run_bzr(["checkout", "bzrm", "bzrb"])
285
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
286
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
287
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])