/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'])
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
97
        self.assertEqual(error,
98
                'Fetching from Git to Bazaar repository. '
99
                'For better performance, fetch into a Git repository.\n')
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
100
        self.assertEqual(output, '')
101
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
102
    def test_branch_ls(self):
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
103
        self.simple_commit()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
104
        output, error = self.run_bzr(['ls', '-r-1'])
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
105
        self.assertEqual(error, '')
106
        self.assertEqual(output, "a\n")
107
0.200.108 by Jelmer Vernooij
Support bzr init --git.
108
    def test_init(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
109
        self.run_bzr("init --format=git repo")
0.200.108 by Jelmer Vernooij
Support bzr init --git.
110
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
111
    def test_info_verbose(self):
112
        self.simple_commit()
113
114
        output, error = self.run_bzr(['info', '-v'])
115
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
116
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
117
        self.assertTrue("control: Local Git Repository" in output)
0.295.1 by Jelmer Vernooij
Split up branch formats.
118
        self.assertTrue("branch: Local Git Branch" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
119
        self.assertTrue("repository: Git Repository" in output)
120
0.200.1325 by Jelmer Vernooij
More test fixes.
121
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
122
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
123
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
124
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
125
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
126
        self.run_bzr(['init', 'foo'])
127
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
128
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
129
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
130
        self.assertEquals("", output)
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
131
        self.assertTrue(error.endswith("Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
132
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
133
    def test_log(self):
134
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
135
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
136
137
        # Check that bzr log does not fail and includes the revision.
138
        output, error = self.run_bzr(['log'])
139
        self.assertEqual(error, '')
140
        self.assertTrue(
141
            '<The commit message>' in output,
142
            "Commit message was not found in output:\n%s" % (output,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
143
144
    def test_log_verbose(self):
145
        # Smoke test for "bzr log -v" in a git repository.
146
        self.simple_commit()
147
148
        # Check that bzr log does not fail and includes the revision.
149
        output, error = self.run_bzr(['log', '-v'])
150
 
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
151
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
152
        git_repo, commit_sha1 = self.simple_commit()
0.200.480 by Jelmer Vernooij
Cope with API changes in Dulwich.
153
        git_repo.refs["refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
154
155
        output, error = self.run_bzr(['tags'])
156
        self.assertEquals(error, '')
157
        self.assertEquals(output, "foo                  1\n")
158
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
159
    def test_tag(self):
160
        self.simple_commit()
161
162
        output, error = self.run_bzr(["tag", "bar"])
163
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
164
        # bzr <= 2.2 emits this message in the output stream
165
        # bzr => 2.3 emits this message in the error stream
166
        self.assertEquals(error + output, 'Created tag bar.\n')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
167
0.200.288 by Jelmer Vernooij
Add test for init-repo.
168
    def test_init_repo(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
169
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
0.200.288 by Jelmer Vernooij
Add test for init-repo.
170
        self.assertEquals(error, '')
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
171
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
172
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
173
    def test_diff_format(self):
174
        tree = self.make_branch_and_tree('.')
175
        self.build_tree(['a'])
176
        tree.add(['a'])
177
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
178
        self.assertEqual(error, '')
179
        self.assertEqual(output,
180
            'diff --git /dev/null b/a\n'
181
            'old mode 0\n'
182
            'new mode 100644\n'
183
            'index 0000000..c197bd8 100644\n'
184
            '--- /dev/null\n'
185
            '+++ b/a\n'
0.200.1666 by Jelmer Vernooij
Fix some tests.
186
            '@@ -0,0 +1 @@\n'
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
187
            '+contents of a\n')
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
188
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
189
    def test_git_import_uncolocated(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")
195
        self.run_bzr(["git-import", "a", "b"])
196
        self.assertEquals(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
197
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
198
    def test_git_import(self):
199
        r = GitRepo.init("a", mkdir=True)
200
        self.build_tree(["a/file"])
201
        r.stage("file")
202
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
203
        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.
204
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
205
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
206
        self.assertEquals(set(["abranch", "bbranch"]),
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
207
                set(ControlDir.open("b").get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
208
209
    def test_git_import_incremental(self):
210
        r = GitRepo.init("a", mkdir=True)
211
        self.build_tree(["a/file"])
212
        r.stage("file")
213
        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.
214
        self.run_bzr(["git-import", "--colocated", "a", "b"])
215
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
216
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
217
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
218
        self.assertEquals(["abranch"], b.get_branches().keys())
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
219
220
    def test_git_import_tags(self):
221
        r = GitRepo.init("a", mkdir=True)
222
        self.build_tree(["a/file"])
223
        r.stage("file")
224
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
225
        r["refs/tags/atag"] = cid
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
226
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
227
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
228
        b = ControlDir.open("b")
0.200.1567 by Jelmer Vernooij
Fix support for colocated branches.
229
        self.assertEquals(["abranch"], b.get_branches().keys())
230
        self.assertEquals(["atag"],
231
                b.open_branch("abranch").tags.get_tag_dict().keys())
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
232
233
    def test_git_import_colo(self):
234
        r = GitRepo.init("a", mkdir=True)
235
        self.build_tree(["a/file"])
236
        r.stage("file")
237
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
238
        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.
239
        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.
240
        self.run_bzr(["git-import", "--colocated", "a", "b"])
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
241
        self.assertEquals(
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
242
            set([b.name for b in ControlDir.open("b").list_branches()]),
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
243
            set(["abranch", "bbranch"]))
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
244
245
    def test_git_refs_from_git(self):
246
        r = GitRepo.init("a", mkdir=True)
247
        self.build_tree(["a/file"])
248
        r.stage("file")
249
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
250
        r["refs/tags/atag"] = cid
251
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
252
        self.assertEquals(stderr, "")
253
        self.assertEquals(stdout,
254
            'refs/tags/atag -> ' + cid + '\n'
255
            'refs/heads/abranch -> ' + cid + '\n')
256
257
    def test_git_refs_from_bzr(self):
258
        tree = self.make_branch_and_tree('a')
259
        self.build_tree(["a/file"])
260
        tree.add(["file"])
261
        revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
262
        tree.branch.tags.set_tag("atag", revid)
263
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
264
        self.assertEquals(stderr, "")
265
        self.assertTrue("refs/tags/atag -> " in stdout)
266
        self.assertTrue("HEAD -> " in stdout)
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
267
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
268
    def test_check(self):
269
        r = GitRepo.init("gitr", mkdir=True)
270
        self.build_tree_contents([("gitr/foo", "hello from git")])
271
        r.stage("foo")
272
        r.do_commit("message", committer="Somebody <user@example.com>")
273
        out, err = self.run_bzr(["check", "gitr"])
274
        self.maxDiff = None
275
        self.assertMultiLineEqual(out, '')
276
        self.assertTrue(err.endswith, '3 objects\n')
6965.1.2 by Jelmer Vernooij
Add test.
277
278
    def test_log_shallow(self):
279
        # Smoke test for "bzr log" in a git repository with shallow depth.
280
        r = GitRepo.init('gitr', mkdir=True)
281
        self.build_tree_contents([("gitr/foo", "hello from git")])
282
        r.stage("foo")
283
        cid = r.do_commit("message", committer="Somebody <user@example.com>",
284
                    commit_timestamp=1526330165, commit_timezone=0,
285
                    author_timestamp=1526330165, author_timezone=0,
286
                    merge_heads=[b'aa' * 20])
287
288
        # Check that bzr log does not fail and includes the revision.
289
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
290
        self.assertEqual(error, 'brz: ERROR: Further revision history missing.\n')
291
        self.assertEqual(output,
292
                '------------------------------------------------------------\n'
293
                'revision-id: git-v1:' + cid + '\n'
294
                'git commit: ' + cid + '\n'
295
                'committer: Somebody <user@example.com>\n'
296
                'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
297
                'message:\n'
298
                '  message\n')