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