/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
0.200.89 by Jelmer Vernooij
Support sprouting branches.
68
    def test_branch(self):
69
        os.mkdir("gitbranch")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
70
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
71
        os.chdir('gitbranch')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
72
        builder = tests.GitBranchBuilder()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
73
        builder.set_file(b'a', b'text for a\n', False)
74
        builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
75
        builder.finish()
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
76
        os.chdir('..')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
77
78
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
79
        self.assertTrue(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
80
            (error == 'Branched 1 revision(s).\n') or
81
            (error == 'Branched 1 revision.\n'),
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
82
            error)
0.200.89 by Jelmer Vernooij
Support sprouting branches.
83
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
84
    def test_checkout(self):
85
        os.mkdir("gitbranch")
86
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
87
        os.chdir('gitbranch')
88
        builder = tests.GitBranchBuilder()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
89
        builder.set_file(b'a', b'text for a\n', False)
90
        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.
91
        builder.finish()
92
        os.chdir('..')
93
94
        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.
95
        self.assertEqual(error,
7143.15.2 by Jelmer Vernooij
Run autopep8.
96
                         'Fetching from Git to Bazaar repository. '
97
                         'For better performance, fetch into a Git repository.\n')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
98
        self.assertEqual(output, '')
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
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'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
103
        self.assertEqual(error, '')
104
        self.assertEqual(output, "a\n")
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
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'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
113
        self.assertEqual(error, '')
114
        self.assertTrue("Standalone tree (format: git)" in output)
115
        self.assertTrue("control: Local Git Repository" in output)
116
        self.assertTrue("branch: Local Git Branch" in output)
117
        self.assertTrue("repository: Git Repository" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
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'])
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
128
        self.assertEqual(b"", output)
129
        self.assertTrue(error.endswith(b"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'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
137
        self.assertEqual(error, '')
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
138
        self.assertTrue(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
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'])
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
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()
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
151
        git_repo.refs[b"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'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
154
        self.assertEqual(error, '')
155
        self.assertEqual(output, "foo                  1\n")
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
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
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
164
        self.assertEqual(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"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
168
        self.assertEqual(error, '')
169
        self.assertEqual(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)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
176
        self.assertEqual(error, '')
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
177
        self.assertEqual(output,
7143.15.2 by Jelmer Vernooij
Run autopep8.
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'
184
                         '@@ -0,0 +1 @@\n'
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")
7143.15.2 by Jelmer Vernooij
Run autopep8.
191
        r.do_commit(ref=b"refs/heads/abranch",
192
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
193
        r.do_commit(ref=b"refs/heads/bbranch",
194
                    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.
195
        self.run_bzr(["git-import", "a", "b"])
7143.15.2 by Jelmer Vernooij
Run autopep8.
196
        self.assertEqual(
197
            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.
198
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
199
    def test_git_import(self):
200
        r = GitRepo.init("a", mkdir=True)
201
        self.build_tree(["a/file"])
202
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
203
        r.do_commit(ref=b"refs/heads/abranch",
204
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
205
        r.do_commit(ref=b"refs/heads/bbranch",
206
                    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.
207
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
208
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
209
        self.assertEqual(set(["abranch", "bbranch"]),
7143.15.2 by Jelmer Vernooij
Run autopep8.
210
                         set(ControlDir.open("b").get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
211
212
    def test_git_import_incremental(self):
213
        r = GitRepo.init("a", mkdir=True)
214
        self.build_tree(["a/file"])
215
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
216
        r.do_commit(ref=b"refs/heads/abranch",
217
                    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.
218
        self.run_bzr(["git-import", "--colocated", "a", "b"])
219
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
220
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
221
        b = ControlDir.open("b")
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
222
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
223
224
    def test_git_import_tags(self):
225
        r = GitRepo.init("a", mkdir=True)
226
        self.build_tree(["a/file"])
227
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
228
        cid = r.do_commit(ref=b"refs/heads/abranch",
229
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
230
        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.
231
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
232
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
233
        b = ControlDir.open("b")
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
234
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
6964.2.3 by Jelmer Vernooij
Review comments.
235
        self.assertEqual(["atag"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
236
                         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.
237
238
    def test_git_import_colo(self):
239
        r = GitRepo.init("a", mkdir=True)
240
        self.build_tree(["a/file"])
241
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
242
        r.do_commit(ref=b"refs/heads/abranch",
243
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
244
        r.do_commit(ref=b"refs/heads/bbranch",
245
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
246
        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.
247
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
248
        self.assertEqual(
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
249
            set([b.name for b in ControlDir.open("b").list_branches()]),
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
250
            set(["abranch", "bbranch"]))
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
251
252
    def test_git_refs_from_git(self):
253
        r = GitRepo.init("a", mkdir=True)
254
        self.build_tree(["a/file"])
255
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
256
        cid = r.do_commit(ref=b"refs/heads/abranch",
257
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
258
        r[b"refs/tags/atag"] = cid
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
259
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
260
        self.assertEqual(stderr, "")
6964.2.3 by Jelmer Vernooij
Review comments.
261
        self.assertEqual(stdout,
7143.15.2 by Jelmer Vernooij
Run autopep8.
262
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
263
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
264
265
    def test_git_refs_from_bzr(self):
266
        tree = self.make_branch_and_tree('a')
267
        self.build_tree(["a/file"])
268
        tree.add(["file"])
7143.15.2 by Jelmer Vernooij
Run autopep8.
269
        revid = tree.commit(
270
            committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
271
        tree.branch.tags.set_tag("atag", revid)
272
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
273
        self.assertEqual(stderr, "")
274
        self.assertTrue("refs/tags/atag -> " in stdout)
275
        self.assertTrue("HEAD -> " in stdout)
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
276
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
277
    def test_check(self):
278
        r = GitRepo.init("gitr", mkdir=True)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
279
        self.build_tree_contents([("gitr/foo", b"hello from git")])
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
280
        r.stage("foo")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
281
        r.do_commit(b"message", committer=b"Somebody <user@example.com>")
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
282
        out, err = self.run_bzr(["check", "gitr"])
283
        self.maxDiff = None
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
284
        self.assertEqual(out, '')
285
        self.assertTrue(err.endswith, '3 objects\n')
6965.1.2 by Jelmer Vernooij
Add test.
286
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
287
288
class ShallowTests(ExternalBase):
289
290
    def setUp(self):
291
        super(ShallowTests, self).setUp()
292
        # Smoke test for "bzr log" in a git repository with shallow depth.
293
        self.repo = GitRepo.init('gitr', mkdir=True)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
294
        self.build_tree_contents([("gitr/foo", b"hello from git")])
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
295
        self.repo.stage("foo")
296
        self.repo.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
297
            b"message", committer=b"Somebody <user@example.com>",
298
            commit_timestamp=1526330165, commit_timezone=0,
299
            author_timestamp=1526330165, author_timezone=0,
300
            merge_heads=[b'aa' * 20])
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
301
6965.1.2 by Jelmer Vernooij
Add test.
302
    def test_log_shallow(self):
303
        # Check that bzr log does not fail and includes the revision.
304
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
7143.15.2 by Jelmer Vernooij
Run autopep8.
305
        self.assertEqual(
306
            error, 'brz: ERROR: Further revision history missing.\n')
6965.1.2 by Jelmer Vernooij
Add test.
307
        self.assertEqual(output,
7143.15.2 by Jelmer Vernooij
Run autopep8.
308
                         '------------------------------------------------------------\n'
309
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
310
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
311
                         'committer: Somebody <user@example.com>\n'
312
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
313
                         'message:\n'
314
                         '  message\n')
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
315
316
    def test_version_info_rio(self):
317
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
318
        self.assertEqual(error, '')
319
        self.assertNotIn('revno:', output)
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
320
321
    def test_version_info_python(self):
322
        output, error = self.run_bzr(['version-info', '--python', 'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
323
        self.assertEqual(error, '')
324
        self.assertNotIn('revno:', output)
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
325
326
    def test_version_info_custom_with_revno(self):
327
        output, error = self.run_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
328
            ['version-info', '--custom',
329
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
330
        self.assertEqual(
331
            error, 'brz: ERROR: Variable {revno} is not available.\n')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
332
        self.assertEqual(output, 'VERSION_INFO r')
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
333
334
    def test_version_info_custom_without_revno(self):
335
        output, error = self.run_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
336
            ['version-info', '--custom', '--template=VERSION_INFO \n',
337
             'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
338
        self.assertEqual(error, '')
339
        self.assertEqual(output, 'VERSION_INFO \n')
7143.17.1 by Jelmer Vernooij
Fix grep in git working trees.
340
341
7143.18.1 by Jelmer Vernooij
Fix 'bzr switch' in git repositories.
342
class SwitchTests(ExternalBase):
343
344
    def test_switch_branch(self):
345
        # Create a git repository with a revision.
346
        repo = GitRepo.init(self.test_dir)
347
        builder = tests.GitBranchBuilder()
348
        builder.set_branch(b'refs/heads/oldbranch')
349
        builder.set_file('a', b'text for a\n', False)
350
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
351
        builder.set_branch(b'refs/heads/newbranch')
352
        builder.reset()
353
        builder.set_file('a', b'text for new a\n', False)
354
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
355
        builder.finish()
356
357
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
358
359
        repo.reset_index()
360
361
        output, error = self.run_bzr('switch oldbranch')
362
        self.assertEqual(output, '')
363
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
364
365
        self.assertFileEqual("text for a\n", 'a')
366
        tree = WorkingTree.open('.')
367
        with tree.lock_read():
368
            basis_tree = tree.basis_tree()
369
            with basis_tree.lock_read():
370
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
7143.18.2 by Jelmer Vernooij
Merge trunk.
371
372
7143.17.1 by Jelmer Vernooij
Fix grep in git working trees.
373
class GrepTests(ExternalBase):
374
375
    def test_simple_grep(self):
376
        tree = self.make_branch_and_tree('.', format='git')
377
        self.build_tree_contents([('a', 'text for a\n')])
378
        tree.add(['a'])
379
        output, error = self.run_bzr('grep text')
380
        self.assertEqual(output, 'a:text for a\n')
381
        self.assertEqual(error, '')