/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
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
28
from ...controldir import (
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
29
    ControlDir,
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
30
    )
31
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
32
from ...tests.blackbox import ExternalBase
7143.18.1 by Jelmer Vernooij
Fix 'bzr switch' in git repositories.
33
from ...workingtree import WorkingTree
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
34
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
35
from .. import (
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
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()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
46
        builder.set_file('a', b'text for a\n', False)
47
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
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.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
51
        r = GitRepo.init(self.test_dir)
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'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
55
        self.assertEqual("master\n", output)
0.200.294 by Jelmer Vernooij
Add test for nick.
56
0.327.1 by Jelmer Vernooij
Add test for branches command.
57
    def test_branches(self):
58
        self.simple_commit()
59
        output, error = self.run_bzr(['branches'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
60
        self.assertEqual("* master\n", output)
0.327.1 by Jelmer Vernooij
Add test for branches command.
61
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
62
    def test_info(self):
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
63
        self.simple_commit()
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
64
        output, error = self.run_bzr(['info'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
65
        self.assertEqual(error, '')
66
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
67
7199.4.1 by Jelmer Vernooij
Fix 'brz ignore' in Git working trees.
68
    def test_ignore(self):
69
        self.simple_commit()
70
        output, error = self.run_bzr(['ignore', 'foo'])
71
        self.assertEqual(error, '')
72
        self.assertEqual(output, '')
73
        self.assertFileEqual("foo\n", ".gitignore")
74
0.200.89 by Jelmer Vernooij
Support sprouting branches.
75
    def test_branch(self):
76
        os.mkdir("gitbranch")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
77
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
78
        os.chdir('gitbranch')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
79
        builder = tests.GitBranchBuilder()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
80
        builder.set_file(b'a', b'text for a\n', False)
81
        builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
82
        builder.finish()
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
83
        os.chdir('..')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
84
85
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
86
        self.assertTrue(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
87
            (error == 'Branched 1 revision(s).\n') or
88
            (error == 'Branched 1 revision.\n'),
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
89
            error)
0.200.89 by Jelmer Vernooij
Support sprouting branches.
90
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
91
    def test_checkout(self):
92
        os.mkdir("gitbranch")
93
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
94
        os.chdir('gitbranch')
95
        builder = tests.GitBranchBuilder()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
96
        builder.set_file(b'a', b'text for a\n', False)
97
        builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
98
        builder.finish()
99
        os.chdir('..')
100
101
        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.
102
        self.assertEqual(error,
7143.15.2 by Jelmer Vernooij
Run autopep8.
103
                         'Fetching from Git to Bazaar repository. '
104
                         'For better performance, fetch into a Git repository.\n')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
105
        self.assertEqual(output, '')
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
106
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
107
    def test_branch_ls(self):
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
108
        self.simple_commit()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
109
        output, error = self.run_bzr(['ls', '-r-1'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
110
        self.assertEqual(error, '')
111
        self.assertEqual(output, "a\n")
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
112
0.200.108 by Jelmer Vernooij
Support bzr init --git.
113
    def test_init(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
114
        self.run_bzr("init --format=git repo")
0.200.108 by Jelmer Vernooij
Support bzr init --git.
115
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
116
    def test_info_verbose(self):
117
        self.simple_commit()
118
119
        output, error = self.run_bzr(['info', '-v'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
120
        self.assertEqual(error, '')
121
        self.assertTrue("Standalone tree (format: git)" in output)
122
        self.assertTrue("control: Local Git Repository" in output)
123
        self.assertTrue("branch: Local Git Branch" in output)
124
        self.assertTrue("repository: Git Repository" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
125
0.200.1325 by Jelmer Vernooij
More test fixes.
126
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
127
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
128
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
129
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
130
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
131
        self.run_bzr(['init', 'foo'])
132
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
133
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
134
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
135
        self.assertEqual(b"", output)
136
        self.assertTrue(error.endswith(b"Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
137
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
138
    def test_log(self):
139
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
140
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
141
142
        # Check that bzr log does not fail and includes the revision.
143
        output, error = self.run_bzr(['log'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
144
        self.assertEqual(error, '')
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
145
        self.assertTrue(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
146
            '<The commit message>' in output,
147
            "Commit message was not found in output:\n%s" % (output,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
148
149
    def test_log_verbose(self):
150
        # Smoke test for "bzr log -v" in a git repository.
151
        self.simple_commit()
152
153
        # Check that bzr log does not fail and includes the revision.
154
        output, error = self.run_bzr(['log', '-v'])
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
155
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
156
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
157
        git_repo, commit_sha1 = self.simple_commit()
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
158
        git_repo.refs[b"refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
159
160
        output, error = self.run_bzr(['tags'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
161
        self.assertEqual(error, '')
162
        self.assertEqual(output, "foo                  1\n")
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
163
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
164
    def test_tag(self):
165
        self.simple_commit()
166
167
        output, error = self.run_bzr(["tag", "bar"])
168
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
169
        # bzr <= 2.2 emits this message in the output stream
170
        # bzr => 2.3 emits this message in the error stream
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
171
        self.assertEqual(error + output, 'Created tag bar.\n')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
172
0.200.288 by Jelmer Vernooij
Add test for init-repo.
173
    def test_init_repo(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
174
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
175
        self.assertEqual(error, '')
176
        self.assertEqual(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
177
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
178
    def test_diff_format(self):
179
        tree = self.make_branch_and_tree('.')
180
        self.build_tree(['a'])
181
        tree.add(['a'])
182
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
183
        self.assertEqual(error, '')
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
184
        self.assertEqual(output,
7143.15.2 by Jelmer Vernooij
Run autopep8.
185
                         'diff --git /dev/null b/a\n'
186
                         'old mode 0\n'
187
                         'new mode 100644\n'
188
                         'index 0000000..c197bd8 100644\n'
189
                         '--- /dev/null\n'
190
                         '+++ b/a\n'
191
                         '@@ -0,0 +1 @@\n'
192
                         '+contents of a\n')
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
193
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
194
    def test_git_import_uncolocated(self):
195
        r = GitRepo.init("a", mkdir=True)
196
        self.build_tree(["a/file"])
197
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
198
        r.do_commit(ref=b"refs/heads/abranch",
199
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
200
        r.do_commit(ref=b"refs/heads/bbranch",
201
                    committer=b"Joe <joe@example.com>", message=b"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", "a", "b"])
7143.15.2 by Jelmer Vernooij
Run autopep8.
203
        self.assertEqual(
204
            set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
205
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
206
    def test_git_import(self):
207
        r = GitRepo.init("a", mkdir=True)
208
        self.build_tree(["a/file"])
209
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
210
        r.do_commit(ref=b"refs/heads/abranch",
211
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
212
        r.do_commit(ref=b"refs/heads/bbranch",
213
                    committer=b"Joe <joe@example.com>", message=b"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"])
6964.2.3 by Jelmer Vernooij
Review comments.
215
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
216
        self.assertEqual(set(["abranch", "bbranch"]),
7143.15.2 by Jelmer Vernooij
Run autopep8.
217
                         set(ControlDir.open("b").get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
218
219
    def test_git_import_incremental(self):
220
        r = GitRepo.init("a", mkdir=True)
221
        self.build_tree(["a/file"])
222
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
223
        r.do_commit(ref=b"refs/heads/abranch",
224
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
225
        self.run_bzr(["git-import", "--colocated", "a", "b"])
226
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
227
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
228
        b = ControlDir.open("b")
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
229
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
230
231
    def test_git_import_tags(self):
232
        r = GitRepo.init("a", mkdir=True)
233
        self.build_tree(["a/file"])
234
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
235
        cid = r.do_commit(ref=b"refs/heads/abranch",
236
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
237
        r[b"refs/tags/atag"] = cid
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"])
6964.2.3 by Jelmer Vernooij
Review comments.
239
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
240
        b = ControlDir.open("b")
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
241
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
6964.2.3 by Jelmer Vernooij
Review comments.
242
        self.assertEqual(["atag"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
243
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
244
245
    def test_git_import_colo(self):
246
        r = GitRepo.init("a", mkdir=True)
247
        self.build_tree(["a/file"])
248
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
249
        r.do_commit(ref=b"refs/heads/abranch",
250
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
251
        r.do_commit(ref=b"refs/heads/bbranch",
252
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
253
        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.
254
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
255
        self.assertEqual(
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
256
            set([b.name for b in ControlDir.open("b").list_branches()]),
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
257
            set(["abranch", "bbranch"]))
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
258
259
    def test_git_refs_from_git(self):
260
        r = GitRepo.init("a", mkdir=True)
261
        self.build_tree(["a/file"])
262
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
263
        cid = r.do_commit(ref=b"refs/heads/abranch",
264
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
265
        r[b"refs/tags/atag"] = cid
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
266
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
267
        self.assertEqual(stderr, "")
6964.2.3 by Jelmer Vernooij
Review comments.
268
        self.assertEqual(stdout,
7143.15.2 by Jelmer Vernooij
Run autopep8.
269
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
270
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
271
272
    def test_git_refs_from_bzr(self):
273
        tree = self.make_branch_and_tree('a')
274
        self.build_tree(["a/file"])
275
        tree.add(["file"])
7143.15.2 by Jelmer Vernooij
Run autopep8.
276
        revid = tree.commit(
277
            committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
278
        tree.branch.tags.set_tag("atag", revid)
279
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
280
        self.assertEqual(stderr, "")
281
        self.assertTrue("refs/tags/atag -> " in stdout)
282
        self.assertTrue("HEAD -> " in stdout)
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
283
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
284
    def test_check(self):
285
        r = GitRepo.init("gitr", mkdir=True)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
286
        self.build_tree_contents([("gitr/foo", b"hello from git")])
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
287
        r.stage("foo")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
288
        r.do_commit(b"message", committer=b"Somebody <user@example.com>")
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
289
        out, err = self.run_bzr(["check", "gitr"])
290
        self.maxDiff = None
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
291
        self.assertEqual(out, '')
292
        self.assertTrue(err.endswith, '3 objects\n')
6965.1.2 by Jelmer Vernooij
Add test.
293
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
294
295
class ShallowTests(ExternalBase):
296
297
    def setUp(self):
298
        super(ShallowTests, self).setUp()
299
        # Smoke test for "bzr log" in a git repository with shallow depth.
300
        self.repo = GitRepo.init('gitr', mkdir=True)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
301
        self.build_tree_contents([("gitr/foo", b"hello from git")])
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
302
        self.repo.stage("foo")
303
        self.repo.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
304
            b"message", committer=b"Somebody <user@example.com>",
305
            commit_timestamp=1526330165, commit_timezone=0,
306
            author_timestamp=1526330165, author_timezone=0,
307
            merge_heads=[b'aa' * 20])
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
308
6965.1.2 by Jelmer Vernooij
Add test.
309
    def test_log_shallow(self):
310
        # Check that bzr log does not fail and includes the revision.
311
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
7143.15.2 by Jelmer Vernooij
Run autopep8.
312
        self.assertEqual(
313
            error, 'brz: ERROR: Further revision history missing.\n')
6965.1.2 by Jelmer Vernooij
Add test.
314
        self.assertEqual(output,
7143.15.2 by Jelmer Vernooij
Run autopep8.
315
                         '------------------------------------------------------------\n'
316
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
317
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
318
                         'committer: Somebody <user@example.com>\n'
319
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
320
                         'message:\n'
321
                         '  message\n')
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
322
323
    def test_version_info_rio(self):
324
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
325
        self.assertEqual(error, '')
326
        self.assertNotIn('revno:', output)
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
327
328
    def test_version_info_python(self):
329
        output, error = self.run_bzr(['version-info', '--python', 'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
330
        self.assertEqual(error, '')
331
        self.assertNotIn('revno:', output)
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
332
333
    def test_version_info_custom_with_revno(self):
334
        output, error = self.run_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
335
            ['version-info', '--custom',
336
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
337
        self.assertEqual(
338
            error, 'brz: ERROR: Variable {revno} is not available.\n')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
339
        self.assertEqual(output, 'VERSION_INFO r')
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
340
341
    def test_version_info_custom_without_revno(self):
342
        output, error = self.run_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
343
            ['version-info', '--custom', '--template=VERSION_INFO \n',
344
             'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
345
        self.assertEqual(error, '')
346
        self.assertEqual(output, 'VERSION_INFO \n')
7143.17.1 by Jelmer Vernooij
Fix grep in git working trees.
347
348
7143.18.1 by Jelmer Vernooij
Fix 'bzr switch' in git repositories.
349
class SwitchTests(ExternalBase):
350
351
    def test_switch_branch(self):
352
        # Create a git repository with a revision.
353
        repo = GitRepo.init(self.test_dir)
354
        builder = tests.GitBranchBuilder()
355
        builder.set_branch(b'refs/heads/oldbranch')
356
        builder.set_file('a', b'text for a\n', False)
357
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
358
        builder.set_branch(b'refs/heads/newbranch')
359
        builder.reset()
360
        builder.set_file('a', b'text for new a\n', False)
361
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
362
        builder.finish()
363
364
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
365
366
        repo.reset_index()
367
368
        output, error = self.run_bzr('switch oldbranch')
369
        self.assertEqual(output, '')
370
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
371
372
        self.assertFileEqual("text for a\n", 'a')
373
        tree = WorkingTree.open('.')
374
        with tree.lock_read():
375
            basis_tree = tree.basis_tree()
376
            with basis_tree.lock_read():
377
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
7143.18.2 by Jelmer Vernooij
Merge trunk.
378
379
7143.17.1 by Jelmer Vernooij
Fix grep in git working trees.
380
class GrepTests(ExternalBase):
381
382
    def test_simple_grep(self):
383
        tree = self.make_branch_and_tree('.', format='git')
384
        self.build_tree_contents([('a', 'text for a\n')])
385
        tree.add(['a'])
386
        output, error = self.run_bzr('grep text')
387
        self.assertEqual(output, 'a:text for a\n')
388
        self.assertEqual(error, '')