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