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